Commit 8eb22c98 authored by Ingo Molnar's avatar Ingo Molnar

Merge tag 'perf-core-for-mingo-3' of...

Merge tag 'perf-core-for-mingo-3' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux into perf/core

Pull perf/core callchain fixes and improvements from Arnaldo Carvalho de Melo <acme@redhat.com:

User visible changes:

  - Make --percent-limit apply to callchains also and fix some bugs
    related to --percent-limit (Namhyung Kim)
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
parents d072b89d 3848c23b
...@@ -75,7 +75,10 @@ static int report__config(const char *var, const char *value, void *cb) ...@@ -75,7 +75,10 @@ static int report__config(const char *var, const char *value, void *cb)
return 0; return 0;
} }
if (!strcmp(var, "report.percent-limit")) { if (!strcmp(var, "report.percent-limit")) {
rep->min_percent = strtof(value, NULL); double pcnt = strtof(value, NULL);
rep->min_percent = pcnt;
callchain_param.min_percent = pcnt;
return 0; return 0;
} }
if (!strcmp(var, "report.children")) { if (!strcmp(var, "report.children")) {
...@@ -633,8 +636,10 @@ parse_percent_limit(const struct option *opt, const char *str, ...@@ -633,8 +636,10 @@ parse_percent_limit(const struct option *opt, const char *str,
int unset __maybe_unused) int unset __maybe_unused)
{ {
struct report *rep = opt->value; struct report *rep = opt->value;
double pcnt = strtof(str, NULL);
rep->min_percent = strtof(str, NULL); rep->min_percent = pcnt;
callchain_param.min_percent = pcnt;
return 0; return 0;
} }
......
...@@ -657,9 +657,24 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser, ...@@ -657,9 +657,24 @@ static int hist_browser__show_callchain_list(struct hist_browser *browser,
return 1; return 1;
} }
static bool check_percent_display(struct rb_node *node, u64 parent_total)
{
struct callchain_node *child;
if (node == NULL)
return false;
if (rb_next(node))
return true;
child = rb_entry(node, struct callchain_node, rb_node);
return callchain_cumul_hits(child) != parent_total;
}
static int hist_browser__show_callchain_flat(struct hist_browser *browser, static int hist_browser__show_callchain_flat(struct hist_browser *browser,
struct rb_root *root, struct rb_root *root,
unsigned short row, u64 total, unsigned short row, u64 total,
u64 parent_total,
print_callchain_entry_fn print, print_callchain_entry_fn print,
struct callchain_print_arg *arg, struct callchain_print_arg *arg,
check_output_full_fn is_output_full) check_output_full_fn is_output_full)
...@@ -669,7 +684,7 @@ static int hist_browser__show_callchain_flat(struct hist_browser *browser, ...@@ -669,7 +684,7 @@ static int hist_browser__show_callchain_flat(struct hist_browser *browser,
bool need_percent; bool need_percent;
node = rb_first(root); node = rb_first(root);
need_percent = node && rb_next(node); need_percent = check_percent_display(node, parent_total);
while (node) { while (node) {
struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
...@@ -763,6 +778,7 @@ static char *hist_browser__folded_callchain_str(struct hist_browser *browser, ...@@ -763,6 +778,7 @@ static char *hist_browser__folded_callchain_str(struct hist_browser *browser,
static int hist_browser__show_callchain_folded(struct hist_browser *browser, static int hist_browser__show_callchain_folded(struct hist_browser *browser,
struct rb_root *root, struct rb_root *root,
unsigned short row, u64 total, unsigned short row, u64 total,
u64 parent_total,
print_callchain_entry_fn print, print_callchain_entry_fn print,
struct callchain_print_arg *arg, struct callchain_print_arg *arg,
check_output_full_fn is_output_full) check_output_full_fn is_output_full)
...@@ -772,7 +788,7 @@ static int hist_browser__show_callchain_folded(struct hist_browser *browser, ...@@ -772,7 +788,7 @@ static int hist_browser__show_callchain_folded(struct hist_browser *browser,
bool need_percent; bool need_percent;
node = rb_first(root); node = rb_first(root);
need_percent = node && rb_next(node); need_percent = check_percent_display(node, parent_total);
while (node) { while (node) {
struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
...@@ -844,20 +860,24 @@ static int hist_browser__show_callchain_folded(struct hist_browser *browser, ...@@ -844,20 +860,24 @@ static int hist_browser__show_callchain_folded(struct hist_browser *browser,
return row - first_row; return row - first_row;
} }
static int hist_browser__show_callchain(struct hist_browser *browser, static int hist_browser__show_callchain_graph(struct hist_browser *browser,
struct rb_root *root, int level, struct rb_root *root, int level,
unsigned short row, u64 total, unsigned short row, u64 total,
u64 parent_total,
print_callchain_entry_fn print, print_callchain_entry_fn print,
struct callchain_print_arg *arg, struct callchain_print_arg *arg,
check_output_full_fn is_output_full) check_output_full_fn is_output_full)
{ {
struct rb_node *node; struct rb_node *node;
int first_row = row, offset = level * LEVEL_OFFSET_STEP; int first_row = row, offset = level * LEVEL_OFFSET_STEP;
u64 new_total;
bool need_percent; bool need_percent;
u64 percent_total = total;
if (callchain_param.mode == CHAIN_GRAPH_REL)
percent_total = parent_total;
node = rb_first(root); node = rb_first(root);
need_percent = node && rb_next(node); need_percent = check_percent_display(node, parent_total);
while (node) { while (node) {
struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node); struct callchain_node *child = rb_entry(node, struct callchain_node, rb_node);
...@@ -878,7 +898,7 @@ static int hist_browser__show_callchain(struct hist_browser *browser, ...@@ -878,7 +898,7 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
folded_sign = callchain_list__folded(chain); folded_sign = callchain_list__folded(chain);
row += hist_browser__show_callchain_list(browser, child, row += hist_browser__show_callchain_list(browser, child,
chain, row, total, chain, row, percent_total,
was_first && need_percent, was_first && need_percent,
offset + extra_offset, offset + extra_offset,
print, arg); print, arg);
...@@ -893,13 +913,9 @@ static int hist_browser__show_callchain(struct hist_browser *browser, ...@@ -893,13 +913,9 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
if (folded_sign == '-') { if (folded_sign == '-') {
const int new_level = level + (extra_offset ? 2 : 1); const int new_level = level + (extra_offset ? 2 : 1);
if (callchain_param.mode == CHAIN_GRAPH_REL) row += hist_browser__show_callchain_graph(browser, &child->rb_root,
new_total = child->children_hit; new_level, row, total,
else child->children_hit,
new_total = total;
row += hist_browser__show_callchain(browser, &child->rb_root,
new_level, row, new_total,
print, arg, is_output_full); print, arg, is_output_full);
} }
if (is_output_full(browser, row)) if (is_output_full(browser, row))
...@@ -910,6 +926,45 @@ static int hist_browser__show_callchain(struct hist_browser *browser, ...@@ -910,6 +926,45 @@ static int hist_browser__show_callchain(struct hist_browser *browser,
return row - first_row; return row - first_row;
} }
static int hist_browser__show_callchain(struct hist_browser *browser,
struct hist_entry *entry, int level,
unsigned short row,
print_callchain_entry_fn print,
struct callchain_print_arg *arg,
check_output_full_fn is_output_full)
{
u64 total = hists__total_period(entry->hists);
u64 parent_total;
int printed;
if (symbol_conf.cumulate_callchain)
parent_total = entry->stat_acc->period;
else
parent_total = entry->stat.period;
if (callchain_param.mode == CHAIN_FLAT) {
printed = hist_browser__show_callchain_flat(browser,
&entry->sorted_chain, row,
total, parent_total, print, arg,
is_output_full);
} else if (callchain_param.mode == CHAIN_FOLDED) {
printed = hist_browser__show_callchain_folded(browser,
&entry->sorted_chain, row,
total, parent_total, print, arg,
is_output_full);
} else {
printed = hist_browser__show_callchain_graph(browser,
&entry->sorted_chain, level, row,
total, parent_total, print, arg,
is_output_full);
}
if (arg->is_current_entry)
browser->he_selection = entry;
return printed;
}
struct hpp_arg { struct hpp_arg {
struct ui_browser *b; struct ui_browser *b;
char folded_sign; char folded_sign;
...@@ -1084,38 +1139,14 @@ static int hist_browser__show_entry(struct hist_browser *browser, ...@@ -1084,38 +1139,14 @@ static int hist_browser__show_entry(struct hist_browser *browser,
--row_offset; --row_offset;
if (folded_sign == '-' && row != browser->b.rows) { if (folded_sign == '-' && row != browser->b.rows) {
u64 total = hists__total_period(entry->hists);
struct callchain_print_arg arg = { struct callchain_print_arg arg = {
.row_offset = row_offset, .row_offset = row_offset,
.is_current_entry = current_entry, .is_current_entry = current_entry,
}; };
if (callchain_param.mode == CHAIN_GRAPH_REL) { printed += hist_browser__show_callchain(browser, entry, 1, row,
if (symbol_conf.cumulate_callchain)
total = entry->stat_acc->period;
else
total = entry->stat.period;
}
if (callchain_param.mode == CHAIN_FLAT) {
printed += hist_browser__show_callchain_flat(browser,
&entry->sorted_chain, row, total,
hist_browser__show_callchain_entry, &arg,
hist_browser__check_output_full);
} else if (callchain_param.mode == CHAIN_FOLDED) {
printed += hist_browser__show_callchain_folded(browser,
&entry->sorted_chain, row, total,
hist_browser__show_callchain_entry, &arg,
hist_browser__check_output_full);
} else {
printed += hist_browser__show_callchain(browser,
&entry->sorted_chain, 1, row, total,
hist_browser__show_callchain_entry, &arg, hist_browser__show_callchain_entry, &arg,
hist_browser__check_output_full); hist_browser__check_output_full);
}
if (arg.is_current_entry)
browser->he_selection = entry;
} }
return printed; return printed;
...@@ -1380,15 +1411,11 @@ static void ui_browser__hists_seek(struct ui_browser *browser, ...@@ -1380,15 +1411,11 @@ static void ui_browser__hists_seek(struct ui_browser *browser,
static int hist_browser__fprintf_callchain(struct hist_browser *browser, static int hist_browser__fprintf_callchain(struct hist_browser *browser,
struct hist_entry *he, FILE *fp) struct hist_entry *he, FILE *fp)
{ {
u64 total = hists__total_period(he->hists);
struct callchain_print_arg arg = { struct callchain_print_arg arg = {
.fp = fp, .fp = fp,
}; };
if (symbol_conf.cumulate_callchain) hist_browser__show_callchain(browser, he, 1, 0,
total = he->stat_acc->period;
hist_browser__show_callchain(browser, &he->sorted_chain, 1, 0, total,
hist_browser__fprintf_callchain_entry, &arg, hist_browser__fprintf_callchain_entry, &arg,
hist_browser__check_dump_full); hist_browser__check_dump_full);
return arg.printed; return arg.printed;
......
...@@ -165,8 +165,28 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root, ...@@ -165,8 +165,28 @@ static size_t __callchain__fprintf_graph(FILE *fp, struct rb_root *root,
return ret; return ret;
} }
/*
* If have one single callchain root, don't bother printing
* its percentage (100 % in fractal mode and the same percentage
* than the hist in graph mode). This also avoid one level of column.
*
* However when percent-limit applied, it's possible that single callchain
* node have different (non-100% in fractal mode) percentage.
*/
static bool need_percent_display(struct rb_node *node, u64 parent_samples)
{
struct callchain_node *cnode;
if (rb_next(node))
return true;
cnode = rb_entry(node, struct callchain_node, rb_node);
return callchain_cumul_hits(cnode) != parent_samples;
}
static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
u64 total_samples, int left_margin) u64 total_samples, u64 parent_samples,
int left_margin)
{ {
struct callchain_node *cnode; struct callchain_node *cnode;
struct callchain_list *chain; struct callchain_list *chain;
...@@ -177,13 +197,8 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, ...@@ -177,13 +197,8 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
int ret = 0; int ret = 0;
char bf[1024]; char bf[1024];
/*
* If have one single callchain root, don't bother printing
* its percentage (100 % in fractal mode and the same percentage
* than the hist in graph mode). This also avoid one level of column.
*/
node = rb_first(root); node = rb_first(root);
if (node && !rb_next(node)) { if (node && !need_percent_display(node, parent_samples)) {
cnode = rb_entry(node, struct callchain_node, rb_node); cnode = rb_entry(node, struct callchain_node, rb_node);
list_for_each_entry(chain, &cnode->val, list) { list_for_each_entry(chain, &cnode->val, list) {
/* /*
...@@ -213,9 +228,15 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root, ...@@ -213,9 +228,15 @@ static size_t callchain__fprintf_graph(FILE *fp, struct rb_root *root,
root = &cnode->rb_root; root = &cnode->rb_root;
} }
if (callchain_param.mode == CHAIN_GRAPH_REL)
total_samples = parent_samples;
ret += __callchain__fprintf_graph(fp, root, total_samples, ret += __callchain__fprintf_graph(fp, root, total_samples,
1, 1, left_margin); 1, 1, left_margin);
ret += fprintf(fp, "\n"); if (ret) {
/* do not add a blank line if it printed nothing */
ret += fprintf(fp, "\n");
}
return ret; return ret;
} }
...@@ -323,16 +344,19 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, ...@@ -323,16 +344,19 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
u64 total_samples, int left_margin, u64 total_samples, int left_margin,
FILE *fp) FILE *fp)
{ {
u64 parent_samples = he->stat.period;
if (symbol_conf.cumulate_callchain)
parent_samples = he->stat_acc->period;
switch (callchain_param.mode) { switch (callchain_param.mode) {
case CHAIN_GRAPH_REL: case CHAIN_GRAPH_REL:
return callchain__fprintf_graph(fp, &he->sorted_chain, return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
symbol_conf.cumulate_callchain ? parent_samples, left_margin);
he->stat_acc->period : he->stat.period,
left_margin);
break; break;
case CHAIN_GRAPH_ABS: case CHAIN_GRAPH_ABS:
return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples, return callchain__fprintf_graph(fp, &he->sorted_chain, total_samples,
left_margin); parent_samples, left_margin);
break; break;
case CHAIN_FLAT: case CHAIN_FLAT:
return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples); return callchain__fprintf_flat(fp, &he->sorted_chain, total_samples);
...@@ -349,30 +373,6 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he, ...@@ -349,30 +373,6 @@ static size_t hist_entry_callchain__fprintf(struct hist_entry *he,
return 0; return 0;
} }
static size_t hist_entry__callchain_fprintf(struct hist_entry *he,
struct hists *hists,
FILE *fp)
{
int left_margin = 0;
u64 total_period = hists->stats.total_period;
if (field_order == NULL && (sort_order == NULL ||
!prefixcmp(sort_order, "comm"))) {
struct perf_hpp_fmt *fmt;
perf_hpp__for_each_format(fmt) {
if (!perf_hpp__is_sort_entry(fmt))
continue;
/* must be 'comm' sort entry */
left_margin = fmt->width(fmt, NULL, hists_to_evsel(hists));
left_margin -= thread__comm_len(he->thread);
break;
}
}
return hist_entry_callchain__fprintf(he, total_period, left_margin, fp);
}
static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp) static int hist_entry__snprintf(struct hist_entry *he, struct perf_hpp *hpp)
{ {
const char *sep = symbol_conf.field_sep; const char *sep = symbol_conf.field_sep;
...@@ -418,6 +418,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ...@@ -418,6 +418,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
.buf = bf, .buf = bf,
.size = size, .size = size,
}; };
u64 total_period = hists->stats.total_period;
if (size == 0 || size > bfsz) if (size == 0 || size > bfsz)
size = hpp.size = bfsz; size = hpp.size = bfsz;
...@@ -427,7 +428,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size, ...@@ -427,7 +428,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
ret = fprintf(fp, "%s\n", bf); ret = fprintf(fp, "%s\n", bf);
if (symbol_conf.use_callchain) if (symbol_conf.use_callchain)
ret += hist_entry__callchain_fprintf(he, hists, fp); ret += hist_entry_callchain__fprintf(he, total_period, 0, fp);
return ret; return ret;
} }
......
...@@ -432,8 +432,12 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists, ...@@ -432,8 +432,12 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,
cmp = hist_entry__cmp(he, entry); cmp = hist_entry__cmp(he, entry);
if (!cmp) { if (!cmp) {
if (sample_self) if (sample_self) {
he_stat__add_period(&he->stat, period, weight); he_stat__add_period(&he->stat, period, weight);
hists->stats.total_period += period;
if (!he->filtered)
hists->stats.total_non_filtered_period += period;
}
if (symbol_conf.cumulate_callchain) if (symbol_conf.cumulate_callchain)
he_stat__add_period(he->stat_acc, period, weight); he_stat__add_period(he->stat_acc, period, weight);
...@@ -466,7 +470,10 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists, ...@@ -466,7 +470,10 @@ static struct hist_entry *hists__findnew_entry(struct hists *hists,
if (!he) if (!he)
return NULL; return NULL;
hists->nr_entries++; if (sample_self)
hists__inc_stats(hists, he);
else
hists->nr_entries++;
rb_link_node(&he->rb_node_in, parent, p); rb_link_node(&he->rb_node_in, parent, p);
rb_insert_color(&he->rb_node_in, hists->entries_in); rb_insert_color(&he->rb_node_in, hists->entries_in);
...@@ -1163,9 +1170,18 @@ static void __hists__insert_output_entry(struct rb_root *entries, ...@@ -1163,9 +1170,18 @@ static void __hists__insert_output_entry(struct rb_root *entries,
struct rb_node *parent = NULL; struct rb_node *parent = NULL;
struct hist_entry *iter; struct hist_entry *iter;
if (use_callchain) if (use_callchain) {
if (callchain_param.mode == CHAIN_GRAPH_REL) {
u64 total = he->stat.period;
if (symbol_conf.cumulate_callchain)
total = he->stat_acc->period;
min_callchain_hits = total * (callchain_param.min_percent / 100);
}
callchain_param.sort(&he->sorted_chain, he->callchain, callchain_param.sort(&he->sorted_chain, he->callchain,
min_callchain_hits, &callchain_param); min_callchain_hits, &callchain_param);
}
while (*p != NULL) { while (*p != NULL) {
parent = *p; parent = *p;
...@@ -1195,7 +1211,7 @@ void hists__output_resort(struct hists *hists, struct ui_progress *prog) ...@@ -1195,7 +1211,7 @@ void hists__output_resort(struct hists *hists, struct ui_progress *prog)
else else
use_callchain = symbol_conf.use_callchain; use_callchain = symbol_conf.use_callchain;
min_callchain_hits = hists->stats.total_period * (callchain_param.min_percent / 100); min_callchain_hits = hists__total_period(hists) * (callchain_param.min_percent / 100);
if (sort__need_collapse) if (sort__need_collapse)
root = &hists->entries_collapsed; root = &hists->entries_collapsed;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment