3
|
1 /* $Id: time.c,v 1.1.1.1 1997/12/06 05:41:31 darius Exp $ */
|
|
2
|
|
3 #ifdef HANDLER_TIMES
|
|
4 #include <stdio.h>
|
|
5 #include <sys/time.h>
|
|
6
|
|
7 unsigned long avg[70], count[70];
|
|
8 struct timeval pre, post;
|
|
9
|
|
10 void print_times(void);
|
|
11 void log_time(int type, struct timeval *pre, struct timeval *post)
|
|
12 {
|
|
13 static int init=0;
|
|
14 unsigned long usecs;
|
|
15 int i;
|
|
16
|
|
17 if(!init) {
|
|
18 for(i=0;i<70;i++)
|
|
19 avg[i] = count[i] = 0;
|
|
20 init=1;
|
|
21 atexit(print_times);
|
|
22 }
|
|
23
|
|
24 usecs = (post->tv_sec * 1000000 + post->tv_usec) -
|
|
25 ( pre->tv_sec * 1000000 + pre->tv_usec);
|
|
26 avg[type] = ((avg[type]*count[type])+usecs)/(count[type]+1);
|
|
27 count[type]++;
|
|
28 }
|
|
29
|
|
30 void print_times()
|
|
31 {
|
|
32 int i, t_cnt=0, t_avg=0;
|
|
33
|
|
34 printf("Packet handler average times:\n");
|
|
35 printf("Type Count Average time (secs)\n");
|
|
36 for(i=0;i<70;i++) {
|
|
37 if(count[i]) {
|
|
38 printf(" %2d %5d %8.7f\n",i,count[i],(double)((double)avg[i]/1000000.0));
|
|
39 t_cnt+=count[i];
|
|
40 t_avg+=avg[i];
|
|
41 }
|
|
42 }
|
|
43 t_avg /= t_cnt;
|
|
44 printf("Totals:\n");
|
|
45 printf(" -- %5d, %8.7f\n", t_cnt, (double)((double)t_avg/1000000.0));
|
|
46 }
|
|
47
|
|
48 start_log()
|
|
49 {
|
|
50 gettimeofday(&pre, 0);
|
|
51 }
|
|
52
|
|
53 stop_log(int type)
|
|
54 {
|
|
55 gettimeofday(&post, 0);
|
|
56 log_time(type, &pre, &post);
|
|
57 }
|
|
58 #endif
|