1*11a8fa6cSceastha /*
2*11a8fa6cSceastha * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3*11a8fa6cSceastha * Use is subject to license terms.
4*11a8fa6cSceastha */
5*11a8fa6cSceastha
67c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
77c478bd9Sstevel@tonic-gate /* All Rights Reserved */
87c478bd9Sstevel@tonic-gate
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate */
147c478bd9Sstevel@tonic-gate
157c478bd9Sstevel@tonic-gate /* time programs */
16*11a8fa6cSceastha #include <stdio.h>
17*11a8fa6cSceastha #include <sys/types.h>
187c478bd9Sstevel@tonic-gate
197c478bd9Sstevel@tonic-gate struct tbuffer {
207c478bd9Sstevel@tonic-gate long proc_user_time;
217c478bd9Sstevel@tonic-gate long proc_system_time;
227c478bd9Sstevel@tonic-gate long child_user_time;
237c478bd9Sstevel@tonic-gate long child_system_time;
247c478bd9Sstevel@tonic-gate };
257c478bd9Sstevel@tonic-gate static long start, user, systm;
26*11a8fa6cSceastha
27*11a8fa6cSceastha void
tick(void)28*11a8fa6cSceastha tick(void)
297c478bd9Sstevel@tonic-gate {
307c478bd9Sstevel@tonic-gate struct tbuffer tx;
317c478bd9Sstevel@tonic-gate time_t tp;
32*11a8fa6cSceastha times(&tx);
33*11a8fa6cSceastha time(&tp);
347c478bd9Sstevel@tonic-gate user = tx.proc_user_time;
35*11a8fa6cSceastha systm = tx.proc_system_time;
367c478bd9Sstevel@tonic-gate start = tp;
377c478bd9Sstevel@tonic-gate }
38*11a8fa6cSceastha
39*11a8fa6cSceastha void
tock(void)40*11a8fa6cSceastha tock(void)
417c478bd9Sstevel@tonic-gate {
427c478bd9Sstevel@tonic-gate struct tbuffer tx;
437c478bd9Sstevel@tonic-gate time_t tp;
447c478bd9Sstevel@tonic-gate float lap, use, sys;
45*11a8fa6cSceastha if (start == 0)
46*11a8fa6cSceastha return;
47*11a8fa6cSceastha times(&tx);
48*11a8fa6cSceastha time(&tp);
497c478bd9Sstevel@tonic-gate lap = (tp - start)/60.;
507c478bd9Sstevel@tonic-gate use = (tx.proc_user_time - user)/60.;
517c478bd9Sstevel@tonic-gate sys = (tx.proc_system_time - systm)/60.;
527c478bd9Sstevel@tonic-gate printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n",
53*11a8fa6cSceastha lap, use+sys, use, sys);
547c478bd9Sstevel@tonic-gate }
55