xref: /original-bsd/old/refer/hunt/tick.c (revision a732a806)
1*a732a806Sbostic /*-
2*a732a806Sbostic  * %sccs.include.proprietary.c%
3*a732a806Sbostic  */
4*a732a806Sbostic 
5e4e48badSsam #ifndef lint
6*a732a806Sbostic static char sccsid[] = "@(#)tick.c	4.4 (Berkeley) 04/18/91";
7*a732a806Sbostic #endif /* not lint */
8e4e48badSsam 
9e1d29ff9Sgarrison /* time programs */
103466c402Sbostic # include <stdio.h>
113466c402Sbostic # include <sys/types.h>
123466c402Sbostic # include <sys/timeb.h>
13e1d29ff9Sgarrison struct tbuffer {
14e1d29ff9Sgarrison 	long	proc_user_time;
15e1d29ff9Sgarrison 	long	proc_system_time;
16e1d29ff9Sgarrison 	long	child_user_time;
17e1d29ff9Sgarrison 	long	child_system_time;
18e1d29ff9Sgarrison };
19e1d29ff9Sgarrison static long start, user, system;
tick()20e1d29ff9Sgarrison tick()
21e1d29ff9Sgarrison {
22e1d29ff9Sgarrison 	struct tbuffer tx;
23e1d29ff9Sgarrison 	struct timeb tp;
24e1d29ff9Sgarrison 	times (&tx);
25e1d29ff9Sgarrison 	ftime (&tp);
26e1d29ff9Sgarrison 	user =  tx.proc_user_time;
27e1d29ff9Sgarrison 	system= tx.proc_system_time;
28e1d29ff9Sgarrison 	start = tp.time*1000+tp.millitm;
29e1d29ff9Sgarrison }
tock()30e1d29ff9Sgarrison tock()
31e1d29ff9Sgarrison {
32e1d29ff9Sgarrison 	struct tbuffer tx;
33e1d29ff9Sgarrison 	struct timeb tp;
34e1d29ff9Sgarrison 	float lap, use, sys;
35e1d29ff9Sgarrison 	if (start==0) return;
36e1d29ff9Sgarrison 	times (&tx);
37e1d29ff9Sgarrison 	ftime (&tp);
38e1d29ff9Sgarrison 	lap = (tp.time*1000+tp.millitm-start)/1000.;
39e1d29ff9Sgarrison 	use = (tx.proc_user_time - user)/60.;
40e1d29ff9Sgarrison 	sys = (tx.proc_system_time - system)/60.;
41e1d29ff9Sgarrison 	printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n",
42e1d29ff9Sgarrison 		lap, use+sys, use, sys);
43e1d29ff9Sgarrison }
44