[PATCH 4/5] perf,tools: zoom in/out for processor socket

From: kan . liang
Date: Fri Sep 04 2015 - 18:02:14 EST


From: Kan Liang <kan.liang@xxxxxxxxx>

Currently, users can zoom in/out for threads and dso in perf top and
report. This patch extends it for socket.
'S' is the short key to zoom into current Processor Socket.

Signed-off-by: Kan Liang <kan.liang@xxxxxxxxx>
---
tools/perf/ui/browsers/hists.c | 43 +++++++++++++++++++++++++++++++++++++++++-
tools/perf/util/hist.c | 19 +++++++++++++++++++
tools/perf/util/hist.h | 1 +
3 files changed, 62 insertions(+), 1 deletion(-)

diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 457f24c..d695fd2 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -1429,6 +1429,7 @@ struct popup_action {
struct thread *thread;
struct dso *dso;
struct map_symbol ms;
+ int socket;

int (*fn)(struct hist_browser *browser, struct popup_action *act);
};
@@ -1676,6 +1677,37 @@ add_exit_opt(struct hist_browser *browser __maybe_unused,
return 1;
}

+static int
+do_zoom_socket(struct hist_browser *browser, struct popup_action *act)
+{
+ if (browser->hists->socket_filter > -1)
+ browser->hists->socket_filter = -1;
+ else
+ browser->hists->socket_filter = act->socket;
+
+ perf_hpp__set_elide(HISTC_SOCKET, false);
+ hists__filter_by_socket(browser->hists);
+ hist_browser__reset(browser);
+ return 0;
+}
+
+static int
+add_socket_opt(struct hist_browser *browser, struct popup_action *act,
+ char **optstr, int socket)
+{
+ if (socket < 0)
+ return 0;
+
+ if (asprintf(optstr, "Zoom %s Processor Socket %d",
+ (browser->hists->socket_filter > -1) ? "out of" : "into",
+ socket) < 0)
+ return 0;
+
+ act->socket = socket;
+ act->fn = do_zoom_socket;
+ return 1;
+}
+
static void hist_browser__update_nr_entries(struct hist_browser *hb)
{
u64 nr_entries = 0;
@@ -1729,6 +1761,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
"E Expand all callchains\n" \
"F Toggle percentage of filtered entries\n" \
"H Display column headers\n" \
+ "S Zoom into current Processor Socket\n" \

/* help messages are sorted by lexical order of the hotkey */
const char report_help[] = HIST_BROWSER_HELP_COMMON
@@ -1778,6 +1811,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
struct thread *thread = NULL;
struct dso *dso = NULL;
int choice = 0;
+ int socket = -1;

nr_options = 0;

@@ -1786,6 +1820,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
if (browser->he_selection != NULL) {
thread = hist_browser__selected_thread(browser);
dso = browser->selection->map ? browser->selection->map->dso : NULL;
+ socket = browser->he_selection->socket;
}
switch (key) {
case K_TAB:
@@ -1828,6 +1863,10 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
actions->thread = thread;
do_zoom_thread(browser, actions);
continue;
+ case 'S':
+ actions->socket = socket;
+ do_zoom_socket(browser, actions);
+ continue;
case '/':
if (ui_browser__input_window("Symbol to show",
"Please enter the name of symbol you want to see",
@@ -1973,7 +2012,9 @@ skip_annotation:
nr_options += add_map_opt(browser, &actions[nr_options],
&options[nr_options],
browser->selection->map);
-
+ nr_options += add_socket_opt(browser, &actions[nr_options],
+ &options[nr_options],
+ socket);
/* perf script support */
if (browser->he_selection) {
nr_options += add_script_opt(browser,
diff --git a/tools/perf/util/hist.c b/tools/perf/util/hist.c
index d7e53c2..bb633cd 100644
--- a/tools/perf/util/hist.c
+++ b/tools/perf/util/hist.c
@@ -1308,6 +1308,25 @@ static bool hists__filter_entry_by_socket(struct hists *hists,
return false;
}

+void hists__filter_by_socket(struct hists *hists)
+{
+ struct rb_node *nd;
+
+ hists->stats.nr_non_filtered_samples = 0;
+
+ hists__reset_filter_stats(hists);
+ hists__reset_col_len(hists);
+
+ for (nd = rb_first(&hists->entries); nd; nd = rb_next(nd)) {
+ struct hist_entry *h = rb_entry(nd, struct hist_entry, rb_node);
+
+ if (hists__filter_entry_by_socket(hists, h))
+ continue;
+
+ hists__remove_entry_filter(hists, h, HIST_FILTER__SOCKET);
+ }
+}
+
void events_stats__inc(struct events_stats *stats, u32 type)
{
++stats->nr_events[0];
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index ef682f2..4d6aa1d 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -147,6 +147,7 @@ size_t perf_evlist__fprintf_nr_events(struct perf_evlist *evlist, FILE *fp);
void hists__filter_by_dso(struct hists *hists);
void hists__filter_by_thread(struct hists *hists);
void hists__filter_by_symbol(struct hists *hists);
+void hists__filter_by_socket(struct hists *hists);

static inline bool hists__has_filter(struct hists *hists)
{
--
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/