]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
perf report/top: Improve toggle callchain menu option
authorArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 12 Dec 2019 14:48:23 +0000 (11:48 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Mon, 6 Jan 2020 14:46:10 +0000 (11:46 -0300)
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>
tools/perf/ui/browsers/hists.c
tools/perf/util/sort.c
tools/perf/util/sort.h

index 1b5a5990dddb4cbfb491e8b836f1d6309cd9e3de..a4413d983216cc64efbddbd82831703fbad40822 100644 (file)
@@ -391,6 +391,52 @@ static void hist_entry__init_have_children(struct hist_entry *he)
        he->init_have_children = true;
 }
 
+static bool hist_browser__selection_has_children(struct hist_browser *browser)
+{
+       struct hist_entry *he = browser->he_selection;
+       struct map_symbol *ms = browser->selection;
+
+       if (!he || !ms)
+               return false;
+
+       if (ms == &he->ms)
+              return he->has_children;
+
+       return container_of(ms, struct callchain_list, ms)->has_children;
+}
+
+static bool hist_browser__selection_unfolded(struct hist_browser *browser)
+{
+       struct hist_entry *he = browser->he_selection;
+       struct map_symbol *ms = browser->selection;
+
+       if (!he || !ms)
+               return false;
+
+       if (ms == &he->ms)
+              return he->unfolded;
+
+       return container_of(ms, struct callchain_list, ms)->unfolded;
+}
+
+static char *hist_browser__selection_sym_name(struct hist_browser *browser, char *bf, size_t size)
+{
+       struct hist_entry *he = browser->he_selection;
+       struct map_symbol *ms = browser->selection;
+       struct callchain_list *callchain_entry;
+
+       if (!he || !ms)
+               return NULL;
+
+       if (ms == &he->ms) {
+              hist_entry__sym_snprintf(he, bf, size, 0);
+              return bf + 4; // skip the level, e.g. '[k] '
+       }
+
+       callchain_entry = container_of(ms, struct callchain_list, ms);
+       return callchain_list__sym_name(callchain_entry, bf, size, browser->show_dso);
+}
+
 static bool hist_browser__toggle_fold(struct hist_browser *browser)
 {
        struct hist_entry *he = browser->he_selection;
@@ -2535,12 +2581,14 @@ static int do_toggle_callchain(struct hist_browser *browser, struct popup_action
 
 static int add_callchain_toggle_opt(struct hist_browser *browser, struct popup_action *act, char **optstr)
 {
-       struct hist_entry *he = browser->he_selection;
+       char sym_name[512];
 
-        if (!he->has_children)
+        if (!hist_browser__selection_has_children(browser))
                 return 0;
 
-       if (asprintf(optstr, "Expand/Collapse callchain") < 0)
+       if (asprintf(optstr, "%s [%s] callchain (one level, same as '+' hotkey, use 'e'/'c' for the whole main level entry)",
+                    hist_browser__selection_unfolded(browser) ? "Collapse" : "Expand",
+                    hist_browser__selection_sym_name(browser, sym_name, sizeof(sym_name))) < 0)
                return 0;
 
        act->fn = do_toggle_callchain;
index 9fcba2872130b117c1b400826beb169cc8175e7e..ab0cfd790ad00dddbf06a5e6b0baafe573614f9a 100644 (file)
@@ -324,8 +324,7 @@ static int _hist_entry__sym_snprintf(struct map_symbol *ms,
        return ret;
 }
 
-static int hist_entry__sym_snprintf(struct hist_entry *he, char *bf,
-                                   size_t size, unsigned int width)
+int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width)
 {
        return _hist_entry__sym_snprintf(&he->ms, he->ip,
                                         he->level, bf, size, width);
index 5aff9542d9b79fc1d95735b101fd30c03fc088ba..6c862d62d05258c5105ef795c3b2d6089d4ddecf 100644 (file)
@@ -164,6 +164,8 @@ static __pure inline bool hist_entry__has_callchains(struct hist_entry *he)
        return he->callchain_size != 0;
 }
 
+int hist_entry__sym_snprintf(struct hist_entry *he, char *bf, size_t size, unsigned int width);
+
 static inline bool hist_entry__has_pairs(struct hist_entry *he)
 {
        return !list_empty(&he->pairs.node);