Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf hists: Reimplement hists__has_callchains()

There are places where we have only access to struct hists and need to
know if any of its hist_entries has callchains, like when drawing
headers for the various output modes (stdio, TUI, etc), so, when adding
a new hist_entry, check if it has callchains, storing this info for
later use by hists__has_callchains().

This reimplementation is necessary because not always a 'struct hists'
is allocated together with a 'struct perf evsel', so we can't go from
'hists' to 'perf_event_attr.sample_type & PERF_SAMPLE_CALLCHAIN'.

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jin Yao <yao.jin@linux.intel.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-hg5g7yddjio3ljwyqnnaj5dt@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+6 -4
+4 -2
tools/perf/util/hist.c
··· 621 621 .raw_data = sample->raw_data, 622 622 .raw_size = sample->raw_size, 623 623 .ops = ops, 624 - }; 624 + }, *he = hists__findnew_entry(hists, &entry, al, sample_self); 625 625 626 - return hists__findnew_entry(hists, &entry, al, sample_self); 626 + if (!hists->has_callchains && he && he->callchain_size != 0) 627 + hists->has_callchains = true; 628 + return he; 627 629 } 628 630 629 631 struct hist_entry *hists__add_entry(struct hists *hists,
+2 -2
tools/perf/util/hist.h
··· 85 85 struct events_stats stats; 86 86 u64 event_stream; 87 87 u16 col_len[HISTC_NR_COLS]; 88 + bool has_callchains; 88 89 int socket_filter; 89 90 struct perf_hpp_list *hpp_list; 90 91 struct list_head hpp_formats; ··· 223 222 224 223 static __pure inline bool hists__has_callchains(struct hists *hists) 225 224 { 226 - const struct perf_evsel *evsel = hists_to_evsel(hists); 227 - return evsel__has_callchain(evsel); 225 + return hists->has_callchains; 228 226 } 229 227 230 228 int hists__init(void);