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>
This commit is contained in:
parent
39d1e1b1e2
commit
28e2a106d1
|
@ -72,8 +72,6 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip)
|
||||||
struct sym_priv *priv;
|
struct sym_priv *priv;
|
||||||
struct sym_hist *h;
|
struct sym_hist *h;
|
||||||
|
|
||||||
he->count++;
|
|
||||||
|
|
||||||
if (!sym || !he->ms.map)
|
if (!sym || !he->ms.map)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -99,9 +97,8 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
static int perf_session__add_hist_entry(struct perf_session *self,
|
static int perf_session__add_hist_entry(struct perf_session *self,
|
||||||
struct addr_location *al, u64 count)
|
struct addr_location *al)
|
||||||
{
|
{
|
||||||
bool hit;
|
|
||||||
struct hist_entry *he;
|
struct hist_entry *he;
|
||||||
|
|
||||||
if (sym_hist_filter != NULL &&
|
if (sym_hist_filter != NULL &&
|
||||||
|
@ -115,7 +112,7 @@ static int perf_session__add_hist_entry(struct perf_session *self,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
he = __perf_session__add_hist_entry(&self->hists, al, NULL, count, &hit);
|
he = __perf_session__add_hist_entry(&self->hists, al, NULL, 1);
|
||||||
if (he == NULL)
|
if (he == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
|
@ -135,7 +132,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!al.filtered && perf_session__add_hist_entry(session, &al, 1)) {
|
if (!al.filtered && perf_session__add_hist_entry(session, &al)) {
|
||||||
pr_warning("problem incrementing symbol count, "
|
pr_warning("problem incrementing symbol count, "
|
||||||
"skipping event\n");
|
"skipping event\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -25,17 +25,9 @@ static bool show_displacement;
|
||||||
static int perf_session__add_hist_entry(struct perf_session *self,
|
static int perf_session__add_hist_entry(struct perf_session *self,
|
||||||
struct addr_location *al, u64 count)
|
struct addr_location *al, u64 count)
|
||||||
{
|
{
|
||||||
bool hit;
|
if (__perf_session__add_hist_entry(&self->hists, al, NULL, count) != NULL)
|
||||||
struct hist_entry *he = __perf_session__add_hist_entry(&self->hists,
|
return 0;
|
||||||
al, NULL,
|
return -ENOMEM;
|
||||||
count, &hit);
|
|
||||||
if (he == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
if (hit)
|
|
||||||
__perf_session__add_count(he, al, count);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int diff__process_sample_event(event_t *event, struct perf_session *session)
|
static int diff__process_sample_event(event_t *event, struct perf_session *session)
|
||||||
|
|
|
@ -82,7 +82,6 @@ static int perf_session__add_hist_entry(struct perf_session *self,
|
||||||
{
|
{
|
||||||
struct map_symbol *syms = NULL;
|
struct map_symbol *syms = NULL;
|
||||||
struct symbol *parent = NULL;
|
struct symbol *parent = NULL;
|
||||||
bool hit;
|
|
||||||
int err = -ENOMEM;
|
int err = -ENOMEM;
|
||||||
struct hist_entry *he;
|
struct hist_entry *he;
|
||||||
struct event_stat_id *stats;
|
struct event_stat_id *stats;
|
||||||
|
@ -103,19 +102,12 @@ static int perf_session__add_hist_entry(struct perf_session *self,
|
||||||
if (stats == NULL)
|
if (stats == NULL)
|
||||||
goto out_free_syms;
|
goto out_free_syms;
|
||||||
he = __perf_session__add_hist_entry(&stats->hists, al, parent,
|
he = __perf_session__add_hist_entry(&stats->hists, al, parent,
|
||||||
data->period, &hit);
|
data->period);
|
||||||
if (he == NULL)
|
if (he == NULL)
|
||||||
goto out_free_syms;
|
goto out_free_syms;
|
||||||
|
|
||||||
if (hit)
|
|
||||||
__perf_session__add_count(he, al, data->period);
|
|
||||||
|
|
||||||
err = 0;
|
err = 0;
|
||||||
if (symbol_conf.use_callchain) {
|
if (symbol_conf.use_callchain)
|
||||||
if (!hit)
|
|
||||||
callchain_init(he->callchain);
|
|
||||||
err = append_chain(he->callchain, data->callchain, syms);
|
err = append_chain(he->callchain, data->callchain, syms);
|
||||||
}
|
|
||||||
out_free_syms:
|
out_free_syms:
|
||||||
free(syms);
|
free(syms);
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -8,13 +8,10 @@ struct callchain_param callchain_param = {
|
||||||
.min_percent = 0.5
|
.min_percent = 0.5
|
||||||
};
|
};
|
||||||
|
|
||||||
void __perf_session__add_count(struct hist_entry *he,
|
static void perf_session__add_cpumode_count(struct hist_entry *he,
|
||||||
struct addr_location *al,
|
unsigned int cpumode, u64 count)
|
||||||
u64 count)
|
|
||||||
{
|
{
|
||||||
he->count += count;
|
switch (cpumode) {
|
||||||
|
|
||||||
switch (al->cpumode) {
|
|
||||||
case PERF_RECORD_MISC_KERNEL:
|
case PERF_RECORD_MISC_KERNEL:
|
||||||
he->count_sys += count;
|
he->count_sys += count;
|
||||||
break;
|
break;
|
||||||
|
@ -36,10 +33,24 @@ void __perf_session__add_count(struct hist_entry *he,
|
||||||
* histogram, sorted on item, collects counts
|
* histogram, sorted on item, collects counts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static struct hist_entry *hist_entry__new(struct hist_entry *template)
|
||||||
|
{
|
||||||
|
size_t callchain_size = symbol_conf.use_callchain ? sizeof(struct callchain_node) : 0;
|
||||||
|
struct hist_entry *self = malloc(sizeof(*self) + callchain_size);
|
||||||
|
|
||||||
|
if (self != NULL) {
|
||||||
|
*self = *template;
|
||||||
|
if (symbol_conf.use_callchain)
|
||||||
|
callchain_init(self->callchain);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
||||||
struct addr_location *al,
|
struct addr_location *al,
|
||||||
struct symbol *sym_parent,
|
struct symbol *sym_parent,
|
||||||
u64 count, bool *hit)
|
u64 count)
|
||||||
{
|
{
|
||||||
struct rb_node **p = &hists->rb_node;
|
struct rb_node **p = &hists->rb_node;
|
||||||
struct rb_node *parent = NULL;
|
struct rb_node *parent = NULL;
|
||||||
|
@ -64,8 +75,8 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
||||||
cmp = hist_entry__cmp(&entry, he);
|
cmp = hist_entry__cmp(&entry, he);
|
||||||
|
|
||||||
if (!cmp) {
|
if (!cmp) {
|
||||||
*hit = true;
|
he->count += count;
|
||||||
return he;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cmp < 0)
|
if (cmp < 0)
|
||||||
|
@ -74,14 +85,13 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
||||||
p = &(*p)->rb_right;
|
p = &(*p)->rb_right;
|
||||||
}
|
}
|
||||||
|
|
||||||
he = malloc(sizeof(*he) + (symbol_conf.use_callchain ?
|
he = hist_entry__new(&entry);
|
||||||
sizeof(struct callchain_node) : 0));
|
|
||||||
if (!he)
|
if (!he)
|
||||||
return NULL;
|
return NULL;
|
||||||
*he = entry;
|
|
||||||
rb_link_node(&he->rb_node, parent, p);
|
rb_link_node(&he->rb_node, parent, p);
|
||||||
rb_insert_color(&he->rb_node, hists);
|
rb_insert_color(&he->rb_node, hists);
|
||||||
*hit = false;
|
out:
|
||||||
|
perf_session__add_cpumode_count(he, al->cpumode, count);
|
||||||
return he;
|
return he;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,13 +12,10 @@ struct addr_location;
|
||||||
struct symbol;
|
struct symbol;
|
||||||
struct rb_root;
|
struct rb_root;
|
||||||
|
|
||||||
void __perf_session__add_count(struct hist_entry *he,
|
|
||||||
struct addr_location *al,
|
|
||||||
u64 count);
|
|
||||||
struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
|
||||||
struct addr_location *al,
|
struct addr_location *al,
|
||||||
struct symbol *parent,
|
struct symbol *parent,
|
||||||
u64 count, bool *hit);
|
u64 count);
|
||||||
extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *);
|
extern int64_t hist_entry__cmp(struct hist_entry *, struct hist_entry *);
|
||||||
extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *);
|
extern int64_t hist_entry__collapse(struct hist_entry *, struct hist_entry *);
|
||||||
int hist_entry__fprintf(struct hist_entry *self,
|
int hist_entry__fprintf(struct hist_entry *self,
|
||||||
|
|
Loading…
Reference in New Issue