114506Ssam #ifndef lint 2*37895Sbostic static char sccsid[] = "@(#)tick.c 4.3 (Berkeley) 05/11/89"; 314506Ssam #endif 414506Ssam 513239Sgarrison /* time programs */ 6*37895Sbostic # include <stdio.h> 7*37895Sbostic # include <sys/types.h> 8*37895Sbostic # include <sys/timeb.h> 913239Sgarrison struct tbuffer { 1013239Sgarrison long proc_user_time; 1113239Sgarrison long proc_system_time; 1213239Sgarrison long child_user_time; 1313239Sgarrison long child_system_time; 1413239Sgarrison }; 1513239Sgarrison static long start, user, system; 1613239Sgarrison tick() 1713239Sgarrison { 1813239Sgarrison struct tbuffer tx; 1913239Sgarrison struct timeb tp; 2013239Sgarrison times (&tx); 2113239Sgarrison ftime (&tp); 2213239Sgarrison user = tx.proc_user_time; 2313239Sgarrison system= tx.proc_system_time; 2413239Sgarrison start = tp.time*1000+tp.millitm; 2513239Sgarrison } 2613239Sgarrison tock() 2713239Sgarrison { 2813239Sgarrison struct tbuffer tx; 2913239Sgarrison struct timeb tp; 3013239Sgarrison float lap, use, sys; 3113239Sgarrison if (start==0) return; 3213239Sgarrison times (&tx); 3313239Sgarrison ftime (&tp); 3413239Sgarrison lap = (tp.time*1000+tp.millitm-start)/1000.; 3513239Sgarrison use = (tx.proc_user_time - user)/60.; 3613239Sgarrison sys = (tx.proc_system_time - system)/60.; 3713239Sgarrison printf("Elapsed %.2f CPU %.2f (user %.2f, sys %.2f)\n", 3813239Sgarrison lap, use+sys, use, sys); 3913239Sgarrison } 40