Skip to content

Commit bdc633f

Browse files
committed
perf report/top: Improve toggle callchain menu option
Taking into account the current status of the callchain, i.e. if folded, show "Expand", otherwise "Collapse", also show the name of the entry that will be affected and mention the hotkeys for expanding/collapsing all callchains below the main entry, the one that appears with/without callchains. Reviewed-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Namhyung Kim <namhyung@kernel.org> Link: https://lkml.kernel.org/n/tip-03arm6poo8463k5tfcfp7gkk@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent d5a599d commit bdc633f

3 files changed

Lines changed: 54 additions & 5 deletions

File tree

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

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,52 @@ static void hist_entry__init_have_children(struct hist_entry *he)
391391
he->init_have_children = true;
392392
}
393393

394+
static bool hist_browser__selection_has_children(struct hist_browser *browser)
395+
{
396+
struct hist_entry *he = browser->he_selection;
397+
struct map_symbol *ms = browser->selection;
398+
399+
if (!he || !ms)
400+
return false;
401+
402+
if (ms == &he->ms)
403+
return he->has_children;
404+
405+
return container_of(ms, struct callchain_list, ms)->has_children;
406+
}
407+
408+
static bool hist_browser__selection_unfolded(struct hist_browser *browser)
409+
{
410+
struct hist_entry *he = browser->he_selection;
411+
struct map_symbol *ms = browser->selection;
412+
413+
if (!he || !ms)
414+
return false;
415+
416+
if (ms == &he->ms)
417+
return he->unfolded;
418+
419+
return container_of(ms, struct callchain_list, ms)->unfolded;
420+
}
421+
422+
static char *hist_browser__selection_sym_name(struct hist_browser *browser, char *bf, size_t size)
423+
{
424+
struct hist_entry *he = browser->he_selection;
425+
struct map_symbol *ms = browser->selection;
426+
struct callchain_list *callchain_entry;
427+
428+
if (!he || !ms)
429+
return NULL;
430+
431+
if (ms == &he->ms) {
432+
hist_entry__sym_snprintf(he, bf, size, 0);
433+
return bf + 4; // skip the level, e.g. '[k] '
434+
}
435+
436+
callchain_entry = container_of(ms, struct callchain_list, ms);
437+
return callchain_list__sym_name(callchain_entry, bf, size, browser->show_dso);
438+
}
439+
394440
static bool hist_browser__toggle_fold(struct hist_browser *browser)
395441
{
396442
struct hist_entry *he = browser->he_selection;
@@ -2535,12 +2581,14 @@ static int do_toggle_callchain(struct hist_browser *browser, struct popup_action
25352581

25362582
static int add_callchain_toggle_opt(struct hist_browser *browser, struct popup_action *act, char **optstr)
25372583
{
2538-
struct hist_entry *he = browser->he_selection;
2584+
char sym_name[512];
25392585

2540-
if (!he->has_children)
2586+
if (!hist_browser__selection_has_children(browser))
25412587
return 0;
25422588

2543-
if (asprintf(optstr, "Expand/Collapse callchain") < 0)
2589+
if (asprintf(optstr, "%s [%s] callchain (one level, same as '+' hotkey, use 'e'/'c' for the whole main level entry)",
2590+
hist_browser__selection_unfolded(browser) ? "Collapse" : "Expand",
2591+
hist_browser__selection_sym_name(browser, sym_name, sizeof(sym_name))) < 0)
25442592
return 0;
25452593

25462594
act->fn = do_toggle_callchain;

‎tools/perf/util/sort.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
324324
return ret;
325325
}
326326

327-
static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf,
328-
size_t size, unsigned int width)
327+
int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width)
329328
{
330329
return _hist_entry__sym_snprintf(&he->ms, he->ip,
331330
he->level, bf, size, width);

‎tools/perf/util/sort.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
164164
return he->callchain_size != 0;
165165
}
166166

167+
int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width);
168+
167169
static inline bool hist_entry__has_pairs(struct hist_entry *he)
168170
{
169171
return !list_empty(&he->pairs.node);

0 commit comments

Comments
 (0)