blob: f7d59f98e89cd05c48c1a6677acaef2c266fc2f4 [file] [log] [blame]
Ian Wienandbfdaacb2006-02-20 22:58:38 +01001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
Juan Cespedesd65efa32003-02-03 00:22:30 +01005#include <stdio.h>
6#include <stdlib.h>
7#include <sys/time.h>
8
9#include "ltrace.h"
Ian Wienandbfdaacb2006-02-20 22:58:38 +010010#include "options.h"
11
12#ifdef USE_DEMANAGE
13#include "demangle.h"
14#endif
Juan Cespedesd65efa32003-02-03 00:22:30 +010015
16static int num_entries = 0;
17static struct entry_st {
18 char *name;
19 int count;
20 struct timeval tv;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010021} *entries = NULL;
Juan Cespedesd65efa32003-02-03 00:22:30 +010022
23static int tot_count = 0;
24static unsigned long int tot_usecs = 0;
25
Ian Wienand2d45b1a2006-02-20 22:48:07 +010026static void fill_struct(void *key, void *value, void *data)
27{
28 struct opt_c_struct *st = (struct opt_c_struct *)value;
Juan Cespedesd65efa32003-02-03 00:22:30 +010029
Ian Wienand2d45b1a2006-02-20 22:48:07 +010030 entries = realloc(entries, (num_entries + 1) * sizeof(struct entry_st));
Juan Cespedesd65efa32003-02-03 00:22:30 +010031 if (!entries) {
32 perror("realloc()");
33 exit(1);
34 }
35 entries[num_entries].name = (char *)key;
36 entries[num_entries].count = st->count;
37 entries[num_entries].tv = st->tv;
38
39 tot_count += st->count;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010040 tot_usecs += 1000000 * st->tv.tv_sec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010041 tot_usecs += st->tv.tv_usec;
42
43 num_entries++;
44}
45
Ian Wienand2d45b1a2006-02-20 22:48:07 +010046static int compar(const void *a, const void *b)
47{
Juan Cespedesd65efa32003-02-03 00:22:30 +010048 struct entry_st *en1, *en2;
49
50 en1 = (struct entry_st *)a;
51 en2 = (struct entry_st *)b;
52
53 if (en2->tv.tv_sec - en1->tv.tv_sec) {
54 return (en2->tv.tv_sec - en1->tv.tv_sec);
55 } else {
56 return (en2->tv.tv_usec - en1->tv.tv_usec);
57 }
58}
59
Ian Wienand2d45b1a2006-02-20 22:48:07 +010060void show_summary(void)
61{
Juan Cespedesd65efa32003-02-03 00:22:30 +010062 int i;
63
64 num_entries = 0;
65 entries = NULL;
66
67 dict_apply_to_all(dict_opt_c, fill_struct, NULL);
68
69 qsort(entries, num_entries, sizeof(*entries), compar);
70
71 printf("%% time seconds usecs/call calls function\n");
Ian Wienand2d45b1a2006-02-20 22:48:07 +010072 printf
73 ("------ ----------- ----------- --------- --------------------\n");
74 for (i = 0; i < num_entries; i++) {
Juan Cespedesd65efa32003-02-03 00:22:30 +010075 unsigned long long int c;
76 unsigned long long int p;
Ian Wienand2d45b1a2006-02-20 22:48:07 +010077 c = 1000000 * (int)entries[i].tv.tv_sec +
78 (int)entries[i].tv.tv_usec;
Juan Cespedesd65efa32003-02-03 00:22:30 +010079 p = 100000 * c / tot_usecs + 5;
Juan Cespedes504a3852003-02-04 23:24:38 +010080 printf("%3lu.%02lu %4d.%06d %11lu %9d %s\n",
Ian Wienand2d45b1a2006-02-20 22:48:07 +010081 (unsigned long int)(p / 1000),
82 (unsigned long int)((p / 10) % 100),
83 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
84 (unsigned long int)(c / entries[i].count),
Ian Wienandbfdaacb2006-02-20 22:58:38 +010085 entries[i].count,
86 opt_C ? my_demange(entries[i].name) : entries[i].name);
Juan Cespedesd65efa32003-02-03 00:22:30 +010087 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +010088 printf
89 ("------ ----------- ----------- --------- --------------------\n");
90 printf("100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000,
91 tot_usecs % 1000000, tot_count);
Juan Cespedesd65efa32003-02-03 00:22:30 +010092}