Skip to content

Commit

Permalink
perf_counter tools: Set the minimum percent for callchains to be disp…
Browse files Browse the repository at this point in the history
…layed

Callchains output may become a burden on a trace because even
rarely hit site are exposed. This can be too much information.

Let the user set a threshold as a minimum percent of hits using
the new pattern for the -c option:

    -c mode,min_percent

Example:

$ perf report -s sym -c flat,4

     8.25%  [k] copy_user_generic_string
             4.19%
                copy_user_generic_string
                generic_file_aio_read
                do_sync_read
                vfs_read
                sys_pread64
                system_call_fastpath
                pread64

     5.39%  [k] search_by_key
     4.63%  0x00000000009e0a
     2.36%  [k] memcpy_c
[...]

$ perf report -s sym -c graph,2

     8.25%  [k] copy_user_generic_string
                |
                |--4.31%-- generic_file_aio_read
                |          do_sync_read
                |          vfs_read
                |          |
                |           --4.19%-- sys_pread64
                |                     system_call_fastpath
                |                     pread64
                |
                 --3.24%-- generic_file_buffered_write
                           __generic_file_aio_write_nolock
                           generic_file_aio_write
                           do_sync_write
                           reiserfs_file_write
                           vfs_write
                           |
                            --3.14%-- sys_pwrite64
                                      system_call_fastpath
                                      __pwrite64

     5.39%  [k] search_by_key
                |
                 --2.23%-- reiserfs_update_sd_size

     4.63%  0x00000000009e0a

     2.36%  [k] memcpy_c
[...]

You can also omit it and it will default to 0.

Signed-off-by: Frederic Weisbecker <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Mike Galbraith <[email protected]>
Cc: Paul Mackerras <[email protected]>
Cc: Anton Blanchard <[email protected]>
Cc: Arnaldo Carvalho de Melo <[email protected]>
LKML-Reference: <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
fweisbec authored and Ingo Molnar committed Jul 2, 2009
1 parent 4eb3e47 commit c20ab37
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
45 changes: 34 additions & 11 deletions tools/perf/builtin-report.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static regex_t parent_regex;
static int exclude_other = 1;
static int callchain;
static enum chain_mode callchain_mode;
static double callchain_min_percent = 0.0;

static u64 sample_type;

Expand Down Expand Up @@ -1224,17 +1225,19 @@ static void collapse__resort(void)

static struct rb_root output_hists;

static void output__insert_entry(struct hist_entry *he)
static void output__insert_entry(struct hist_entry *he, u64 min_callchain_hits)
{
struct rb_node **p = &output_hists.rb_node;
struct rb_node *parent = NULL;
struct hist_entry *iter;

if (callchain) {
if (callchain_mode == FLAT)
sort_chain_flat(&he->sorted_chain, &he->callchain);
sort_chain_flat(&he->sorted_chain, &he->callchain,
min_callchain_hits);
else if (callchain_mode == GRAPH)
sort_chain_graph(&he->sorted_chain, &he->callchain);
sort_chain_graph(&he->sorted_chain, &he->callchain,
min_callchain_hits);
}

while (*p != NULL) {
Expand All @@ -1251,11 +1254,14 @@ static void output__insert_entry(struct hist_entry *he)
rb_insert_color(&he->rb_node, &output_hists);
}

static void output__resort(void)
static void output__resort(u64 total_samples)
{
struct rb_node *next;
struct hist_entry *n;
struct rb_root *tree = &hist;
u64 min_callchain_hits;

min_callchain_hits = total_samples * (callchain_min_percent / 100);

if (sort__need_collapse)
tree = &collapse_hists;
Expand All @@ -1267,7 +1273,7 @@ static void output__resort(void)
next = rb_next(&n->rb_node);

rb_erase(&n->rb_node, tree);
output__insert_entry(n);
output__insert_entry(n, min_callchain_hits);
}
}

Expand Down Expand Up @@ -1801,7 +1807,7 @@ static int __cmd_report(void)
dsos__fprintf(stdout);

collapse__resort();
output__resort();
output__resort(total);
output__fprintf(stdout, total);

return rc;
Expand All @@ -1811,19 +1817,36 @@ static int
parse_callchain_opt(const struct option *opt __used, const char *arg,
int unset __used)
{
char *tok;
char *endptr;

callchain = 1;

if (!arg)
return 0;

if (!strncmp(arg, "graph", strlen(arg)))
tok = strtok((char *)arg, ",");
if (!tok)
return -1;

/* get the output mode */
if (!strncmp(tok, "graph", strlen(arg)))
callchain_mode = GRAPH;

else if (!strncmp(arg, "flat", strlen(arg)))
else if (!strncmp(tok, "flat", strlen(arg)))
callchain_mode = FLAT;
else
return -1;

/* get the min percentage */
tok = strtok(NULL, ",");
if (!tok)
return 0;

callchain_min_percent = strtod(tok, &endptr);
if (tok == endptr)
return -1;

return 0;
}

Expand All @@ -1850,9 +1873,9 @@ static const struct option options[] = {
"regex filter to identify parent, see: '--sort parent'"),
OPT_BOOLEAN('x', "exclude-other", &exclude_other,
"Only display entries with parent-match"),
OPT_CALLBACK_DEFAULT('c', "callchain", NULL, "output_type",
"Display callchains with output_type: flat, graph. "
"Default to flat", &parse_callchain_opt, "flat"),
OPT_CALLBACK_DEFAULT('c', "callchain", NULL, "output_type,min_percent",
"Display callchains using output_type and min percent threshold. "
"Default: flat,0", &parse_callchain_opt, "flat,100"),
OPT_STRING('d', "dsos", &dso_list_str, "dso[,dso...]",
"only consider symbols in these dsos"),
OPT_STRING('C', "comms", &comm_list_str, "comm[,comm...]",
Expand Down
19 changes: 11 additions & 8 deletions tools/perf/util/callchain.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,38 @@ rb_insert_callchain(struct rb_root *root, struct callchain_node *chain,
* Once we get every callchains from the stream, we can now
* sort them by hit
*/
void sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node)
void sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node,
u64 min_hit)
{
struct callchain_node *child;

chain_for_each_child(child, node)
sort_chain_flat(rb_root, child);
sort_chain_flat(rb_root, child, min_hit);

if (node->hit)
if (node->hit && node->hit >= min_hit)
rb_insert_callchain(rb_root, node, FLAT);
}

static void __sort_chain_graph(struct callchain_node *node)
static void __sort_chain_graph(struct callchain_node *node, u64 min_hit)
{
struct callchain_node *child;

node->rb_root = RB_ROOT;
node->cumul_hit = node->hit;

chain_for_each_child(child, node) {
__sort_chain_graph(child);
rb_insert_callchain(&node->rb_root, child, GRAPH);
__sort_chain_graph(child, min_hit);
if (child->cumul_hit >= min_hit)
rb_insert_callchain(&node->rb_root, child, GRAPH);
node->cumul_hit += child->cumul_hit;
}
}

void
sort_chain_graph(struct rb_root *rb_root, struct callchain_node *chain_root)
sort_chain_graph(struct rb_root *rb_root, struct callchain_node *chain_root,
u64 min_hit)
{
__sort_chain_graph(chain_root);
__sort_chain_graph(chain_root, min_hit);
rb_root->rb_node = chain_root->rb_root.rb_node;
}

Expand Down
6 changes: 4 additions & 2 deletions tools/perf/util/callchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ static inline void callchain_init(struct callchain_node *node)

void append_chain(struct callchain_node *root, struct ip_callchain *chain,
struct symbol **syms);
void sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node);
void sort_chain_graph(struct rb_root *rb_root, struct callchain_node *node);
void sort_chain_flat(struct rb_root *rb_root, struct callchain_node *node,
u64 min_hit);
void sort_chain_graph(struct rb_root *rb_root, struct callchain_node *node,
u64 min_hit);
#endif

0 comments on commit c20ab37

Please sign in to comment.