blob: d2f271b6484a443485506a22c700389a2d777011 [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 Wienand2d45b1a2006-02-20 22:48:07 +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 Wienand2d45b1a2006-02-20 22:48:07 +010017static void fill_struct(void *key, void *value, void *data)
18{
19 struct opt_c_struct *st = (struct opt_c_struct *)value;
Juan Cespedesd65efa32003-02-03 00:22:30 +010020
Ian Wienand2d45b1a2006-02-20 22:48:07 +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 Wienand2d45b1a2006-02-20 22:48:07 +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 Wienand2d45b1a2006-02-20 22:48:07 +010037static int compar(const void *a, const void *b)
38{
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 Wienand2d45b1a2006-02-20 22:48:07 +010051void show_summary(void)
52{
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 Wienand2d45b1a2006-02-20 22:48:07 +010063 printf
64 ("------ ----------- ----------- --------- --------------------\n");
65 for (i = 0; i < num_entries; i++) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010066 unsigned long long int c;
67 unsigned long long int p;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010068 c = 1000000 * (int)entries[i].tv.tv_sec +
69 (int)entries[i].tv.tv_usec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010070 p = 100000 * c / tot_usecs + 5;
Juan Cespedes504a3852003-02-04 23:24:38 +010071 printf("%3lu.%02lu %4d.%06d %11lu %9d %s\n",
Ian Wienand2d45b1a2006-02-20 22:48:07 +010072 (unsigned long int)(p / 1000),
73 (unsigned long int)((p / 10) % 100),
74 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
75 (unsigned long int)(c / entries[i].count),
76 entries[i].count, entries[i].name);
Juan Cespedesd65efa32003-02-03 00:22:30 +010077 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +010078 printf
79 ("------ ----------- ----------- --------- --------------------\n");
80 printf("100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000,
81 tot_usecs % 1000000, tot_count);
Juan Cespedesd65efa32003-02-03 00:22:30 +010082}