annotate time.c @ 3:5a977ccbc7a9 default tip

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