2 * This file is part of ltrace.
3 * Copyright (C) 2003,2008,2009 Juan Cespedes
4 * Copyright (C) 2006 Ian Wienand
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
30 static int num_entries = 0;
31 static struct entry_st {
37 static int tot_count = 0;
38 static unsigned long int tot_usecs = 0;
40 static void fill_struct(void *key, void *value, void *data)
42 struct opt_c_struct *st = (struct opt_c_struct *)value;
44 entries = realloc(entries, (num_entries + 1) * sizeof(struct entry_st));
49 entries[num_entries].name = (char *)key;
50 entries[num_entries].count = st->count;
51 entries[num_entries].tv = st->tv;
53 tot_count += st->count;
54 tot_usecs += 1000000 * st->tv.tv_sec;
55 tot_usecs += st->tv.tv_usec;
60 static int compar(const void *a, const void *b)
62 struct entry_st *en1, *en2;
64 en1 = (struct entry_st *)a;
65 en2 = (struct entry_st *)b;
67 if (en2->tv.tv_sec - en1->tv.tv_sec) {
68 return (en2->tv.tv_sec - en1->tv.tv_sec);
70 return (en2->tv.tv_usec - en1->tv.tv_usec);
74 void show_summary(void)
81 dict_apply_to_all(dict_opt_c, fill_struct, NULL);
83 qsort(entries, num_entries, sizeof(*entries), compar);
85 fprintf(options.output, "%% time seconds usecs/call calls function\n");
86 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n");
87 for (i = 0; i < num_entries; i++) {
88 unsigned long long int c;
89 unsigned long long int p;
90 c = 1000000 * (int)entries[i].tv.tv_sec +
91 (int)entries[i].tv.tv_usec;
92 p = 100000 * c / tot_usecs + 5;
93 fprintf(options.output, "%3lu.%02lu %4d.%06d %11lu %9d %s\n",
94 (unsigned long int)(p / 1000),
95 (unsigned long int)((p / 10) % 100),
96 (int)entries[i].tv.tv_sec, (int)entries[i].tv.tv_usec,
97 (unsigned long int)(c / entries[i].count),
100 options.demangle ? my_demangle(entries[i].name) :
104 fprintf(options.output, "------ ----------- ----------- --------- --------------------\n");
105 fprintf(options.output, "100.00 %4lu.%06lu %9d total\n", tot_usecs / 1000000,
106 tot_usecs % 1000000, tot_count);