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