mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kan.liang@intel.com
To: acme@kernel.org
Cc: a.p.zijlstra@chello.nl, mingo@redhat.com, jolsa@kernel.org,
	namhyung@kernel.org, ak@linux.intel.com, eranian@google.com,
	linux-kernel@vger.kernel.org, Kan Liang <kan.liang@intel.com>
Subject: [PATCH RFC 02/10] perf,tools: Support new sort type --socket
Date: Tue, 18 Aug 2015 05:25:38 -0400	[thread overview]
Message-ID: <1439889946-28986-3-git-send-email-kan.liang@intel.com> (raw)
In-Reply-To: <1439889946-28986-1-git-send-email-kan.liang@intel.com>

From: Kan Liang <kan.liang@intel.com>

This patch enable perf report to sort by 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

Signed-off-by: Kan Liang <kan.liang@intel.com>
---
 tools/perf/Documentation/perf-report.txt |  3 ++-
 tools/perf/util/cpumap.c                 | 21 ++++++++++++++-------
 tools/perf/util/cpumap.h                 |  1 +
 tools/perf/util/hist.h                   |  1 +
 tools/perf/util/sort.c                   | 28 ++++++++++++++++++++++++++++
 tools/perf/util/sort.h                   |  1 +
 6 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/tools/perf/Documentation/perf-report.txt b/tools/perf/Documentation/perf-report.txt
index a18ba75..ca76b0d 100644
--- a/tools/perf/Documentation/perf-report.txt
+++ b/tools/perf/Documentation/perf-report.txt
@@ -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: 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
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 3667e21..7f25e6c 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -225,17 +225,12 @@ void cpu_map__put(struct cpu_map *map)
 		cpu_map__delete(map);
 }
 
-int cpu_map__get_socket(struct cpu_map *map, int idx)
+int cpu__get_socket(int cpu)
 {
 	FILE *fp;
 	const char *mnt;
 	char path[PATH_MAX];
-	int cpu, ret;
-
-	if (idx > map->nr)
-		return -1;
-
-	cpu = map->map[idx];
+	int ret;
 
 	mnt = sysfs__mountpoint();
 	if (!mnt)
@@ -253,6 +248,18 @@ int cpu_map__get_socket(struct cpu_map *map, int idx)
 	return ret == 1 ? cpu : -1;
 }
 
+int cpu_map__get_socket(struct cpu_map *map, int idx)
+{
+	int cpu;
+
+	if (idx > map->nr)
+		return -1;
+
+	cpu = map->map[idx];
+
+	return cpu__get_socket(cpu);
+}
+
 static int cmp_ids(const void *a, const void *b)
 {
 	return *(int *)a - *(int *)b;
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 0af9cec..effb56e 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -18,6 +18,7 @@ struct cpu_map *cpu_map__new(const char *cpu_list);
 struct cpu_map *cpu_map__dummy_new(void);
 struct cpu_map *cpu_map__read(FILE *file);
 size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);
+int cpu__get_socket(int cpu);
 int cpu_map__get_socket(struct cpu_map *map, int idx);
 int cpu_map__get_core(struct cpu_map *map, int idx);
 int cpu_map__build_socket_map(struct cpu_map *cpus, struct cpu_map **sockp);
diff --git a/tools/perf/util/hist.h b/tools/perf/util/hist.h
index bc528d5..af80fb5 100644
--- a/tools/perf/util/hist.h
+++ b/tools/perf/util/hist.h
@@ -29,6 +29,7 @@ enum hist_column {
 	HISTC_COMM,
 	HISTC_PARENT,
 	HISTC_CPU,
+	HISTC_SOCKET,
 	HISTC_SRCLINE,
 	HISTC_SRCFILE,
 	HISTC_MISPREDICT,
diff --git a/tools/perf/util/sort.c b/tools/perf/util/sort.c
index 7e38716..245e254 100644
--- a/tools/perf/util/sort.c
+++ b/tools/perf/util/sort.c
@@ -421,6 +421,33 @@ 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)
+{
+	int r_socket, l_socket;
+
+	r_socket = cpu__get_socket(right->cpu);
+	l_socket = cpu__get_socket(left->cpu);
+	return r_socket - l_socket;
+}
+
+static int hist_entry__socket_snprintf(struct hist_entry *he, char *bf,
+				    size_t size, unsigned int width)
+{
+	int socket = cpu__get_socket(he->cpu);
+
+	return repsep_snprintf(bf, size, "%*.*d", width, width-3, 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 +1275,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),
diff --git a/tools/perf/util/sort.h b/tools/perf/util/sort.h
index 3c2a399..9d86a1f 100644
--- a/tools/perf/util/sort.h
+++ b/tools/perf/util/sort.h
@@ -172,6 +172,7 @@ enum sort_type {
 	SORT_SYM,
 	SORT_PARENT,
 	SORT_CPU,
+	SORT_SOCKET,
 	SORT_SRCLINE,
 	SORT_SRCFILE,
 	SORT_LOCAL_WEIGHT,
-- 
1.8.3.1


  parent reply	other threads:[~2015-08-18 16:41 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-18  9:25 [PATCH RFC 00/10] stat read during perf sampling kan.liang
2015-08-18  9:25 ` [PATCH RFC 01/10] perf,tools: open event on evsel cpus and threads kan.liang
2015-08-20  8:57   ` Jiri Olsa
2015-08-20 17:24     ` Liang, Kan
2015-08-21  7:43       ` Jiri Olsa
2015-08-21 13:24         ` Liang, Kan
2015-08-18  9:25 ` kan.liang [this message]
2015-08-20  9:09   ` [PATCH RFC 02/10] perf,tools: Support new sort type --socket Jiri Olsa
2015-08-21 20:25     ` Liang, Kan
2015-08-23 22:00       ` Jiri Olsa
2015-08-24 14:22         ` Liang, Kan
2015-08-24 14:27           ` Jiri Olsa
2015-08-24 16:47             ` Liang, Kan
2015-08-24 19:30               ` Jiri Olsa
2015-08-27 18:24                 ` Jiri Olsa
2015-08-27 18:29                   ` Liang, Kan
2015-08-18  9:25 ` [PATCH RFC 03/10] perf,tools: support option --socket kan.liang
2015-08-18 17:36   ` Stephane Eranian
2015-08-20  9:30   ` Jiri Olsa
2015-08-18  9:25 ` [PATCH RFC 04/10] perf,tools: Add 'N' event/group modifier kan.liang
2015-08-18  9:25 ` [PATCH RFC 05/10] perf,tools: Enable statistic read for perf record kan.liang
2015-08-20  9:39   ` Jiri Olsa
2015-08-20  9:41   ` Jiri Olsa
2015-08-18  9:25 ` [PATCH RFC 06/10] perf,tools: New RECORD type PERF_RECORD_STAT_READ kan.liang
2015-08-20  9:49   ` Jiri Olsa
2015-08-18  9:25 ` [PATCH RFC 07/10] perf,tools: record counter statistics during sampling kan.liang
2015-08-18  9:25 ` [PATCH RFC 08/10] perf,tools: option to set stat read interval kan.liang
2015-08-18  9:25 ` [PATCH RFC 09/10] perf,tools: don't validate non-sample event kan.liang
2015-08-18  9:25 ` [PATCH RFC 10/10] perf,tools: Show STAT_READ in perf report kan.liang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1439889946-28986-3-git-send-email-kan.liang@intel.com \
    --to=kan.liang@intel.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome