xref: /titanic_44/usr/src/cmd/refer/tick.c (revision 4a634bb80136cc001d14ab96addd9915105e5223)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
9 /*
10  * Copyright (c) 1980 Regents of the University of California.
11  * All rights reserved. The Berkeley software License Agreement
12  * specifies the terms and conditions for redistribution.
13  */
14 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 /* time programs */
18 #include <stdio.h>
19 #include <sys/types.h>
20 
21 struct tbuffer {
22 	long	proc_user_time;
23 	long	proc_system_time;
24 	long	child_user_time;
25 	long	child_system_time;
26 };
27 static long start, user, systm;
28 
29 void
30 tick(void)
31 {
32 	struct tbuffer tx;
33 	time_t tp;
34 	times(&tx);
35 	time(&tp);
36 	user =  tx.proc_user_time;
37 	systm = tx.proc_system_time;
38 	start = tp;
39 }
40 
41 void
42 tock(void)
43 {
44 	struct tbuffer tx;
45 	time_t tp;
46 	float lap, use, sys;
47 	if (start == 0)
48 		return;
49 	times(&tx);
50 	time(&tp);
51 	lap = (tp - start)/60.;
52 	use = (tx.proc_user_time - user)/60.;
53 	sys = (tx.proc_system_time - systm)/60.;
54 	printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n",
55 	    lap, use+sys, use, sys);
56 }
57