| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame^] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <sys/time.h> |
| 4 | |
| 5 | #include "ltrace.h" |
| 6 | |
| 7 | static int num_entries = 0; |
| 8 | static struct entry_st { |
| 9 | char *name; |
| 10 | int count; |
| 11 | struct timeval tv; |
| 12 | } * entries = NULL; |
| 13 | |
| 14 | static int tot_count = 0; |
| 15 | static unsigned long int tot_usecs = 0; |
| 16 | |
| 17 | static void |
| 18 | fill_struct(void * key, void * value, void * data) { |
| 19 | struct opt_c_struct * st = (struct opt_c_struct *)value; |
| 20 | |
| 21 | entries = realloc(entries, (num_entries+1)*sizeof(struct entry_st)); |
| 22 | 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; |
| 31 | tot_usecs += 1000000*st->tv.tv_sec; |
| 32 | tot_usecs += st->tv.tv_usec; |
| 33 | |
| 34 | num_entries++; |
| 35 | } |
| 36 | |
| 37 | static int |
| 38 | compar(const void *a, const void *b) { |
| 39 | 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 | |
| 51 | void |
| 52 | summary(void) { |
| 53 | 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"); |
| 63 | printf( "------ ----------- ----------- --------- --------------------\n"); |
| 64 | for(i=0; i<num_entries; i++) { |
| 65 | unsigned long long int c; |
| 66 | unsigned long long int p; |
| 67 | c = 1000000 * (int)entries[i].tv.tv_sec + (int)entries[i].tv.tv_usec; |
| 68 | p = 100000 * c / tot_usecs + 5; |
| 69 | printf("%3lu.%02d %4d.%06d %11lu %9d %s\n", |
| 70 | (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); |
| 75 | } |
| 76 | printf("------ ----------- ----------- --------- --------------------\n"); |
| 77 | printf("100.00 %4lu.%06lu %9d total\n", |
| 78 | tot_usecs / 1000000, tot_usecs % 1000000, tot_count); |
| 79 | } |