blob: dab845cefa46434b475d06466465279a8875d53a [file] [log] [blame]
Ian Wienandbfdaacb2006-02-20 22:58:38 +01001#include "config.h"
Ian Wienandbfdaacb2006-02-20 22:58:38 +01002
Juan Cespedesd65efa32003-02-03 00:22:30 +01003#include <stdio.h>
4#include <stdlib.h>
5#include <sys/time.h>
6
Juan Cespedesf7281232009-06-25 16:11:21 +02007#include "common.h"
Juan Cespedesd65efa32003-02-03 00:22:30 +01008
9static int num_entries = 0;
10static struct entry_st {
11 char *name;
12 int count;
13 struct timeval tv;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010014} *entries = NULL;
Juan Cespedesd65efa32003-02-03 00:22:30 +010015
16static int tot_count = 0;
17static unsigned long int tot_usecs = 0;
18
Ian Wienand2d45b1a2006-02-20 22:48:07 +010019static void fill_struct(void *key, void *value, void *data)
20{
21 struct opt_c_struct *st = (struct opt_c_struct *)value;
Juan Cespedesd65efa32003-02-03 00:22:30 +010022
Ian Wienand2d45b1a2006-02-20 22:48:07 +010023 entries = realloc(entries, (num_entries + 1) * sizeof(struct entry_st));
Juan Cespedesd65efa32003-02-03 00:22:30 +010024 if (!entries) {
25 perror("realloc()");
26 exit(1);
27 }
28 entries[num_entries].name = (char *)key;
29 entries[num_entries].count = st->count;
30 entries[num_entries].tv = st->tv;
31
32 tot_count += st->count;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010033 tot_usecs += 1000000 * st->tv.tv_sec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010034 tot_usecs += st->tv.tv_usec;
35
36 num_entries++;
37}
38
Ian Wienand2d45b1a2006-02-20 22:48:07 +010039static int compar(const void *a, const void *b)
40{
Juan Cespedesd65efa32003-02-03 00:22:30 +010041 struct entry_st *en1, *en2;
42
43 en1 = (struct entry_st *)a;
44 en2 = (struct entry_st *)b;
45
46 if (en2->tv.tv_sec - en1->tv.tv_sec) {
47 return (en2->tv.tv_sec - en1->tv.tv_sec);
48 } else {
49 return (en2->tv.tv_usec - en1->tv.tv_usec);
50 }
51}
52
Ian Wienand2d45b1a2006-02-20 22:48:07 +010053void show_summary(void)
54{
Juan Cespedesd65efa32003-02-03 00:22:30 +010055 int i;
56
57 num_entries = 0;
58 entries = NULL;
59
60 dict_apply_to_all(dict_opt_c, fill_struct, NULL);
61
62 qsort(entries, num_entries, sizeof(*entries), compar);
63
Juan Cespedesb65bdc52008-12-16 19:50:16 +010064 fprintf(options.output, "%% time seconds usecs/call calls function\n");
65 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n");
Ian Wienand2d45b1a2006-02-20 22:48:07 +010066 for (i = 0; i < num_entries; i++) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010067 unsigned long long int c;
68 unsigned long long int p;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010069 c = 1000000 * (int)entries[i].tv.tv_sec +
70 (int)entries[i].tv.tv_usec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010071 p = 100000 * c / tot_usecs + 5;
Juan Cespedesb65bdc52008-12-16 19:50:16 +010072 fprintf(options.output, "%3lu.%02lu %4d.%06d %11lu %9d %s\n",
Ian Wienand2d45b1a2006-02-20 22:48:07 +010073 (unsigned long int)(p / 1000),
74 (unsigned long int)((p / 10) % 100),
75 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
76 (unsigned long int)(c / entries[i].count),
Ian Wienandbfdaacb2006-02-20 22:58:38 +010077 entries[i].count,
Olaf Heringa841f652006-09-15 01:57:49 +020078#ifdef USE_DEMANGLE
Juan Cespedesce377d52008-12-16 19:38:10 +010079 options.demangle ? my_demangle(entries[i].name) :
Olaf Heringa841f652006-09-15 01:57:49 +020080#endif
81 entries[i].name);
Juan Cespedesd65efa32003-02-03 00:22:30 +010082 }
Juan Cespedesb65bdc52008-12-16 19:50:16 +010083 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n");
84 fprintf(options.output, "100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000,
Ian Wienand2d45b1a2006-02-20 22:48:07 +010085 tot_usecs % 1000000, tot_count);
Juan Cespedesd65efa32003-02-03 00:22:30 +010086}