Skip to contentSkip to conversation

perf,tools: add processor socket info in hist_entry and addr_location

PATCH In review [email protected] 4 participants 17 messages Sep 4, 2015 – Sep 15, 2015 perf events

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 perf,tools: add processor socket info in hist_entry and addr_location

From: Kan Liang <[email protected]>

Add processor socket id info in hist_entry and addr_location. For perf report, the socket id info is from perf.data. For others, the socket id info is from current system.

---
 tools/perf/builtin-report.c | 4 ++++
 tools/perf/util/event.c     | 1 +
 tools/perf/util/hist.c      | 1 +
 tools/perf/util/sort.h      | 1 +
 tools/perf/util/symbol.h    | 1 +
 5 files changed, 8 insertions(+)
tools/perf/builtin-report.c +4 -0
index 62b285e..affd70d 100644
@@ -149,6 +149,7 @@ static int process_sample_event(struct perf_tool *tool,
 		.add_entry_cb 		= hist_iter__report_callback,
 	};
 	int ret = 0;
+	struct perf_env *env = evsel->evlist->env;
 
 	if (perf_event__preprocess_sample(event, machine, &al, sample) < 0) {
 		pr_debug("problem processing %d event, skipping it.\n",
@@ -156,6 +157,9 @@ static int process_sample_event(struct perf_tool *tool,
 		return -1;
 	}
 
+	/* read socket id from perf.data for perf report */
+	al.socket = env->cpu[al.cpu].socket_id;
+
 	if (rep->hide_unresolved && al.sym == NULL)
 		goto out_put;
 
tools/perf/util/event.c +1 -0
index 7ff6127..0bf8c98 100644
@@ -1021,6 +1021,7 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	al->sym = NULL;
 	al->cpu = sample->cpu;
+	al->socket = cpu_map__get_socket_id(al->cpu);
 
 	if (al->map) {
 		struct dso *dso = al->map->dso;
tools/perf/util/hist.c +1 -0
index 08b6cd9..80c4683 100644
@@ -452,6 +452,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
 			.map	= al->map,
 			.sym	= al->sym,
 		},
+		.socket	 = al->socket,
 		.cpu	 = al->cpu,
 		.cpumode = al->cpumode,
 		.ip	 = al->addr,
tools/perf/util/sort.h +1 -0
index 3c2a399..7cf1cf7 100644
@@ -90,6 +90,7 @@ struct hist_entry {
 	struct comm		*comm;
 	u64			ip;
 	u64			transaction;
+	s32			socket;
 	s32			cpu;
 	u8			cpumode;
 
tools/perf/util/symbol.h +1 -0
index 440ba8a..40073c6 100644
@@ -191,6 +191,7 @@ struct addr_location {
 	u8	      filtered;
 	u8	      cpumode;
 	s32	      cpu;
+	s32	      socket;
 };
 
 struct symsrc {
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/5 perf,tools: Support new sort type --socket

From: Kan Liang <[email protected]>

This patch enable perf report to sort by processor socket

$ perf report --stdio --sort socket,comm,dso,symbol
 # To display the perf.data header info, please use
 --header/--header-only options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 686  of event 'cycles'
 # Event count (approx.): 349215462
 #
 # Overhead  SOCKET  Command    Shared Object     Symbol
 # ........  ......  .........  ................
 .................................
 #
    97.05%     000  test       test              [.] plusB_c
     0.98%     000  test       test              [.] plusA_c
     0.93%     001  perf       [kernel.vmlinux]  [k]
smp_call_function_single
     0.19%     001  perf       [kernel.vmlinux]  [k] page_fault
     0.19%     001  swapper    [kernel.vmlinux]  [k] pm_qos_request
     0.16%     000  test       [kernel.vmlinux]  [k] add_mm_counter_fast
---
 tools/perf/Documentation/perf-report.txt |  3 ++-
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/sort.c                   | 22 ++++++++++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 4 files changed, 26 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +2 -1
index 9c7981b..92361a7 100644
@@ -68,7 +68,7 @@ OPTIONS
 --sort=::
 	Sort histogram entries by given key(s) - multiple keys can be specified
 	in CSV format.  Following sort keys are available:
-	pid, comm, dso, symbol, parent, cpu, srcline, weight, local_weight.
+	pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, local_weight.
 
 	Each key has following meaning:
 
@@ -79,6 +79,7 @@ OPTIONS
 	- parent: name of function matched to the parent regex filter. Unmatched
 	entries are displayed as "[other]".
 	- cpu: cpu number the task ran at the time of sample
+	- socket: processor socket number the task ran at the time of sample
 	- srcline: filename and line number executed at the time of sample.  The
 	DWARF debugging info must be provided.
 	- srcfile: file name of the source file of the same. Requires dwarf
tools/perf/util/hist.h +1 -0
index de6d58e..5d04d28 100644
@@ -29,6 +29,7 @@ enum hist_column {
 	HISTC_COMM,
 	HISTC_PARENT,
 	HISTC_CPU,
+	HISTC_SOCKET,
 	HISTC_SRCLINE,
 	HISTC_SRCFILE,
 	HISTC_MISPREDICT,
tools/perf/util/sort.c +22 -0
index a97bcee..c4a32b9 100644
@@ -421,6 +421,27 @@ struct sort_entry sort_cpu = {
 	.se_width_idx	= HISTC_CPU,
 };
 
+/* --sort socket */
+
+static int64_t
+sort__socket_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return right->socket - left->socket;
+}
+
+static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
+				    size_t size, unsigned int width)
+{
+	return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket);
+}
+
+struct sort_entry sort_socket = {
+	.se_header      = "SOCKET",
+	.se_cmp	        = sort__socket_cmp,
+	.se_snprintf    = hist_entry__socket_snprintf,
+	.se_width_idx	= HISTC_SOCKET,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1248,6 +1269,7 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_SYM, "symbol", sort_sym),
 	DIM(SORT_PARENT, "parent", sort_parent),
 	DIM(SORT_CPU, "cpu", sort_cpu),
+	DIM(SORT_SOCKET, "socket", sort_socket),
 	DIM(SORT_SRCLINE, "srcline", sort_srcline),
 	DIM(SORT_SRCFILE, "srcfile", sort_srcfile),
 	DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
tools/perf/util/sort.h +1 -0
index 7cf1cf7..654ac8a 100644
@@ -173,6 +173,7 @@ enum sort_type {
 	SORT_SYM,
 	SORT_PARENT,
 	SORT_CPU,
+	SORT_SOCKET,
 	SORT_SRCLINE,
 	SORT_SRCFILE,
 	SORT_LOCAL_WEIGHT,
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 10:45:43AM -0400, [email protected] escreveu:

Quoted 4 lines

From: Kan Liang <[email protected]>

This patch enable perf report to sort by processor socket

Quoted 13 lines
$ perf report --stdio --sort socket,comm,dso,symbol
 # To display the perf.data header info, please use
 --header/--header-only options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 686  of event 'cycles'
 # Event count (approx.): 349215462
 #
 # Overhead  SOCKET  Command    Shared Object     Symbol
 # ........  ......  .........  ................
 .................................

So this works in 'perf top' only for the first screen rendering, when it refreshes we lose the "SOCKET" header (why all caps?) and the colum stops being %03d and instead becomes %d, I am checking now.

- Arnaldo

Quoted 104 lines

#

    97.05%     000  test       test              [.] plusB_c
     0.98%     000  test       test              [.] plusA_c
     0.93%     001  perf       [kernel.vmlinux]  [k]
smp_call_function_single
     0.19%     001  perf       [kernel.vmlinux]  [k] page_fault
     0.19%     001  swapper    [kernel.vmlinux]  [k] pm_qos_request
     0.16%     000  test       [kernel.vmlinux]  [k] add_mm_counter_fast
---
 tools/perf/Documentation/perf-report.txt |  3 ++-
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/sort.c                   | 22 ++++++++++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 4 files changed, 26 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +2 -1
index 9c7981b..92361a7 100644
@@ -68,7 +68,7 @@ OPTIONS
 --sort=::
 	Sort histogram entries by given key(s) - multiple keys can be specified
 	in CSV format.  Following sort keys are available:
-	pid, comm, dso, symbol, parent, cpu, srcline, weight, local_weight.
+	pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, local_weight.
 
 	Each key has following meaning:
 
@@ -79,6 +79,7 @@ OPTIONS
 	- parent: name of function matched to the parent regex filter. Unmatched
 	entries are displayed as "[other]".
 	- cpu: cpu number the task ran at the time of sample
+	- socket: processor socket number the task ran at the time of sample
 	- srcline: filename and line number executed at the time of sample.  The
 	DWARF debugging info must be provided.
 	- srcfile: file name of the source file of the same. Requires dwarf
tools/perf/util/hist.h +1 -0
index de6d58e..5d04d28 100644
@@ -29,6 +29,7 @@ enum hist_column {
 	HISTC_COMM,
 	HISTC_PARENT,
 	HISTC_CPU,
+	HISTC_SOCKET,
 	HISTC_SRCLINE,
 	HISTC_SRCFILE,
 	HISTC_MISPREDICT,
tools/perf/util/sort.c +22 -0
index a97bcee..c4a32b9 100644
@@ -421,6 +421,27 @@ struct sort_entry sort_cpu = {
 	.se_width_idx	= HISTC_CPU,
 };
 
+/* --sort socket */
+
+static int64_t
+sort__socket_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return right->socket - left->socket;
+}
+
+static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
+				    size_t size, unsigned int width)
+{
+	return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket);
+}
+
+struct sort_entry sort_socket = {
+	.se_header      = "SOCKET",
+	.se_cmp	        = sort__socket_cmp,
+	.se_snprintf    = hist_entry__socket_snprintf,
+	.se_width_idx	= HISTC_SOCKET,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1248,6 +1269,7 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_SYM, "symbol", sort_sym),
 	DIM(SORT_PARENT, "parent", sort_parent),
 	DIM(SORT_CPU, "cpu", sort_cpu),
+	DIM(SORT_SOCKET, "socket", sort_socket),
 	DIM(SORT_SRCLINE, "srcline", sort_srcline),
 	DIM(SORT_SRCFILE, "srcfile", sort_srcfile),
 	DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
tools/perf/util/sort.h +1 -0
index 7cf1cf7..654ac8a 100644
@@ -173,6 +173,7 @@ enum sort_type {
 	SORT_SYM,
 	SORT_PARENT,
 	SORT_CPU,
+	SORT_SOCKET,
 	SORT_SRCLINE,
 	SORT_SRCFILE,
 	SORT_LOCAL_WEIGHT,
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 07:41:39PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 19 lines

Em Fri, Sep 04, 2015 at 10:45:43AM -0400, [email protected] escreveu:

Quoted 4 lines

From: Kan Liang <[email protected]>

This patch enable perf report to sort by processor socket

Quoted 13 lines
$ perf report --stdio --sort socket,comm,dso,symbol
 # To display the perf.data header info, please use
 --header/--header-only options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 686  of event 'cycles'
 # Event count (approx.): 349215462
 #
 # Overhead  SOCKET  Command    Shared Object     Symbol
 # ........  ......  .........  ................
 .................................
Quoted 3 lines

So this works in 'perf top' only for the first screen rendering, when it refreshes we lose the "SOCKET" header (why all caps?) and the colum stops being %03d and instead becomes %d, I am checking now.

Patch below fix this, but we stumble in another problem, when zooming it is not eliding the SOCKET column, i.e. if we're zooming into a column, it will have the same value for all entries, no use in showing it, save some columns, will check that as well.

Will fold the fixes to the patches where the problems were introduced, the feature is cool, one more zoom! :-)

Thanks,

- Arnaldo

tools/perf/util/hist.c +1 -0
index bb633cd4730a..67b48616ab31 100644
@@ -146,6 +146,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 		hists__set_unres_dso_col_len(hists, HISTC_MEM_DADDR_DSO);
 	}
 
+	hists__new_col_len(hists, HISTC_SOCKET, 6);
 	hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
 	hists__new_col_len(hists, HISTC_MEM_TLB, 22);
 	hists__new_col_len(hists, HISTC_MEM_SNOOP, 12);
#4 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 07:52:55PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 24 lines

Em Fri, Sep 04, 2015 at 07:41:39PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 19 lines

Em Fri, Sep 04, 2015 at 10:45:43AM -0400, [email protected] escreveu:

Quoted 4 lines

From: Kan Liang <[email protected]>

This patch enable perf report to sort by processor socket

Quoted 13 lines
$ perf report --stdio --sort socket,comm,dso,symbol
 # To display the perf.data header info, please use
 --header/--header-only options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 686  of event 'cycles'
 # Event count (approx.): 349215462
 #
 # Overhead  SOCKET  Command    Shared Object     Symbol
 # ........  ......  .........  ................
 .................................
Quoted 3 lines

So this works in 'perf top' only for the first screen rendering, when it refreshes we lose the "SOCKET" header (why all caps?) and the colum stops being %03d and instead becomes %d, I am checking now.

Quoted 7 lines

Patch below fix this, but we stumble in another problem, when zooming it is not eliding the SOCKET column, i.e. if we're zooming into a column, it will have the same value for all entries, no use in showing it, save some columns, will check that as well.

Will fold the fixes to the patches where the problems were introduced, the feature is cool, one more zoom! :-)

One more fixed, see below, now we have another, using ESC should remove the last applied Zoom operation, just like for the other Zoom operations (DSO, thread, etc), looking at that now.

- Arnaldo

tools/perf/ui/browsers/hists.c +5 -3
index d695fd2b6228..67d40feb1880 100644
@@ -1680,12 +1680,14 @@ add_exit_opt(struct hist_browser *browser __maybe_unused,
 static int
 do_zoom_socket(struct hist_browser *browser, struct popup_action *act)
 {
-	if (browser->hists->socket_filter > -1)
+	if (browser->hists->socket_filter > -1) {
 		browser->hists->socket_filter = -1;
-	else
+		perf_hpp__set_elide(HISTC_SOCKET, false);
+	} else {
 		browser->hists->socket_filter = act->socket;
+		perf_hpp__set_elide(HISTC_SOCKET, true);
+	}
 
-	perf_hpp__set_elide(HISTC_SOCKET, false);
 	hists__filter_by_socket(browser->hists);
 	hist_browser__reset(browser);
 	return 0;
#5 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 08:06:21PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 30 lines

Em Fri, Sep 04, 2015 at 07:52:55PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 29 lines

Em Fri, Sep 04, 2015 at 07:41:39PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 19 lines

Em Fri, Sep 04, 2015 at 10:45:43AM -0400, [email protected] escreveu:

Quoted 4 lines

From: Kan Liang <[email protected]>

This patch enable perf report to sort by processor socket

Quoted 13 lines
$ perf report --stdio --sort socket,comm,dso,symbol
 # To display the perf.data header info, please use
 --header/--header-only options.
 #
 #
 # Total Lost Samples: 0
 #
 # Samples: 686  of event 'cycles'
 # Event count (approx.): 349215462
 #
 # Overhead  SOCKET  Command    Shared Object     Symbol
 # ........  ......  .........  ................
 .................................
Quoted 3 lines

So this works in 'perf top' only for the first screen rendering, when it refreshes we lose the "SOCKET" header (why all caps?) and the colum stops being %03d and instead becomes %d, I am checking now.

Patch below fix this, but we stumble in another problem, when zooming it is not eliding the SOCKET column, i.e. if we're zooming into a column, it will have the same value for all entries, no use in showing it, save some columns, will check that as well.

Quoted 6 lines
Quoted 2 lines

Will fold the fixes to the patches where the problems were introduced, the feature is cool, one more zoom! :-)

One more fixed, see below, now we have another, using ESC should remove the last applied Zoom operation, just like for the other Zoom operations (DSO, thread, etc), looking at that now.

Fixed, see below, to test, press S, then d to zoom into Socket then DSO and then press ESC to unzoom one level (the DSO in this case) then ESC again, to unzoom the Socket one.

If you use the left arrow key it will be equivalent to ESC, but we'll repurpose the left/right arrows for horizontal scrolling soon.

- Arnaldo

#6 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 08:25:47PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 11 lines
Quoted 3 lines

One more fixed, see below, now we have another, using ESC should remove the last applied Zoom operation, just like for the other Zoom operations (DSO, thread, etc), looking at that now.

Fixed, see below, to test, press S, then d to zoom into Socket then DSO and then press ESC to unzoom one level (the DSO in this case) then ESC again, to unzoom the Socket one.

If you use the left arrow key it will be equivalent to ESC, but we'll repurpose the left/right arrows for horizontal scrolling soon.

Ooops, here it is:

tools/perf/ui/browsers/hists.c +7 -3
index 67d40feb1880..e4fd40f72b4a 100644
@@ -1681,11 +1681,13 @@ static int
 do_zoom_socket(struct hist_browser *browser, struct popup_action *act)
 {
 	if (browser->hists->socket_filter > -1) {
+		pstack__remove(browser->pstack, &browser->hists->socket_filter);
 		browser->hists->socket_filter = -1;
 		perf_hpp__set_elide(HISTC_SOCKET, false);
 	} else {
 		browser->hists->socket_filter = act->socket;
 		perf_hpp__set_elide(HISTC_SOCKET, true);
+		pstack__push(browser->pstack, &browser->hists->socket_filter);
 	}
 
 	hists__filter_by_socket(browser->hists);
@@ -1794,7 +1796,7 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 		hist_browser__update_nr_entries(browser);
 	}
 
-	browser->pstack = pstack__new(2);
+	browser->pstack = pstack__new(3);
 	if (browser->pstack == NULL)
 		goto out;
 
@@ -1944,9 +1946,11 @@ static int perf_evsel__hists_browse(struct perf_evsel *evsel, int nr_events,
 				 * Ditto for thread below.
 				 */
 				do_zoom_dso(browser, actions);
-			}
-			if (top == &browser->hists->thread_filter)
+			} else if (top == &browser->hists->thread_filter) {
 				do_zoom_thread(browser, actions);
+			} else if (top == &browser->hists->socket_filter) {
+				do_zoom_socket(browser, actions);
+			}
 			continue;
 		}
 		case 'q':
#7 lore raw

Re: [PATCH 2/5] perf,tools: Support new sort type --socket

Em Fri, Sep 04, 2015 at 08:26:18PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 5 lines

Em Fri, Sep 04, 2015 at 08:25:47PM -0300, Arnaldo Carvalho de Melo escreveu:

Quoted 4 lines
Quoted 3 lines

One more fixed, see below, now we have another, using ESC should remove the last applied Zoom operation, just like for the other Zoom operations (DSO, thread, etc), looking at that now.

Quoted 8 lines
Quoted 7 lines

Fixed, see below, to test, press S, then d to zoom into Socket then DSO and then press ESC to unzoom one level (the DSO in this case) then ESC again, to unzoom the Socket one.

If you use the left arrow key it will be equivalent to ESC, but we'll repurpose the left/right arrows for horizontal scrolling soon.

Ooops, here it is:

Ok, I have all updated and pushed to my perf/core branch, please take a look/test.

- Arnaldo

#8 lore raw

[tip:perf/core] perf tools: Introduce new sort type "socket" for the processor socket

In reply to [email protected]
perf tools: Introduce new sort type "socket" for the processor socket
Commit-ID:  2e7ea3ab8282f6bb1d211d8af760a734c055f493
Gitweb:     http://git.kernel.org/tip/2e7ea3ab8282f6bb1d211d8af760a734c055f493
Author:     Kan Liang <[email protected]>
AuthorDate: Fri, 4 Sep 2015 10:45:43 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Sep 2015 12:50:30 -0300

perf tools: Introduce new sort type "socket" for the processor socket

This patch enable perf report to sort by processor socket:

  $ perf report --stdio --sort socket,comm,dso,symbol
  # To display the perf.data header info, please use --header/--header-only options.
  #
  # Total Lost Samples: 0
  #
  # Samples: 686  of event 'cycles'
  # Event count (approx.): 349215462
  #
  # Overhead SOCKET Command Shared Object    Symbol
  # ........ ...... ....... ................ ............................
  #
    97.05%    000   test    test             [.] plusB_c
     0.98%    000   test    test             [.] plusA_c
     0.93%    001   perf    [kernel.vmlinux] [k] smp_call_function_single
     0.19%    001   perf    [kernel.vmlinux] [k] page_fault
     0.19%    001   swapper [kernel.vmlinux] [k] pm_qos_request
     0.16%    000   test    [kernel.vmlinux] [k] add_mm_counter_fast
Cc Adrian Hunter <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
[ Fix col calc, un-allcapsify col header & read the topology when not using perf.data ]
---
 tools/perf/Documentation/perf-report.txt |  3 ++-
 tools/perf/builtin-top.c                 | 15 +++++++++++++++
 tools/perf/util/hist.c                   |  1 +
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/sort.c                   | 25 +++++++++++++++++++++++++
 tools/perf/util/sort.h                   |  2 ++
 6 files changed, 46 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +2 -1
index 9c7981b..92361a7 100644
@@ -68,7 +68,7 @@ OPTIONS
 --sort=::
 	Sort histogram entries by given key(s) - multiple keys can be specified
 	in CSV format.  Following sort keys are available:
-	pid, comm, dso, symbol, parent, cpu, srcline, weight, local_weight.
+	pid, comm, dso, symbol, parent, cpu, socket, srcline, weight, local_weight.
 
 	Each key has following meaning:
 
@@ -79,6 +79,7 @@ OPTIONS
 	- parent: name of function matched to the parent regex filter. Unmatched
 	entries are displayed as "[other]".
 	- cpu: cpu number the task ran at the time of sample
+	- socket: processor socket number the task ran at the time of sample
 	- srcline: filename and line number executed at the time of sample.  The
 	DWARF debugging info must be provided.
 	- srcfile: file name of the source file of the same. Requires dwarf
tools/perf/builtin-top.c +15 -0
index e5ca684..bdaf44f 100644
@@ -963,6 +963,13 @@ static int __cmd_top(struct perf_top *top)
 
 	machine__synthesize_threads(&top->session->machines.host, &opts->target,
 				    top->evlist->threads, false, opts->proc_map_timeout);
+
+	if (sort__has_socket) {
+		ret = perf_env__read_cpu_topology_map(&perf_env);
+		if (ret < 0)
+			goto out_err_cpu_topo;
+	}
+
 	ret = perf_top__start_counters(top);
 	if (ret)
 		goto out_delete;
@@ -1020,6 +1027,14 @@ out_delete:
 	top->session = NULL;
 
 	return ret;
+
+out_err_cpu_topo: {
+	char errbuf[BUFSIZ];
+	const char *err = strerror_r(-ret, errbuf, sizeof(errbuf));
+
+	ui__error("Could not read the CPU topology map: %s\n", err);
+	goto out_delete;
+}
 }
 
 static int
tools/perf/util/hist.c +1 -0
index d2b94c4..ba72a29 100644
@@ -145,6 +145,7 @@ void hists__calc_col_len(struct hists *hists, struct hist_entry *h)
 	}
 
 	hists__new_col_len(hists, HISTC_CPU, 3);
+	hists__new_col_len(hists, HISTC_SOCKET, 6);
 	hists__new_col_len(hists, HISTC_MEM_LOCKED, 6);
 	hists__new_col_len(hists, HISTC_MEM_TLB, 22);
 	hists__new_col_len(hists, HISTC_MEM_SNOOP, 12);
tools/perf/util/hist.h +1 -0
index de6d58e..5d04d28 100644
@@ -29,6 +29,7 @@ enum hist_column {
 	HISTC_COMM,
 	HISTC_PARENT,
 	HISTC_CPU,
+	HISTC_SOCKET,
 	HISTC_SRCLINE,
 	HISTC_SRCFILE,
 	HISTC_MISPREDICT,
tools/perf/util/sort.c +25 -0
index a97bcee..6b9556d 100644
@@ -21,6 +21,7 @@ int		sort__need_collapse = 0;
 int		sort__has_parent = 0;
 int		sort__has_sym = 0;
 int		sort__has_dso = 0;
+int		sort__has_socket = 0;
 enum sort_mode	sort__mode = SORT_MODE__NORMAL;
 
 
@@ -421,6 +422,27 @@ struct sort_entry sort_cpu = {
 	.se_width_idx	= HISTC_CPU,
 };
 
+/* --sort socket */
+
+static int64_t
+sort__socket_cmp(struct hist_entry *left, struct hist_entry *right)
+{
+	return right->socket - left->socket;
+}
+
+static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
+				    size_t size, unsigned int width)
+{
+	return repsep_snprintf(bf, size, "%*.*d", width, width-3, he->socket);
+}
+
+struct sort_entry sort_socket = {
+	.se_header      = "Socket",
+	.se_cmp	        = sort__socket_cmp,
+	.se_snprintf    = hist_entry__socket_snprintf,
+	.se_width_idx	= HISTC_SOCKET,
+};
+
 /* sort keys for branch stacks */
 
 static int64_t
@@ -1248,6 +1270,7 @@ static struct sort_dimension common_sort_dimensions[] = {
 	DIM(SORT_SYM, "symbol", sort_sym),
 	DIM(SORT_PARENT, "parent", sort_parent),
 	DIM(SORT_CPU, "cpu", sort_cpu),
+	DIM(SORT_SOCKET, "socket", sort_socket),
 	DIM(SORT_SRCLINE, "srcline", sort_srcline),
 	DIM(SORT_SRCFILE, "srcfile", sort_srcfile),
 	DIM(SORT_LOCAL_WEIGHT, "local_weight", sort_local_weight),
@@ -1550,6 +1573,8 @@ int sort_dimension__add(const char *tok)
 
 		} else if (sd->entry == &sort_dso) {
 			sort__has_dso = 1;
+		} else if (sd->entry == &sort_socket) {
+			sort__has_socket = 1;
 		}
 
 		return __sort_dimension__add(sd);
tools/perf/util/sort.h +2 -0
index 7cf1cf7..c06b757 100644
@@ -34,6 +34,7 @@ extern int have_ignore_callees;
 extern int sort__need_collapse;
 extern int sort__has_parent;
 extern int sort__has_sym;
+extern int sort__has_socket;
 extern enum sort_mode sort__mode;
 extern struct sort_entry sort_comm;
 extern struct sort_entry sort_dso;
@@ -173,6 +174,7 @@ enum sort_type {
 	SORT_SYM,
 	SORT_PARENT,
 	SORT_CPU,
+	SORT_SOCKET,
 	SORT_SRCLINE,
 	SORT_SRCFILE,
 	SORT_LOCAL_WEIGHT,
#9 lore raw

PATCH 3/5 perf,report: introduce socket-filter option

In reply to [email protected]

From: Kan Liang <[email protected]>

Introduce --socket-filter option for perf report to only show processor socket that match with this filter.

perf report --socket-filter 1 --stdio
# To display the perf.data header info, please use --header/--header-only options.
#
#
# Total Lost Samples: 0
#
# Samples: 752 of event 'cycles'
# Event count (approx.): 350995599
# Processor Socket: 1
#

 # Overhead  Command    Shared Object     Symbol
 # ........  .........  ................
 .................................
 #
    97.02%  test       test              [.] plusB_c
     0.97%  test       test              [.] plusA_c
     0.23%  swapper    [kernel.vmlinux]  [k] acpi_idle_do_entry
     0.09%  rcu_sched  [kernel.vmlinux]  [k]
dyntick_save_progress_counter
     0.01%  swapper    [kernel.vmlinux]  [k] task_waking_fair
     0.00%  swapper    [kernel.vmlinux]  [k] run_timer_softirq
---
 tools/perf/Documentation/perf-report.txt |  3 +++
 tools/perf/builtin-report.c              | 11 +++++++++++
 tools/perf/ui/browsers/hists.c           |  4 ++++
 tools/perf/util/hist.c                   | 16 ++++++++++++++++
 tools/perf/util/hist.h                   |  4 +++-
 5 files changed, 37 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +3 -0
index 92361a7..b941d5e 100644
@@ -350,6 +350,9 @@ include::itrace.txt[]
 	This option extends the perf report to show reference callgraphs,
 	which collected by reference event, in no callgraph event.
 
+--socket-filter::
+	Only report the samples on the processor socket that match with this filter
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
tools/perf/builtin-report.c +11 -0
index affd70d..4b43245 100644
@@ -62,6 +62,7 @@ struct report {
 	float			min_percent;
 	u64			nr_entries;
 	u64			queue_size;
+	int			socket_filter;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 };
 
@@ -290,6 +291,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	struct perf_evsel *evsel = hists_to_evsel(hists);
 	char buf[512];
 	size_t size = sizeof(buf);
+	int socket = hists->socket_filter;
 
 	if (symbol_conf.filter_relative) {
 		nr_samples = hists->stats.nr_non_filtered_samples;
@@ -330,6 +332,10 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 		ret += fprintf(fp, "\n# Sort order   : %s", sort_order ? : default_mem_sort_order);
 	} else
 		ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
+
+	if (socket > -1)
+		ret += fprintf(fp, "\n# Processor Socket: %d", socket);
+
 	return ret + fprintf(fp, "\n#\n");
 }
 
@@ -454,6 +460,8 @@ static void report__collapse_hists(struct report *rep)
 		if (pos->idx == 0)
 			hists->symbol_filter_str = rep->symbol_filter_str;
 
+		hists->socket_filter = rep->socket_filter;
+
 		hists__collapse_resort(hists, &prog);
 
 		/* Non-group events are considered as leader */
@@ -639,6 +647,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		},
 		.max_stack		 = PERF_MAX_STACK_DEPTH,
 		.pretty_printing_style	 = "normal",
+		.socket_filter		 = -1,
 	};
 	const struct option options[] = {
 	OPT_STRING('i', "input", &input_name, "file",
@@ -751,6 +760,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 			"Show full source file name path for source lines"),
 	OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
 		    "Show callgraph from reference event"),
+	OPT_INTEGER(0, "socket-filter", &report.socket_filter,
+		    "only show processor socket that match with this filter"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
tools/perf/ui/browsers/hists.c +4 -0
index cf86f2d..457f24c 100644
@@ -1261,6 +1261,7 @@ static int hists__browser_title(struct hists *hists,
 	int printed;
 	const struct dso *dso = hists->dso_filter;
 	const struct thread *thread = hists->thread_filter;
+	int socket = hists->socket_filter;
 	unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
 	u64 nr_events = hists->stats.total_period;
 	struct perf_evsel *evsel = hists_to_evsel(hists);
@@ -1314,6 +1315,9 @@ static int hists__browser_title(struct hists *hists,
 	if (dso)
 		printed += scnprintf(bf + printed, size - printed,
 				    ", DSO: %s", dso->short_name);
+	if (socket > -1)
+		printed += scnprintf(bf + printed, size - printed,
+				    ", Processor Socket: %d", socket);
 	if (!is_report_browser(hbt)) {
 		struct perf_top *top = hbt->arg;
 
tools/perf/util/hist.c +16 -0
index 80c4683..d7e53c2 100644
@@ -15,6 +15,8 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 					  struct hist_entry *he);
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he);
+static bool hists__filter_entry_by_socket(struct hists *hists,
+					  struct hist_entry *he);
 
 u16 hists__col_len(struct hists *hists, enum hist_column col)
 {
@@ -1025,6 +1027,7 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
 	hists__filter_entry_by_dso(hists, he);
 	hists__filter_entry_by_thread(hists, he);
 	hists__filter_entry_by_symbol(hists, he);
+	hists__filter_entry_by_socket(hists, he);
 }
 
 void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
@@ -1293,6 +1296,18 @@ void hists__filter_by_symbol(struct hists *hists)
 	}
 }
 
+static bool hists__filter_entry_by_socket(struct hists *hists,
+					  struct hist_entry *he)
+{
+	if ((hists->socket_filter > -1) &&
+	    (he->socket != hists->socket_filter)) {
+		he->filtered |= (1 << HIST_FILTER__SOCKET);
+		return true;
+	}
+
+	return false;
+}
+
 void events_stats__inc(struct events_stats *stats, u32 type)
 {
 	++stats->nr_events[0];
@@ -1518,6 +1533,7 @@ static int hists_evsel__init(struct perf_evsel *evsel)
 	hists->entries_collapsed = RB_ROOT;
 	hists->entries = RB_ROOT;
 	pthread_mutex_init(&hists->lock, NULL);
+	hists->socket_filter = -1;
 	return 0;
 }
 
tools/perf/util/hist.h +3 -1
index 5d04d28..ef682f2 100644
@@ -20,6 +20,7 @@ enum hist_filter {
 	HIST_FILTER__SYMBOL,
 	HIST_FILTER__GUEST,
 	HIST_FILTER__HOST,
+	HIST_FILTER__SOCKET,
 };
 
 enum hist_column {
@@ -71,6 +72,7 @@ struct hists {
 	struct events_stats	stats;
 	u64			event_stream;
 	u16			col_len[HISTC_NR_COLS];
+	int			socket_filter;
 };
 
 struct hist_entry_iter;
@@ -149,7 +151,7 @@ void hists__filter_by_symbol(struct hists *hists);
 static inline bool hists__has_filter(struct hists *hists)
 {
 	return hists->thread_filter || hists->dso_filter ||
-		hists->symbol_filter_str;
+		hists->symbol_filter_str || (hists->socket_filter > -1);
 }
 
 u16 hists__col_len(struct hists *hists, enum hist_column col);
Signature · 1 line
1.8.3.1
#10 lore raw

[tip:perf/core] perf report: Introduce --socket-filter option

perf report: Introduce --socket-filter option
Commit-ID:  21394d948a0c7c451d4a4d68afed9a06c4969636
Gitweb:     http://git.kernel.org/tip/21394d948a0c7c451d4a4d68afed9a06c4969636
Author:     Kan Liang <[email protected]>
AuthorDate: Fri, 4 Sep 2015 10:45:44 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Sep 2015 12:50:31 -0300

perf report: Introduce --socket-filter option

Introduce --socket-filter option for 'perf report' to only show entries for a processor socket that match this filter.

  $ perf report --socket-filter 1 --stdio
  # To display the perf.data header info, please use --header/--header-only options.
  #
  # Total Lost Samples: 0
  #
  # Samples: 752  of event 'cycles'
  # Event count (approx.): 350995599
  # Processor Socket: 1
  #
  # Overhead  Command    Shared Object     Symbol
  # ........  .........  ................  .................................
  #
      97.02%  test       test              [.] plusB_c
       0.97%  test       test              [.] plusA_c
       0.23%  swapper    [kernel.vmlinux]  [k] acpi_idle_do_entry
       0.09%  rcu_sched  [kernel.vmlinux]  [k] dyntick_save_progress_counter
       0.01%  swapper    [kernel.vmlinux]  [k] task_waking_fair
       0.00%  swapper    [kernel.vmlinux]  [k] run_timer_softirq
---
 tools/perf/Documentation/perf-report.txt |  3 +++
 tools/perf/builtin-report.c              | 11 +++++++++++
 tools/perf/ui/browsers/hists.c           |  4 ++++
 tools/perf/util/hist.c                   | 16 ++++++++++++++++
 tools/perf/util/hist.h                   |  4 +++-
 5 files changed, 37 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-report.txt +3 -0
index 92361a7..b941d5e 100644
@@ -350,6 +350,9 @@ include::itrace.txt[]
 	This option extends the perf report to show reference callgraphs,
 	which collected by reference event, in no callgraph event.
 
+--socket-filter::
+	Only report the samples on the processor socket that match with this filter
+
 include::callchain-overhead-calculation.txt[]
 
 SEE ALSO
tools/perf/builtin-report.c +11 -0
index 62b285e..9b50836 100644
@@ -62,6 +62,7 @@ struct report {
 	float			min_percent;
 	u64			nr_entries;
 	u64			queue_size;
+	int			socket_filter;
 	DECLARE_BITMAP(cpu_bitmap, MAX_NR_CPUS);
 };
 
@@ -286,6 +287,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	struct perf_evsel *evsel = hists_to_evsel(hists);
 	char buf[512];
 	size_t size = sizeof(buf);
+	int socket = hists->socket_filter;
 
 	if (symbol_conf.filter_relative) {
 		nr_samples = hists->stats.nr_non_filtered_samples;
@@ -326,6 +328,10 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 		ret += fprintf(fp, "\n# Sort order   : %s", sort_order ? : default_mem_sort_order);
 	} else
 		ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
+
+	if (socket > -1)
+		ret += fprintf(fp, "\n# Processor Socket: %d", socket);
+
 	return ret + fprintf(fp, "\n#\n");
 }
 
@@ -450,6 +456,8 @@ static void report__collapse_hists(struct report *rep)
 		if (pos->idx == 0)
 			hists->symbol_filter_str = rep->symbol_filter_str;
 
+		hists->socket_filter = rep->socket_filter;
+
 		hists__collapse_resort(hists, &prog);
 
 		/* Non-group events are considered as leader */
@@ -635,6 +643,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 		},
 		.max_stack		 = PERF_MAX_STACK_DEPTH,
 		.pretty_printing_style	 = "normal",
+		.socket_filter		 = -1,
 	};
 	const struct option options[] = {
 	OPT_STRING('i', "input", &input_name, "file",
@@ -747,6 +756,8 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 			"Show full source file name path for source lines"),
 	OPT_BOOLEAN(0, "show-ref-call-graph", &symbol_conf.show_ref_callgraph,
 		    "Show callgraph from reference event"),
+	OPT_INTEGER(0, "socket-filter", &report.socket_filter,
+		    "only show processor socket that match with this filter"),
 	OPT_END()
 	};
 	struct perf_data_file file = {
tools/perf/ui/browsers/hists.c +4 -0
index 17d6c6d..792dcf5 100644
@@ -1261,6 +1261,7 @@ static int hists__browser_title(struct hists *hists,
 	int printed;
 	const struct dso *dso = hists->dso_filter;
 	const struct thread *thread = hists->thread_filter;
+	int socket = hists->socket_filter;
 	unsigned long nr_samples = hists->stats.nr_events[PERF_RECORD_SAMPLE];
 	u64 nr_events = hists->stats.total_period;
 	struct perf_evsel *evsel = hists_to_evsel(hists);
@@ -1314,6 +1315,9 @@ static int hists__browser_title(struct hists *hists,
 	if (dso)
 		printed += scnprintf(bf + printed, size - printed,
 				    ", DSO: %s", dso->short_name);
+	if (socket > -1)
+		printed += scnprintf(bf + printed, size - printed,
+				    ", Processor Socket: %d", socket);
 	if (!is_report_browser(hbt)) {
 		struct perf_top *top = hbt->arg;
 
tools/perf/util/hist.c +16 -0
index ba72a29..5d78ae8 100644
@@ -15,6 +15,8 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 					  struct hist_entry *he);
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he);
+static bool hists__filter_entry_by_socket(struct hists *hists,
+					  struct hist_entry *he);
 
 u16 hists__col_len(struct hists *hists, enum hist_column col)
 {
@@ -1027,6 +1029,7 @@ static void hists__apply_filters(struct hists *hists, struct hist_entry *he)
 	hists__filter_entry_by_dso(hists, he);
 	hists__filter_entry_by_thread(hists, he);
 	hists__filter_entry_by_symbol(hists, he);
+	hists__filter_entry_by_socket(hists, he);
 }
 
 void hists__collapse_resort(struct hists *hists, struct ui_progress *prog)
@@ -1295,6 +1298,18 @@ void hists__filter_by_symbol(struct hists *hists)
 	}
 }
 
+static bool hists__filter_entry_by_socket(struct hists *hists,
+					  struct hist_entry *he)
+{
+	if ((hists->socket_filter > -1) &&
+	    (he->socket != hists->socket_filter)) {
+		he->filtered |= (1 << HIST_FILTER__SOCKET);
+		return true;
+	}
+
+	return false;
+}
+
 void events_stats__inc(struct events_stats *stats, u32 type)
 {
 	++stats->nr_events[0];
@@ -1520,6 +1535,7 @@ static int hists_evsel__init(struct perf_evsel *evsel)
 	hists->entries_collapsed = RB_ROOT;
 	hists->entries = RB_ROOT;
 	pthread_mutex_init(&hists->lock, NULL);
+	hists->socket_filter = -1;
 	return 0;
 }
 
tools/perf/util/hist.h +3 -1
index 5d04d28..ef682f2 100644
@@ -20,6 +20,7 @@ enum hist_filter {
 	HIST_FILTER__SYMBOL,
 	HIST_FILTER__GUEST,
 	HIST_FILTER__HOST,
+	HIST_FILTER__SOCKET,
 };
 
 enum hist_column {
@@ -71,6 +72,7 @@ struct hists {
 	struct events_stats	stats;
 	u64			event_stream;
 	u16			col_len[HISTC_NR_COLS];
+	int			socket_filter;
 };
 
 struct hist_entry_iter;
@@ -149,7 +151,7 @@ void hists__filter_by_symbol(struct hists *hists);
 static inline bool hists__has_filter(struct hists *hists)
 {
 	return hists->thread_filter || hists->dso_filter ||
-		hists->symbol_filter_str;
+		hists->symbol_filter_str || (hists->socket_filter > -1);
 }
 
 u16 hists__col_len(struct hists *hists, enum hist_column col);
#11 lore raw

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

In reply to [email protected]

From: Kan Liang <[email protected]>

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.

---
 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(-)
tools/perf/ui/browsers/hists.c +42 -1
index 457f24c..d695fd2 100644
@@ -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,
tools/perf/util/hist.c +19 -0
index d7e53c2..bb633cd 100644
@@ -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];
tools/perf/util/hist.h +1 -0
index ef682f2..4d6aa1d 100644
@@ -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)
 {
Signature · 1 line
1.8.3.1
#12 lore raw

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

Quoted 5 lines · On Fri, Sep 04, 2015 at 10:45:45AM -0400, [email protected] wrote:

From: Kan Liang <[email protected]>

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.

Nice feature.

Would be nice to also able to zoom into the current logical CPU.

-Andi

Signature · 1 line
[email protected] -- Speaking for myself only
#13 lore raw

[tip:perf/core] perf hists browser: Zoom in/ out for processor socket

In reply to [email protected]
perf hists browser: Zoom in/out for processor socket
Commit-ID:  84734b06b63093cd44533f4caa43d4452fb11ec3
Gitweb:     http://git.kernel.org/tip/84734b06b63093cd44533f4caa43d4452fb11ec3
Author:     Kan Liang <[email protected]>
AuthorDate: Fri, 4 Sep 2015 10:45:45 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Sep 2015 13:02:08 -0300

perf hists browser: Zoom in/out for processor socket

Currently, users can zoom in/out for threads and dso in 'perf top' and 'perf report'.

This patch extends it for the processor sockets.

'S' is the short key to zoom into current Processor Socket.

[ - Made it elide the Socket column when zooming into it,

    just like with the other zoom ops;

- Make it use browser->pstack, to unzoom level by level;
- Rename 'socket' variables to 'socket_id' to make it build on older systems where it shadows a global glibc declaration ]

---
 tools/perf/builtin-report.c    |  6 ++---
 tools/perf/ui/browsers/hists.c | 61 +++++++++++++++++++++++++++++++++++++-----
 tools/perf/util/hist.c         | 19 +++++++++++++
 tools/perf/util/hist.h         |  1 +
 4 files changed, 77 insertions(+), 10 deletions(-)
tools/perf/builtin-report.c +3 -3
index 9b50836..e4e3f14 100644
@@ -287,7 +287,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	struct perf_evsel *evsel = hists_to_evsel(hists);
 	char buf[512];
 	size_t size = sizeof(buf);
-	int socket = hists->socket_filter;
+	int socked_id = hists->socket_filter;
 
 	if (symbol_conf.filter_relative) {
 		nr_samples = hists->stats.nr_non_filtered_samples;
@@ -329,8 +329,8 @@ static size_t hists__fprintf_nr_sample_events(struct hists *hists, struct report
 	} else
 		ret += fprintf(fp, "\n# Event count (approx.): %" PRIu64, nr_events);
 
-	if (socket > -1)
-		ret += fprintf(fp, "\n# Processor Socket: %d", socket);
+	if (socked_id > -1)
+		ret += fprintf(fp, "\n# Processor Socket: %d", socked_id);
 
 	return ret + fprintf(fp, "\n#\n");
 }
tools/perf/ui/browsers/hists.c +54 -7

129 lines not on this page · raw message

tools/perf/util/hist.c +19 -0
index 5d78ae8..b3567a2 100644
@@ -1310,6 +1310,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];
tools/perf/util/hist.h +1 -0
index ef682f2..4d6aa1d 100644
@@ -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)
 {
#14 lore raw

PATCH 5/5 perf,test: test hists socket filter

In reply to [email protected]

From: Kan Liang <[email protected]>

Add test case for hists socket filter.

---
 tools/perf/tests/hists_filter.c | 55 +++++++++++++++++++++++++++++++++--------
 1 file changed, 45 insertions(+), 10 deletions(-)
tools/perf/tests/hists_filter.c +45 -10
index ce48775..818acf8 100644
@@ -16,30 +16,31 @@ struct sample {
 	struct thread *thread;
 	struct map *map;
 	struct symbol *sym;
+	int socket;
 };
 
 /* For the numbers, see hists_common.c */
 static struct sample fake_samples[] = {
 	/* perf [kernel] schedule() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, .socket = 0 },
 	/* perf [perf]   main() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, .socket = 0 },
 	/* perf [libc]   malloc() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, .socket = 0 },
 	/* perf [perf]   main() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, /* will be merged */
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, .socket = 0 }, /* will be merged */
 	/* perf [perf]   cmd_record() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, },
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, .socket = 1 },
 	/* perf [kernel] page_fault() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 1 },
 	/* bash [bash]   main() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, .socket = 2 },
 	/* bash [bash]   xmalloc() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, .socket = 2 },
 	/* bash [libc]   malloc() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, .socket = 3 },
 	/* bash [kernel] page_fault() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 3 },
 };
 
 static int add_hist_entries(struct perf_evlist *evlist,
@@ -83,6 +84,7 @@ static int add_hist_entries(struct perf_evlist *evlist,
 							  &sample) < 0)
 				goto out;
 
+			al.socket = fake_samples[i].socket;
 			if (hist_entry_iter__add(&iter, &al,
 						 PERF_MAX_STACK_DEPTH, NULL) < 0) {
 				addr_location__put(&al);
@@ -253,6 +255,39 @@ int test__hists_filter(void)
 		TEST_ASSERT_VAL("Unmatched total period for symbol filter",
 				hists->stats.total_non_filtered_period == 300);
 
+		/* remove symbol filter first */
+		hists->symbol_filter_str = NULL;
+		hists__filter_by_symbol(hists);
+
+		/* now applying socket filters */
+		hists->socket_filter = 2;
+		hists__filter_by_socket(hists);
+
+		if (verbose > 2) {
+			pr_info("Histogram for socket filters\n");
+			print_hists_out(hists);
+		}
+
+		/* normal stats should be invariant */
+		TEST_ASSERT_VAL("Invalid nr samples",
+				hists->stats.nr_events[PERF_RECORD_SAMPLE] == 10);
+		TEST_ASSERT_VAL("Invalid nr hist entries",
+				hists->nr_entries == 9);
+		TEST_ASSERT_VAL("Invalid total period",
+				hists->stats.total_period == 1000);
+
+		/* but filter stats are changed */
+		TEST_ASSERT_VAL("Unmatched nr samples for socket filter",
+				hists->stats.nr_non_filtered_samples == 2);
+		TEST_ASSERT_VAL("Unmatched nr hist entries for socket filter",
+				hists->nr_non_filtered_entries == 2);
+		TEST_ASSERT_VAL("Unmatched total period for socket filter",
+				hists->stats.total_non_filtered_period == 200);
+
+		/* remove socket filter first */
+		hists->socket_filter = -1;
+		hists__filter_by_socket(hists);
+
 		/* now applying all filters at once. */
 		hists->thread_filter = fake_samples[1].thread;
 		hists->dso_filter = fake_samples[1].map->dso;
Signature · 1 line
1.8.3.1
#15 lore raw

[tip:perf/core] perf test: Add entry for hists socket filter

perf test: Add entry for hists socket filter
Commit-ID:  92d424ae898e0d04ac34263aa33e40acc1e1f3d1
Gitweb:     http://git.kernel.org/tip/92d424ae898e0d04ac34263aa33e40acc1e1f3d1
Author:     Kan Liang <[email protected]>
AuthorDate: Fri, 4 Sep 2015 10:45:46 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Sep 2015 13:04:10 -0300

perf test: Add entry for hists socket filter

Add test case for hists socket filter.

---
 tools/perf/tests/hists_filter.c | 55 +++++++++++++++++++++++++++++++++--------
 1 file changed, 45 insertions(+), 10 deletions(-)
tools/perf/tests/hists_filter.c +45 -10
index ce48775..818acf8 100644
@@ -16,30 +16,31 @@ struct sample {
 	struct thread *thread;
 	struct map *map;
 	struct symbol *sym;
+	int socket;
 };
 
 /* For the numbers, see hists_common.c */
 static struct sample fake_samples[] = {
 	/* perf [kernel] schedule() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_KERNEL_SCHEDULE, .socket = 0 },
 	/* perf [perf]   main() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_PERF_MAIN, .socket = 0 },
 	/* perf [libc]   malloc() */
-	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, },
+	{ .pid = FAKE_PID_PERF1, .ip = FAKE_IP_LIBC_MALLOC, .socket = 0 },
 	/* perf [perf]   main() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, }, /* will be merged */
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_MAIN, .socket = 0 }, /* will be merged */
 	/* perf [perf]   cmd_record() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, },
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_PERF_CMD_RECORD, .socket = 1 },
 	/* perf [kernel] page_fault() */
-	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
+	{ .pid = FAKE_PID_PERF2, .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 1 },
 	/* bash [bash]   main() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_MAIN, .socket = 2 },
 	/* bash [bash]   xmalloc() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_BASH_XMALLOC, .socket = 2 },
 	/* bash [libc]   malloc() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_LIBC_MALLOC, .socket = 3 },
 	/* bash [kernel] page_fault() */
-	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, },
+	{ .pid = FAKE_PID_BASH,  .ip = FAKE_IP_KERNEL_PAGE_FAULT, .socket = 3 },
 };
 
 static int add_hist_entries(struct perf_evlist *evlist,
@@ -83,6 +84,7 @@ static int add_hist_entries(struct perf_evlist *evlist,
 							  &sample) < 0)
 				goto out;
 
+			al.socket = fake_samples[i].socket;
 			if (hist_entry_iter__add(&iter, &al,
 						 PERF_MAX_STACK_DEPTH, NULL) < 0) {
 				addr_location__put(&al);
@@ -253,6 +255,39 @@ int test__hists_filter(void)
 		TEST_ASSERT_VAL("Unmatched total period for symbol filter",
 				hists->stats.total_non_filtered_period == 300);
 
+		/* remove symbol filter first */
+		hists->symbol_filter_str = NULL;
+		hists__filter_by_symbol(hists);
+
+		/* now applying socket filters */
+		hists->socket_filter = 2;
+		hists__filter_by_socket(hists);
+
+		if (verbose > 2) {
+			pr_info("Histogram for socket filters\n");
+			print_hists_out(hists);
+		}
+
+		/* normal stats should be invariant */
+		TEST_ASSERT_VAL("Invalid nr samples",
+				hists->stats.nr_events[PERF_RECORD_SAMPLE] == 10);
+		TEST_ASSERT_VAL("Invalid nr hist entries",
+				hists->nr_entries == 9);
+		TEST_ASSERT_VAL("Invalid total period",
+				hists->stats.total_period == 1000);
+
+		/* but filter stats are changed */
+		TEST_ASSERT_VAL("Unmatched nr samples for socket filter",
+				hists->stats.nr_non_filtered_samples == 2);
+		TEST_ASSERT_VAL("Unmatched nr hist entries for socket filter",
+				hists->nr_non_filtered_entries == 2);
+		TEST_ASSERT_VAL("Unmatched total period for socket filter",
+				hists->stats.total_non_filtered_period == 200);
+
+		/* remove socket filter first */
+		hists->socket_filter = -1;
+		hists__filter_by_socket(hists);
+
 		/* now applying all filters at once. */
 		hists->thread_filter = fake_samples[1].thread;
 		hists->dso_filter = fake_samples[1].map->dso;
#16 lore raw

[tip:perf/core] perf tools: Add processor socket info to hist_entry and addr_location

In reply to [email protected]
perf tools: Add processor socket info to hist_entry and addr_location
Commit-ID:  0c4c4debb0adda4c18c158d95031dc2b9f637869
Gitweb:     http://git.kernel.org/tip/0c4c4debb0adda4c18c158d95031dc2b9f637869
Author:     Kan Liang <[email protected]>
AuthorDate: Fri, 4 Sep 2015 10:45:42 -0400
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 14 Sep 2015 12:50:29 -0300

perf tools: Add processor socket info to hist_entry and addr_location

This information will come from perf.data files of from the current system, cached when needed, such as when the 'socket' sort order gets introduced.

Cc Adrian Hunter <[email protected]>
Cc Andi Kleen <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Stephane Eranian <[email protected]>
Cc Wang Nan <[email protected]>
[ Don't blindly use env->cpu[al.cpu].socket_id & use machine->env, fixes by Jiri & Arnaldo ]
---
 tools/perf/util/event.c  | 8 ++++++++
 tools/perf/util/hist.c   | 1 +
 tools/perf/util/sort.h   | 1 +
 tools/perf/util/symbol.h | 1 +
 4 files changed, 11 insertions(+)
tools/perf/util/event.c +8 -0
index 7ff6127..497157a 100644
@@ -1021,6 +1021,14 @@ int perf_event__preprocess_sample(const union perf_event *event,
 
 	al->sym = NULL;
 	al->cpu = sample->cpu;
+	al->socket = -1;
+
+	if (al->cpu >= 0) {
+		struct perf_env *env = machine->env;
+
+		if (env && env->cpu)
+			al->socket = env->cpu[al->cpu].socket_id;
+	}
 
 	if (al->map) {
 		struct dso *dso = al->map->dso;
tools/perf/util/hist.c +1 -0
index 48d5906..d2b94c4 100644
@@ -453,6 +453,7 @@ struct hist_entry *__hists__add_entry(struct hists *hists,
 			.map	= al->map,
 			.sym	= al->sym,
 		},
+		.socket	 = al->socket,
 		.cpu	 = al->cpu,
 		.cpumode = al->cpumode,
 		.ip	 = al->addr,
tools/perf/util/sort.h +1 -0
index 3c2a399..7cf1cf7 100644
@@ -90,6 +90,7 @@ struct hist_entry {
 	struct comm		*comm;
 	u64			ip;
 	u64			transaction;
+	s32			socket;
 	s32			cpu;
 	u8			cpumode;
 
tools/perf/util/symbol.h +1 -0
index 440ba8a..40073c6 100644
@@ -191,6 +191,7 @@ struct addr_location {
 	u8	      filtered;
 	u8	      cpumode;
 	s32	      cpu;
+	s32	      socket;
 };
 
 struct symsrc {