Skip to content

Commit fabd37b

Browse files
committed
perf hists: Check if a hist_entry has callchains before using them
So far if we use 'perf record -g' this will make symbol_conf.use_callchain 'true' and logic will assume that all events have callchains enabled, but ever since we added the possibility of setting up callchains for some events (e.g.: -e cycles/call-graph=dwarf/) while not for others, we limit usage scenarios by looking at that symbol_conf.use_callchain global boolean, we better look at each event attributes. On the road to that we need to look if a hist_entry has callchains, that is, to go from hist_entry->hists to the evsel that contains it, to then look at evsel->sample_type for PERF_SAMPLE_CALLCHAIN. The next step is to add a symbol_conf.ignore_callchains global, to use in the places where what we really want to know is if callchains should be ignored, even if present. Then -g will mean just to select a callchain mode to be applied to all events not explicitely setting some other callchain mode, i.e. a default callchain mode, and --no-call-graph will set symbol_conf.ignore_callchains with that clear intention. That too will at some point become a per evsel thing, that tools can set for all or just a few of its evsels. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: https://lkml.kernel.org/n/tip-0sas5cm4dsw2obn75g7ruz69@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0b5d6ec commit fabd37b

7 files changed

Lines changed: 25 additions & 17 deletions

File tree

‎tools/perf/ui/browsers/hists.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,6 +1231,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
12311231
int width = browser->b.width;
12321232
char folded_sign = ' ';
12331233
bool current_entry = ui_browser__is_current_entry(&browser->b, row);
1234+
bool use_callchain = hist_entry__has_callchains(entry) && symbol_conf.use_callchain;
12341235
off_t row_offset = entry->row_offset;
12351236
bool first = true;
12361237
struct perf_hpp_fmt *fmt;
@@ -1240,7 +1241,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
12401241
browser->selection = &entry->ms;
12411242
}
12421243

1243-
if (symbol_conf.use_callchain) {
1244+
if (use_callchain) {
12441245
hist_entry__init_have_children(entry);
12451246
folded_sign = hist_entry__folded(entry);
12461247
}
@@ -1276,7 +1277,7 @@ static int hist_browser__show_entry(struct hist_browser *browser,
12761277
}
12771278

12781279
if (first) {
1279-
if (symbol_conf.use_callchain) {
1280+
if (use_callchain) {
12801281
ui_browser__printf(&browser->b, "%c ", folded_sign);
12811282
width -= 2;
12821283
}
@@ -1583,7 +1584,7 @@ hists_browser__scnprintf_headers(struct hist_browser *browser, char *buf,
15831584
int column = 0;
15841585
int span = 0;
15851586

1586-
if (symbol_conf.use_callchain) {
1587+
if (hists__has_callchains(hists) && symbol_conf.use_callchain) {
15871588
ret = scnprintf(buf, size, " ");
15881589
if (advance_hpp_check(&dummy_hpp, ret))
15891590
return ret;
@@ -1987,7 +1988,7 @@ static int hist_browser__fprintf_entry(struct hist_browser *browser,
19871988
bool first = true;
19881989
int ret;
19891990

1990-
if (symbol_conf.use_callchain) {
1991+
if (hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
19911992
folded_sign = hist_entry__folded(he);
19921993
printed += fprintf(fp, "%c ", folded_sign);
19931994
}
@@ -2671,7 +2672,7 @@ static void hist_browser__update_percent_limit(struct hist_browser *hb,
26712672
he->nr_rows = 0;
26722673
}
26732674

2674-
if (!he->leaf || !symbol_conf.use_callchain)
2675+
if (!he->leaf || !hist_entry__has_callchains(he) || !symbol_conf.use_callchain)
26752676
goto next;
26762677

26772678
if (callchain_param.mode == CHAIN_GRAPH_REL) {

‎tools/perf/ui/gtk/hists.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ static void perf_gtk__show_hists(GtkWidget *window, struct hists *hists,
382382
gtk_tree_store_set(store, &iter, col_idx++, s, -1);
383383
}
384384

385-
if (symbol_conf.use_callchain && hists__has(hists, sym)) {
385+
if (hists__has_callchains(hists) &&
386+
symbol_conf.use_callchain && hists__has(hists, sym)) {
386387
if (callchain_param.mode == CHAIN_GRAPH_REL)
387388
total = symbol_conf.cumulate_callchain ?
388389
h->stat_acc->period : h->stat.period;
@@ -479,7 +480,7 @@ static void perf_gtk__add_hierarchy_entries(struct hists *hists,
479480
}
480481
}
481482

482-
if (symbol_conf.use_callchain && he->leaf) {
483+
if (he->leaf && hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
483484
if (callchain_param.mode == CHAIN_GRAPH_REL)
484485
total = symbol_conf.cumulate_callchain ?
485486
he->stat_acc->period : he->stat.period;

‎tools/perf/ui/hist.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int __hpp__sort_acc(struct hist_entry *a, struct hist_entry *b,
207207
if (ret)
208208
return ret;
209209

210-
if (a->thread != b->thread || !symbol_conf.use_callchain)
210+
if (a->thread != b->thread || !hist_entry__has_callchains(a) || !symbol_conf.use_callchain)
211211
return 0;
212212

213213
ret = b->callchain->max_depth - a->callchain->max_depth;

‎tools/perf/ui/stdio/hist.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static int hist_entry__hierarchy_fprintf(struct hist_entry *he,
516516
}
517517
printed += putc('\n', fp);
518518

519-
if (symbol_conf.use_callchain && he->leaf) {
519+
if (he->leaf && hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
520520
u64 total = hists__total_period(hists);
521521

522522
printed += hist_entry_callchain__fprintf(he, total, 0, fp);
@@ -550,7 +550,7 @@ static int hist_entry__fprintf(struct hist_entry *he, size_t size,
550550

551551
ret = fprintf(fp, "%s\n", bf);
552552

553-
if (use_callchain)
553+
if (hist_entry__has_callchains(he) && use_callchain)
554554
callchain_ret = hist_entry_callchain__fprintf(he, total_period,
555555
0, fp);
556556

‎tools/perf/util/hist.c‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ static int hist_entry__init(struct hist_entry *he,
410410
map__get(he->mem_info->daddr.map);
411411
}
412412

413-
if (symbol_conf.use_callchain)
413+
if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
414414
callchain_init(he->callchain);
415415

416416
if (he->raw_data) {
@@ -492,7 +492,7 @@ static u8 symbol__parent_filter(const struct symbol *parent)
492492

493493
static void hist_entry__add_callchain_period(struct hist_entry *he, u64 period)
494494
{
495-
if (!symbol_conf.use_callchain)
495+
if (!hist_entry__has_callchains(he) || !symbol_conf.use_callchain)
496496
return;
497497

498498
he->hists->callchain_period += period;
@@ -986,7 +986,7 @@ iter_add_next_cumulative_entry(struct hist_entry_iter *iter,
986986
iter->he = he;
987987
he_cache[iter->curr++] = he;
988988

989-
if (symbol_conf.use_callchain)
989+
if (hist_entry__has_callchains(he) && symbol_conf.use_callchain)
990990
callchain_append(he->callchain, &cursor, sample->period);
991991
return 0;
992992
}
@@ -1373,7 +1373,8 @@ static int hists__hierarchy_insert_entry(struct hists *hists,
13731373
if (new_he) {
13741374
new_he->leaf = true;
13751375

1376-
if (symbol_conf.use_callchain) {
1376+
if (hist_entry__has_callchains(new_he) &&
1377+
symbol_conf.use_callchain) {
13771378
callchain_cursor_reset(&callchain_cursor);
13781379
if (callchain_merge(&callchain_cursor,
13791380
new_he->callchain,
@@ -1414,7 +1415,7 @@ static int hists__collapse_insert_entry(struct hists *hists,
14141415
if (symbol_conf.cumulate_callchain)
14151416
he_stat__add_stat(iter->stat_acc, he->stat_acc);
14161417

1417-
if (symbol_conf.use_callchain) {
1418+
if (hist_entry__has_callchains(he) && symbol_conf.use_callchain) {
14181419
callchain_cursor_reset(&callchain_cursor);
14191420
if (callchain_merge(&callchain_cursor,
14201421
iter->callchain,

‎tools/perf/util/hist.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ static inline struct hists *evsel__hists(struct perf_evsel *evsel)
220220
return &hevsel->hists;
221221
}
222222

223+
static __pure inline bool hists__has_callchains(struct hists *hists)
224+
{
225+
const struct perf_evsel *evsel = hists_to_evsel(hists);
226+
return evsel__has_callchain(evsel);
227+
}
228+
223229
int hists__init(void);
224230
int __hists__init(struct hists *hists, struct perf_hpp_list *hpp_list);
225231

‎tools/perf/util/sort.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,7 @@ struct hist_entry {
153153

154154
static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
155155
{
156-
const struct perf_evsel *evsel = hists_to_evsel(he->hists);
157-
return evsel__has_callchain(evsel);
156+
return hists__has_callchains(he->hists);
158157
}
159158

160159
static inline bool hist_entry__has_pairs(struct hist_entry *he)

0 commit comments

Comments
 (0)