blob: 2cfe4d6efeba8a79ad5889028bbb79dbb31c5c8d [file] [log] [blame]
Juan Cespedesd65efa32003-02-03 00:22:30 +01001#include <stdio.h>
2#include <stdlib.h>
3#include <sys/time.h>
4
5#include "ltrace.h"
6
7static int num_entries = 0;
8static struct entry_st {
9 char *name;
10 int count;
11 struct timeval tv;
Ian Wienand9a2ad352006-02-20 22:44:45 +010012} * entries = NULL;
Juan Cespedesd65efa32003-02-03 00:22:30 +010013
14static int tot_count = 0;
15static unsigned long int tot_usecs = 0;
16
Ian Wienand9a2ad352006-02-20 22:44:45 +010017static void
18fill_struct(void * key, void * value, void * data) {
19 struct opt_c_struct * st = (struct opt_c_struct *)value;
Juan Cespedesd65efa32003-02-03 00:22:30 +010020
Ian Wienand9a2ad352006-02-20 22:44:45 +010021 entries = realloc(entries, (num_entries+1)*sizeof(struct entry_st));
Juan Cespedesd65efa32003-02-03 00:22:30 +010022 if (!entries) {
23 perror("realloc()");
24 exit(1);
25 }
26 entries[num_entries].name = (char *)key;
27 entries[num_entries].count = st->count;
28 entries[num_entries].tv = st->tv;
29
30 tot_count += st->count;
Ian Wienand9a2ad352006-02-20 22:44:45 +010031 tot_usecs += 1000000*st->tv.tv_sec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010032 tot_usecs += st->tv.tv_usec;
33
34 num_entries++;
35}
36
Ian Wienand9a2ad352006-02-20 22:44:45 +010037static int
38compar(const void *a, const void *b) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010039 struct entry_st *en1, *en2;
40
41 en1 = (struct entry_st *)a;
42 en2 = (struct entry_st *)b;
43
44 if (en2->tv.tv_sec - en1->tv.tv_sec) {
45 return (en2->tv.tv_sec - en1->tv.tv_sec);
46 } else {
47 return (en2->tv.tv_usec - en1->tv.tv_usec);
48 }
49}
50
Ian Wienand9a2ad352006-02-20 22:44:45 +010051void
52show_summary(void) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010053 int i;
54
55 num_entries = 0;
56 entries = NULL;
57
58 dict_apply_to_all(dict_opt_c, fill_struct, NULL);
59
60 qsort(entries, num_entries, sizeof(*entries), compar);
61
62 printf("%% time seconds usecs/call calls function\n");
Ian Wienand9a2ad352006-02-20 22:44:45 +010063 printf( "------ ----------- ----------- --------- --------------------\n");
64 for(i=0; i<num_entries; i++) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010065 unsigned long long int c;
66 unsigned long long int p;
Ian Wienand9a2ad352006-02-20 22:44:45 +010067 c = 1000000 * (int)entries[i].tv.tv_sec + (int)entries[i].tv.tv_usec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010068 p = 100000 * c / tot_usecs + 5;
Juan Cespedes504a3852003-02-04 23:24:38 +010069 printf("%3lu.%02lu %4d.%06d %11lu %9d %s\n",
Ian Wienand9a2ad352006-02-20 22:44:45 +010070 (unsigned long int)(p / 1000),
71 (unsigned long int)((p / 10) % 100),
72 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
73 (unsigned long int)(c / entries[i].count),
74 entries[i].count, entries[i].name);
Juan Cespedesd65efa32003-02-03 00:22:30 +010075 }
Ian Wienand9a2ad352006-02-20 22:44:45 +010076 printf("------ ----------- ----------- --------- --------------------\n");
77 printf("100.00 %4lu.%06lu %9d total\n",
78 tot_usecs / 1000000, tot_usecs % 1000000, tot_count);
Juan Cespedesd65efa32003-02-03 00:22:30 +010079}