Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 191329
b: refs/heads/master
c: 1f0ac71
h: refs/heads/master
i:
  191327: cfb369d
v: v3
  • Loading branch information
Ingo Molnar committed May 10, 2010
1 parent cd72d50 commit b6d7787
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 102 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 76ba7e846fcc89d9d4b25b89e303c9058de96d60
refs/heads/master: 1f0ac7183f4d270bd9ce511254ba5d931d4f29c9
9 changes: 3 additions & 6 deletions trunk/tools/perf/builtin-annotate.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ static int annotate__hist_hit(struct hist_entry *he, u64 ip)
struct sym_priv *priv;
struct sym_hist *h;

he->count++;

if (!sym || !he->ms.map)
return 0;

Expand All @@ -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,
struct addr_location *al, u64 count)
struct addr_location *al)
{
bool hit;
struct hist_entry *he;

if (sym_hist_filter != NULL &&
Expand All @@ -115,7 +112,7 @@ static int perf_session__add_hist_entry(struct perf_session *self,
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)
return -ENOMEM;

Expand All @@ -135,7 +132,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)
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, "
"skipping event\n");
return -1;
Expand Down
14 changes: 3 additions & 11 deletions trunk/tools/perf/builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,9 @@ static bool show_displacement;
static int perf_session__add_hist_entry(struct perf_session *self,
struct addr_location *al, u64 count)
{
bool hit;
struct hist_entry *he = __perf_session__add_hist_entry(&self->hists,
al, NULL,
count, &hit);
if (he == NULL)
return -ENOMEM;

if (hit)
__perf_session__add_count(he, al, count);

return 0;
if (__perf_session__add_hist_entry(&self->hists, al, NULL, count) != NULL)
return 0;
return -ENOMEM;
}

static int diff__process_sample_event(event_t *event, struct perf_session *session)
Expand Down
48 changes: 14 additions & 34 deletions trunk/tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ static int perf_session__add_hist_entry(struct perf_session *self,
{
struct map_symbol *syms = NULL;
struct symbol *parent = NULL;
bool hit;
int err;
int err = -ENOMEM;
struct hist_entry *he;
struct event_stat_id *stats;
struct perf_event_attr *attr;
Expand All @@ -101,39 +100,17 @@ static int perf_session__add_hist_entry(struct perf_session *self,
else
stats = get_stats(self, data->id, 0, 0);
if (stats == NULL)
return -ENOMEM;
goto out_free_syms;
he = __perf_session__add_hist_entry(&stats->hists, al, parent,
data->period, &hit);
data->period);
if (he == NULL)
return -ENOMEM;

if (hit)
__perf_session__add_count(he, al, data->period);

if (symbol_conf.use_callchain) {
if (!hit)
callchain_init(he->callchain);
goto out_free_syms;
err = 0;
if (symbol_conf.use_callchain)
err = append_chain(he->callchain, data->callchain, syms);
free(syms);

if (err)
return err;
}

return 0;
}

static int validate_chain(struct ip_callchain *chain, event_t *event)
{
unsigned int chain_size;

chain_size = event->header.size;
chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;

if (chain->nr*sizeof(u64) > chain_size)
return -1;

return 0;
out_free_syms:
free(syms);
return err;
}

static int add_event_total(struct perf_session *session,
Expand Down Expand Up @@ -171,7 +148,7 @@ static int process_sample_event(event_t *event, struct perf_session *session)

dump_printf("... chain: nr:%Lu\n", data.callchain->nr);

if (validate_chain(data.callchain, event) < 0) {
if (!ip_callchain__valid(data.callchain, event)) {
pr_debug("call-chain problem with event, "
"skipping it.\n");
return 0;
Expand Down Expand Up @@ -366,7 +343,7 @@ static int
parse_callchain_opt(const struct option *opt __used, const char *arg,
int unset)
{
char *tok;
char *tok, *tok2;
char *endptr;

/*
Expand Down Expand Up @@ -411,10 +388,13 @@ parse_callchain_opt(const struct option *opt __used, const char *arg,
if (!tok)
goto setup;

tok2 = strtok(NULL, ",");
callchain_param.min_percent = strtod(tok, &endptr);
if (tok == endptr)
return -1;

if (tok2)
callchain_param.print_limit = strtod(tok2, &endptr);
setup:
if (register_callchain_param(&callchain_param) < 0) {
fprintf(stderr, "Can't register callchain params\n");
Expand Down
7 changes: 7 additions & 0 deletions trunk/tools/perf/util/callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@

#include "callchain.h"

bool ip_callchain__valid(struct ip_callchain *chain, event_t *event)
{
unsigned int chain_size = event->header.size;
chain_size -= (unsigned long)&event->ip.__more_data - (unsigned long)event;
return chain->nr * sizeof(u64) <= chain_size;
}

#define chain_for_each_child(child, parent) \
list_for_each_entry(child, &parent->children, brothers)

Expand Down
4 changes: 4 additions & 0 deletions trunk/tools/perf/util/callchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "../perf.h"
#include <linux/list.h>
#include <linux/rbtree.h>
#include "event.h"
#include "util.h"
#include "symbol.h"

Expand Down Expand Up @@ -33,6 +34,7 @@ typedef void (*sort_chain_func_t)(struct rb_root *, struct callchain_node *,

struct callchain_param {
enum chain_mode mode;
u32 print_limit;
double min_percent;
sort_chain_func_t sort;
};
Expand All @@ -58,4 +60,6 @@ static inline u64 cumul_hits(struct callchain_node *node)
int register_callchain_param(struct callchain_param *param);
int append_chain(struct callchain_node *root, struct ip_callchain *chain,
struct map_symbol *syms);

bool ip_callchain__valid(struct ip_callchain *chain, event_t *event);
#endif /* __PERF_CALLCHAIN_H */
27 changes: 25 additions & 2 deletions trunk/tools/perf/util/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,10 @@ int event__process_mmap(event_t *self, struct perf_session *session)
return 0;
}

thread = perf_session__findnew(session, self->mmap.pid);
machine = perf_session__find_host_machine(session);
if (machine == NULL)
goto out_problem;
thread = perf_session__findnew(session, self->mmap.pid);
map = map__new(&machine->user_dsos, self->mmap.start,
self->mmap.len, self->mmap.pgoff,
self->mmap.pid, self->mmap.filename,
Expand Down Expand Up @@ -552,14 +554,18 @@ void thread__find_addr_map(struct thread *self,
if (cpumode == PERF_RECORD_MISC_KERNEL && perf_host) {
al->level = 'k';
machine = perf_session__find_host_machine(session);
if (machine == NULL) {
al->map = NULL;
return;
}
mg = &machine->kmaps;
} else if (cpumode == PERF_RECORD_MISC_USER && perf_host) {
al->level = '.';
machine = perf_session__find_host_machine(session);
} else if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
al->level = 'g';
machine = perf_session__find_machine(session, pid);
if (!machine) {
if (machine == NULL) {
al->map = NULL;
return;
}
Expand Down Expand Up @@ -650,6 +656,16 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
goto out_filtered;

dump_printf(" ... thread: %s:%d\n", thread->comm, thread->pid);
/*
* Have we already created the kernel maps for the host machine?
*
* This should have happened earlier, when we processed the kernel MMAP
* events, but for older perf.data files there was no such thing, so do
* it now.
*/
if (cpumode == PERF_RECORD_MISC_KERNEL &&
session->host_machine.vmlinux_maps[MAP__FUNCTION] == NULL)
machine__create_kernel_maps(&session->host_machine);

thread__find_addr_map(thread, session, cpumode, MAP__FUNCTION,
self->ip.pid, self->ip.ip, al);
Expand All @@ -676,6 +692,13 @@ int event__preprocess_sample(const event_t *self, struct perf_session *session,
dso__calc_col_width(al->map->dso);

al->sym = map__find_symbol(al->map, al->addr, filter);
} else {
const unsigned int unresolved_col_width = BITS_PER_LONG / 4;

if (dsos__col_width < unresolved_col_width &&
!symbol_conf.col_width_list_str && !symbol_conf.field_sep &&
!symbol_conf.dso_list)
dsos__col_width = unresolved_col_width;
}

if (symbol_conf.sym_list && al->sym &&
Expand Down
46 changes: 33 additions & 13 deletions trunk/tools/perf/util/hist.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@ struct callchain_param callchain_param = {
.min_percent = 0.5
};

void __perf_session__add_count(struct hist_entry *he,
struct addr_location *al,
u64 count)
static void perf_session__add_cpumode_count(struct hist_entry *he,
unsigned int cpumode, u64 count)
{
he->count += count;

switch (al->cpumode) {
switch (cpumode) {
case PERF_RECORD_MISC_KERNEL:
he->count_sys += count;
break;
Expand All @@ -36,10 +33,24 @@ void __perf_session__add_count(struct hist_entry *he,
* 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 addr_location *al,
struct symbol *sym_parent,
u64 count, bool *hit)
u64 count)
{
struct rb_node **p = &hists->rb_node;
struct rb_node *parent = NULL;
Expand All @@ -64,8 +75,8 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
cmp = hist_entry__cmp(&entry, he);

if (!cmp) {
*hit = true;
return he;
he->count += count;
goto out;
}

if (cmp < 0)
Expand All @@ -74,14 +85,13 @@ struct hist_entry *__perf_session__add_hist_entry(struct rb_root *hists,
p = &(*p)->rb_right;
}

he = malloc(sizeof(*he) + (symbol_conf.use_callchain ?
sizeof(struct callchain_node) : 0));
he = hist_entry__new(&entry);
if (!he)
return NULL;
*he = entry;
rb_link_node(&he->rb_node, parent, p);
rb_insert_color(&he->rb_node, hists);
*hit = false;
out:
perf_session__add_cpumode_count(he, al->cpumode, count);
return he;
}

Expand Down Expand Up @@ -323,6 +333,7 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
u64 remaining;
size_t ret = 0;
int i;
uint entries_printed = 0;

if (callchain_param.mode == CHAIN_GRAPH_REL)
new_total = self->children_hit;
Expand Down Expand Up @@ -369,6 +380,8 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
new_depth_mask | (1 << depth),
left_margin);
node = next;
if (++entries_printed == callchain_param.print_limit)
break;
}

if (callchain_param.mode == CHAIN_GRAPH_REL &&
Expand All @@ -394,6 +407,7 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
bool printed = false;
int i = 0;
int ret = 0;
u32 entries_printed = 0;

list_for_each_entry(chain, &self->val, list) {
if (!i++ && sort__first_dimension == SORT_SYM)
Expand All @@ -414,6 +428,9 @@ static size_t callchain__fprintf_graph(FILE *fp, struct callchain_node *self,
ret += fprintf(fp, " %s\n", chain->ms.sym->name);
else
ret += fprintf(fp, " %p\n", (void *)(long)chain->ip);

if (++entries_printed == callchain_param.print_limit)
break;
}

ret += __callchain__fprintf_graph(fp, self, total_samples, 1, 1, left_margin);
Expand Down Expand Up @@ -452,6 +469,7 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
struct rb_node *rb_node;
struct callchain_node *chain;
size_t ret = 0;
u32 entries_printed = 0;

rb_node = rb_first(&self->sorted_chain);
while (rb_node) {
Expand All @@ -474,6 +492,8 @@ static size_t hist_entry_callchain__fprintf(FILE *fp, struct hist_entry *self,
break;
}
ret += fprintf(fp, "\n");
if (++entries_printed == callchain_param.print_limit)
break;
rb_node = rb_next(rb_node);
}

Expand Down
5 changes: 1 addition & 4 deletions trunk/tools/perf/util/hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ struct addr_location;
struct symbol;
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 addr_location *al,
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__collapse(struct hist_entry *, struct hist_entry *);
int hist_entry__fprintf(struct hist_entry *self,
Expand Down
Loading

0 comments on commit b6d7787

Please sign in to comment.