2009-09-28 21:32:55 +08:00
|
|
|
#include "hist.h"
|
2009-12-14 23:10:39 +08:00
|
|
|
#include "session.h"
|
|
|
|
#include "sort.h"
|
2009-09-28 21:32:55 +08:00
|
|
|
|
|
|
|
struct callchain_param callchain_param = {
|
|
|
|
.mode = CHAIN_GRAPH_REL,
|
|
|
|
.min_percent = 0.5
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* histogram, sorted on item, collects counts
|
|
|
|
*/
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
struct hist_entry *__perf_session__add_hist_entry(struct perf_session *self,
|
|
|
|
struct addr_location *al,
|
|
|
|
struct symbol *sym_parent,
|
|
|
|
u64 count, bool *hit)
|
2009-10-03 21:42:45 +08:00
|
|
|
{
|
2009-12-14 23:10:39 +08:00
|
|
|
struct rb_node **p = &self->hists.rb_node;
|
2009-10-03 21:42:45 +08:00
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct hist_entry *he;
|
|
|
|
struct hist_entry entry = {
|
perf tools: Consolidate symbol resolving across all tools
Now we have a very high level routine for simple tools to
process IP sample events:
int event__preprocess_sample(const event_t *self,
struct addr_location *al,
symbol_filter_t filter)
It receives the event itself and will insert new threads in the
global threads list and resolve the map and symbol, filling all
this info into the new addr_location struct, so that tools like
annotate and report can further process the event by creating
hist_entries in their specific way (with or without callgraphs,
etc).
It in turn uses the new next layer function:
void thread__find_addr_location(struct thread *self, u8 cpumode,
enum map_type type, u64 addr,
struct addr_location *al,
symbol_filter_t filter)
This one will, given a thread (userspace or the kernel kthread
one), will find the given type (MAP__FUNCTION now, MAP__VARIABLE
too in the near future) at the given cpumode, taking vdsos into
account (userspace hit, but kernel symbol) and will fill all
these details in the addr_location given.
Tools that need a more compact API for plain function
resolution, like 'kmem', can use this other one:
struct symbol *thread__find_function(struct thread *self, u64 addr,
symbol_filter_t filter)
So, to resolve a kernel symbol, that is all the 'kmem' tool
needs, its just a matter of calling:
sym = thread__find_function(kthread, addr, NULL);
The 'filter' parameter is needed because we do lazy
parsing/loading of ELF symtabs or /proc/kallsyms.
With this we remove more code duplication all around, which is
always good, huh? :-)
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: John Kacur <jkacur@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
LKML-Reference: <1259346563-12568-12-git-send-email-acme@infradead.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-11-28 02:29:23 +08:00
|
|
|
.thread = al->thread,
|
|
|
|
.map = al->map,
|
|
|
|
.sym = al->sym,
|
|
|
|
.ip = al->addr,
|
|
|
|
.level = al->level,
|
2009-10-03 21:42:45 +08:00
|
|
|
.count = count,
|
|
|
|
.parent = sym_parent,
|
|
|
|
};
|
|
|
|
int cmp;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
he = rb_entry(parent, struct hist_entry, rb_node);
|
|
|
|
|
|
|
|
cmp = hist_entry__cmp(&entry, he);
|
|
|
|
|
|
|
|
if (!cmp) {
|
|
|
|
*hit = true;
|
|
|
|
return he;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmp < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
he = malloc(sizeof(*he));
|
|
|
|
if (!he)
|
|
|
|
return NULL;
|
|
|
|
*he = entry;
|
|
|
|
rb_link_node(&he->rb_node, parent, p);
|
2009-12-14 23:10:39 +08:00
|
|
|
rb_insert_color(&he->rb_node, &self->hists);
|
2009-10-03 21:42:45 +08:00
|
|
|
*hit = false;
|
|
|
|
return he;
|
|
|
|
}
|
|
|
|
|
2009-09-28 21:32:55 +08:00
|
|
|
int64_t
|
|
|
|
hist_entry__cmp(struct hist_entry *left, struct hist_entry *right)
|
|
|
|
{
|
|
|
|
struct sort_entry *se;
|
|
|
|
int64_t cmp = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(se, &hist_entry__sort_list, list) {
|
|
|
|
cmp = se->cmp(left, right);
|
|
|
|
if (cmp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t
|
|
|
|
hist_entry__collapse(struct hist_entry *left, struct hist_entry *right)
|
|
|
|
{
|
|
|
|
struct sort_entry *se;
|
|
|
|
int64_t cmp = 0;
|
|
|
|
|
|
|
|
list_for_each_entry(se, &hist_entry__sort_list, list) {
|
|
|
|
int64_t (*f)(struct hist_entry *, struct hist_entry *);
|
|
|
|
|
|
|
|
f = se->collapse ?: se->cmp;
|
|
|
|
|
|
|
|
cmp = f(left, right);
|
|
|
|
if (cmp)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return cmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hist_entry__free(struct hist_entry *he)
|
|
|
|
{
|
|
|
|
free(he);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* collapse the histogram
|
|
|
|
*/
|
|
|
|
|
2009-12-14 21:37:11 +08:00
|
|
|
static void collapse__insert_entry(struct rb_root *root, struct hist_entry *he)
|
2009-09-28 21:32:55 +08:00
|
|
|
{
|
2009-12-14 21:37:11 +08:00
|
|
|
struct rb_node **p = &root->rb_node;
|
2009-09-28 21:32:55 +08:00
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct hist_entry *iter;
|
|
|
|
int64_t cmp;
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
iter = rb_entry(parent, struct hist_entry, rb_node);
|
|
|
|
|
|
|
|
cmp = hist_entry__collapse(iter, he);
|
|
|
|
|
|
|
|
if (!cmp) {
|
|
|
|
iter->count += he->count;
|
|
|
|
hist_entry__free(he);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cmp < 0)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&he->rb_node, parent, p);
|
2009-12-14 21:37:11 +08:00
|
|
|
rb_insert_color(&he->rb_node, root);
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
void perf_session__collapse_resort(struct perf_session *self)
|
2009-09-28 21:32:55 +08:00
|
|
|
{
|
2009-12-14 21:37:11 +08:00
|
|
|
struct rb_root tmp;
|
2009-09-28 21:32:55 +08:00
|
|
|
struct rb_node *next;
|
|
|
|
struct hist_entry *n;
|
|
|
|
|
|
|
|
if (!sort__need_collapse)
|
|
|
|
return;
|
|
|
|
|
2009-12-14 21:37:11 +08:00
|
|
|
tmp = RB_ROOT;
|
2009-12-14 23:10:39 +08:00
|
|
|
next = rb_first(&self->hists);
|
2009-12-14 21:37:11 +08:00
|
|
|
|
2009-09-28 21:32:55 +08:00
|
|
|
while (next) {
|
|
|
|
n = rb_entry(next, struct hist_entry, rb_node);
|
|
|
|
next = rb_next(&n->rb_node);
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
rb_erase(&n->rb_node, &self->hists);
|
2009-12-14 21:37:11 +08:00
|
|
|
collapse__insert_entry(&tmp, n);
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|
2009-12-14 21:37:11 +08:00
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
self->hists = tmp;
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* reverse the map, sort on count.
|
|
|
|
*/
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
static void perf_session__insert_output_hist_entry(struct perf_session *self,
|
|
|
|
struct rb_root *root,
|
|
|
|
struct hist_entry *he,
|
|
|
|
u64 min_callchain_hits)
|
2009-09-28 21:32:55 +08:00
|
|
|
{
|
2009-12-14 21:37:11 +08:00
|
|
|
struct rb_node **p = &root->rb_node;
|
2009-09-28 21:32:55 +08:00
|
|
|
struct rb_node *parent = NULL;
|
|
|
|
struct hist_entry *iter;
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
if (self->use_callchain)
|
2009-09-28 21:32:55 +08:00
|
|
|
callchain_param.sort(&he->sorted_chain, &he->callchain,
|
|
|
|
min_callchain_hits, &callchain_param);
|
|
|
|
|
|
|
|
while (*p != NULL) {
|
|
|
|
parent = *p;
|
|
|
|
iter = rb_entry(parent, struct hist_entry, rb_node);
|
|
|
|
|
|
|
|
if (he->count > iter->count)
|
|
|
|
p = &(*p)->rb_left;
|
|
|
|
else
|
|
|
|
p = &(*p)->rb_right;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb_link_node(&he->rb_node, parent, p);
|
2009-12-14 21:37:11 +08:00
|
|
|
rb_insert_color(&he->rb_node, root);
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
void perf_session__output_resort(struct perf_session *self, u64 total_samples)
|
2009-09-28 21:32:55 +08:00
|
|
|
{
|
2009-12-14 21:37:11 +08:00
|
|
|
struct rb_root tmp;
|
2009-09-28 21:32:55 +08:00
|
|
|
struct rb_node *next;
|
|
|
|
struct hist_entry *n;
|
|
|
|
u64 min_callchain_hits;
|
|
|
|
|
|
|
|
min_callchain_hits =
|
|
|
|
total_samples * (callchain_param.min_percent / 100);
|
|
|
|
|
2009-12-14 21:37:11 +08:00
|
|
|
tmp = RB_ROOT;
|
2009-12-14 23:10:39 +08:00
|
|
|
next = rb_first(&self->hists);
|
2009-09-28 21:32:55 +08:00
|
|
|
|
|
|
|
while (next) {
|
|
|
|
n = rb_entry(next, struct hist_entry, rb_node);
|
|
|
|
next = rb_next(&n->rb_node);
|
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
rb_erase(&n->rb_node, &self->hists);
|
|
|
|
perf_session__insert_output_hist_entry(self, &tmp, n,
|
|
|
|
min_callchain_hits);
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|
2009-12-14 21:37:11 +08:00
|
|
|
|
2009-12-14 23:10:39 +08:00
|
|
|
self->hists = tmp;
|
2009-09-28 21:32:55 +08:00
|
|
|
}
|