summary.c revision 8d1b92ba755f6d6229f5e230fc43d958b13836f8
1#if HAVE_CONFIG_H 2#include "config.h" 3#endif 4 5#include <stdio.h> 6#include <stdlib.h> 7#include <sys/time.h> 8 9#include "common.h" 10 11static int num_entries = 0; 12static struct entry_st { 13 char *name; 14 int count; 15 struct timeval tv; 16} *entries = NULL; 17 18static int tot_count = 0; 19static unsigned long int tot_usecs = 0; 20 21static void fill_struct(void *key, void *value, void *data) 22{ 23 struct opt_c_struct *st = (struct opt_c_struct *)value; 24 25 entries = realloc(entries, (num_entries + 1) * sizeof(struct entry_st)); 26 if (!entries) { 27 perror("realloc()"); 28 exit(1); 29 } 30 entries[num_entries].name = (char *)key; 31 entries[num_entries].count = st->count; 32 entries[num_entries].tv = st->tv; 33 34 tot_count += st->count; 35 tot_usecs += 1000000 * st->tv.tv_sec; 36 tot_usecs += st->tv.tv_usec; 37 38 num_entries++; 39} 40 41static int compar(const void *a, const void *b) 42{ 43 struct entry_st *en1, *en2; 44 45 en1 = (struct entry_st *)a; 46 en2 = (struct entry_st *)b; 47 48 if (en2->tv.tv_sec - en1->tv.tv_sec) { 49 return (en2->tv.tv_sec - en1->tv.tv_sec); 50 } else { 51 return (en2->tv.tv_usec - en1->tv.tv_usec); 52 } 53} 54 55void show_summary(void) 56{ 57 int i; 58 59 num_entries = 0; 60 entries = NULL; 61 62 dict_apply_to_all(dict_opt_c, fill_struct, NULL); 63 64 qsort(entries, num_entries, sizeof(*entries), compar); 65 66 fprintf(options.output, "%% time seconds usecs/call calls function\n"); 67 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n"); 68 for (i = 0; i < num_entries; i++) { 69 unsigned long long int c; 70 unsigned long long int p; 71 c = 1000000 * (int)entries[i].tv.tv_sec + 72 (int)entries[i].tv.tv_usec; 73 p = 100000 * c / tot_usecs + 5; 74 fprintf(options.output, "%3lu.%02lu %4d.%06d %11lu %9d %s\n", 75 (unsigned long int)(p / 1000), 76 (unsigned long int)((p / 10) % 100), 77 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec, 78 (unsigned long int)(c / entries[i].count), 79 entries[i].count, 80#ifdef USE_DEMANGLE 81 options.demangle ? my_demangle(entries[i].name) : 82#endif 83 entries[i].name); 84 } 85 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n"); 86 fprintf(options.output, "100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000, 87 tot_usecs % 1000000, tot_count); 88} 89