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 /* time programs */
16 #include <stdio.h>
17 #include <sys/types.h>
18
19 struct tbuffer {
20 long proc_user_time;
21 long proc_system_time;
22 long child_user_time;
23 long child_system_time;
24 };
25 static long start, user, systm;
26
27 void
tick(void)28 tick(void)
29 {
30 struct tbuffer tx;
31 time_t tp;
32 times(&tx);
33 time(&tp);
34 user = tx.proc_user_time;
35 systm = tx.proc_system_time;
36 start = tp;
37 }
38
39 void
tock(void)40 tock(void)
41 {
42 struct tbuffer tx;
43 time_t tp;
44 float lap, use, sys;
45 if (start == 0)
46 return;
47 times(&tx);
48 time(&tp);
49 lap = (tp - start)/60.;
50 use = (tx.proc_user_time - user)/60.;
51 sys = (tx.proc_system_time - systm)/60.;
52 printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n",
53 lap, use+sys, use, sys);
54 }
55