aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/hist.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2010-05-09 12:02:23 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2010-05-09 12:10:39 -0400
commit28e2a106d16046ca792722795f809e3f80a5af80 (patch)
treec84149ddf45d02044187fe4511cead93d009b6ee /tools/perf/util/hist.c
parent39d1e1b1e26dc84d40bf2792287d0d61e44b57df (diff)
perf hist: Simplify the insertion of new hist_entry instances
And with that fix at least one bug: The first hit for an entry, the one that calls malloc to create a new instance in __perf_session__add_hist_entry, wasn't adding the count to the per cpumode (PERF_RECORD_MISC_USER, etc) total variable. Cc: Frédéric Weisbecker <fweisbec@gmail.com> Cc: Mike Galbraith <efault@gmx.de> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Tom Zanussi <tzanussi@gmail.com> LKML-Reference: <new-submission> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/hist.c')
-rw-r--r--tools/perf/util/hist.c36
1 files changed, 23 insertions, 13 deletions
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index ad6b22dde27f..e0c8a722e11f 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -8,13 +8,10 @@ struct callchain_param callchain_param = {
8 .min_percent = 0.5 8 .min_percent = 0.5
9}; 9};
10 10
11void __perf_session__add_count(struct hist_entry *he, 11static void perf_session__add_cpumode_count(struct hist_entry *he,
12 struct addr_location *al, 12 unsigned int cpumode, u64 count)
13 u64 count)
14{ 13{
15 he->count += count; 14 switch (cpumode) {
16
17 switch (al->cpumode) {
18 case PERF_RECORD_MISC_KERNEL: 15 case PERF_RECORD_MISC_KERNEL:
19 he->count_sys += count; 16 he->count_sys += count;
20 break; 17 break;
@@ -36,10 +33,24 @@ void __perf_session__add_count(struct hist_entry *he,
36 * histogram, sorted on item, collects counts 33 * histogram, sorted on item, collects counts
37 */ 34 */
38 35
36static struct hist_entry *hist_entry__new(struct hist_entry *template)
37{
38 size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0;
39 struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
40
41 if (self != NULL) {
42 *self = *template;
43 if (symbol_conf.use_callchain)
44 callchain_init(self->callchain);
45 }
46
47 return self;
48}
49
39struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists, 50struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
40 struct addr_location *al, 51 struct addr_location *al,
41 struct symbol *sym_parent, 52 struct symbol *sym_parent,
42 u64 count, bool *hit) 53 u64 count)
43{ 54{
44 struct rb_node **p = &hists->rb_node; 55 struct rb_node **p = &hists->rb_node;
45 struct rb_node *parent = NULL; 56 struct rb_node *parent = NULL;
@@ -64,8 +75,8 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
64 cmp = hist_entry__cmp(&entry, he); 75 cmp = hist_entry__cmp(&entry, he);
65 76
66 if (!cmp) { 77 if (!cmp) {
67 *hit = true; 78 he->count += count;
68 return he; 79 goto out;
69 } 80 }
70 81
71 if (cmp < 0) 82 if (cmp < 0)
@@ -74,14 +85,13 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
74 p = &(*p)->rb_right; 85 p = &(*p)->rb_right;
75 } 86 }
76 87
77 he = malloc(sizeof(*he) + (symbol_conf.use_callchain ? 88 he = hist_entry__new(&entry);
78 sizeof(struct callchain_node) : 0));
79 if (!he) 89 if (!he)
80 return NULL; 90 return NULL;
81 *he = entry;
82 rb_link_node(&he->rb_node, parent, p); 91 rb_link_node(&he->rb_node, parent, p);
83 rb_insert_color(&he->rb_node, hists); 92 rb_insert_color(&he->rb_node, hists);
84 *hit = false; 93out:
94 perf_session__add_cpumode_count(he, al->cpumode, count);
85 return he; 95 return he;
86} 96}
87 97