linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/8] perf tools: Add sched map changes
@ 2016-04-12 13:29 Jiri Olsa
  2016-04-12 13:29 ` [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa
                   ` (8 more replies)
  0 siblings, 9 replies; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

hi,
sending few perf sched map changes I found
useful recently.

Also available in:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/fixes

thanks,
jirka


---
Jiri Olsa (8):
      perf tools: Add thread_map__has function
      perf tools: Add cpu_map__has function
      perf tools sched: Add compact display option
      perf tools sched: Use color_fprintf for output
      perf tools sched: Make thread_map__new_by_tid_str global
      perf tools sched: Collor given pids
      perf tools sched: Collor given cpus
      perf tools sched: Display only given cpus

 tools/perf/builtin-sched.c   | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
 tools/perf/util/cpumap.c     |  12 ++++++++
 tools/perf/util/cpumap.h     |   2 ++
 tools/perf/util/thread_map.c |  14 ++++++++-
 tools/perf/util/thread_map.h |   3 ++
 5 files changed, 216 insertions(+), 13 deletions(-)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH 1/8] perf tools: Add thread_map__has function
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:43   ` [tip:perf/core] perf thread_map: Add has() method tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 2/8] perf tools: Add cpu_map__has function Jiri Olsa
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Adding thread_map__has function to return bool
of pid presence in threads map.

Link: http://lkml.kernel.org/n/tip-f3ilapuk59z22pi7qs7b0qw9@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/thread_map.c | 12 ++++++++++++
 tools/perf/util/thread_map.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 267112b4e3db..878ac0687b0a 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -436,3 +436,15 @@ struct thread_map *thread_map__new_event(struct thread_map_event *event)
 
 	return threads;
 }
+
+bool thread_map__has(struct thread_map *threads, pid_t pid)
+{
+	int i;
+
+	for (i = 0; i < threads->nr; ++i) {
+		if (threads->map[i].pid == pid)
+			return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 85e4c7c4fbde..9a065ea69ff1 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -55,4 +55,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread)
 }
 
 void thread_map__read_comms(struct thread_map *threads);
+bool thread_map__has(struct thread_map *threads, pid_t pid);
 #endif	/* __PERF_THREAD_MAP_H */
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 2/8] perf tools: Add cpu_map__has function
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
  2016-04-12 13:29 ` [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:43   ` [tip:perf/core] perf cpu_map: Add has() method tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Adding cpu_map__has function to return bool
of cpu presence in cpus map.

Link: http://lkml.kernel.org/n/tip-tygq9cdzleyl7kv4wsz32s8n@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/cpumap.c | 12 ++++++++++++
 tools/perf/util/cpumap.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 9bcf2bed3a6d..02d801670f30 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -587,3 +587,15 @@ int cpu__setup_cpunode_map(void)
 	closedir(dir1);
 	return 0;
 }
+
+bool cpu_map__has(struct cpu_map *cpus, int cpu)
+{
+	int i;
+
+	for (i = 0; i < cpus->nr; ++i) {
+		if (cpus->map[i] == cpu)
+			return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 81a2562aaa2b..1a0a35073ce1 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -66,4 +66,6 @@ int cpu__get_node(int cpu);
 int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
 		       int (*f)(struct cpu_map *map, int cpu, void *data),
 		       void *data);
+
+bool cpu_map__has(struct cpu_map *cpus, int cpu);
 #endif /* __PERF_CPUMAP_H */
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 3/8] perf tools sched: Add compact display option
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
  2016-04-12 13:29 ` [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa
  2016-04-12 13:29 ` [PATCH 2/8] perf tools: Add cpu_map__has function Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-12 14:09   ` Arnaldo Carvalho de Melo
  2016-04-14  5:44   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 4/8] perf tools sched: Use color_fprintf for output Jiri Olsa
                   ` (5 subsequent siblings)
  8 siblings, 2 replies; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Add compact map display that does not output the whole
cpu matrix, only cpus that got event.

  $ perf sched map -c
    *A0   1082427.094098 secs A0 => perf:19404 (CPU 2)
     A0 *.    1082427.094127 secs .  => swapper:0 (CPU 1)
     A0  .  *B0   1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
     A0  .  *.    1082427.094177 secs
    *C0  .   .    1082427.094187 secs C0 => migration/2:21
     C0 *A0  .    1082427.094193 secs
    *.   A0  .    1082427.094195 secs
    *D0  A0  .    1082427.094402 secs D0 => rngd:968
    *.   A0  .    1082427.094406 secs
     .  *E0  .    1082427.095221 secs E0 => kworker/1:1:5333
     .   E0 *F0   1082427.095227 secs F0 => xterm:3342

It helps to display sane output for small thread loads
on big cpu servers.

Link: http://lkml.kernel.org/n/tip-f38ysxz8v6nxoklp7gc4odti@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 56 insertions(+), 6 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 871b55ae22a4..64dd94667055 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -122,6 +122,12 @@ struct trace_sched_handler {
 				  struct machine *machine);
 };
 
+struct perf_sched_map {
+	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
+	int			*comp_cpus;
+	bool			 comp;
+};
+
 struct perf_sched {
 	struct perf_tool tool;
 	const char	 *sort_order;
@@ -173,6 +179,7 @@ struct perf_sched {
 	struct list_head sort_list, cmp_pid;
 	bool force;
 	bool skip_merge;
+	struct perf_sched_map map;
 };
 
 static u64 get_nsecs(void)
@@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	int new_shortname;
 	u64 timestamp0, timestamp = sample->time;
 	s64 delta;
-	int cpu, this_cpu = sample->cpu;
+	int i, this_cpu = sample->cpu;
+	int cpus_nr;
+	bool new_cpu = false;
 
 	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
 	if (this_cpu > sched->max_cpu)
 		sched->max_cpu = this_cpu;
 
+	if (sched->map.comp) {
+		cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
+		if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) {
+			sched->map.comp_cpus[cpus_nr++] = this_cpu;
+			new_cpu = true;
+		}
+	} else
+		cpus_nr = sched->max_cpu;
+
 	timestamp0 = sched->cpu_last_switched[this_cpu];
 	sched->cpu_last_switched[this_cpu] = timestamp;
 	if (timestamp0)
@@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		new_shortname = 1;
 	}
 
-	for (cpu = 0; cpu <= sched->max_cpu; cpu++) {
+	for (i = 0; i < cpus_nr; i++) {
+		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
+
 		if (cpu != this_cpu)
 			printf(" ");
 		else
@@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 
 	printf("  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		printf("%s => %s:%d\n",
+		printf("%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
-	} else {
-		printf("\n");
 	}
 
+	if (sched->map.comp && new_cpu)
+		printf(" (CPU %d)", this_cpu);
+
+	printf("\n");
+
 	thread__put(sched_in);
 
 	return 0;
@@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_map_cpus(struct perf_sched *sched)
+{
+	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
+
+	if (sched->map.comp) {
+		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
+		return sched->map.comp_cpus ? 0 : -1;
+	}
+
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
-	sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF);
+	if (setup_map_cpus(sched))
+		return -1;
 
 	setup_pager();
 	if (perf_sched__read_events(sched))
@@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "dump raw trace in ASCII"),
 	OPT_END()
 	};
+	const struct option map_options[] = {
+	OPT_BOOLEAN(0, "compact", &sched.map.comp,
+		    "map output in compact mode"),
+	OPT_END()
+	};
 	const char * const latency_usage[] = {
 		"perf sched latency [<options>]",
 		NULL
@@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		"perf sched replay [<options>]",
 		NULL
 	};
+	const char * const map_usage[] = {
+		"perf sched map [<options>]",
+		NULL
+	};
 	const char *const sched_subcommands[] = { "record", "latency", "map",
 						  "replay", "script", NULL };
 	const char *sched_usage[] = {
@@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		setup_sorting(&sched, latency_options, latency_usage);
 		return perf_sched__lat(&sched);
 	} else if (!strcmp(argv[0], "map")) {
+		if (argc) {
+			argc = parse_options(argc, argv, map_options, replay_usage, 0);
+			if (argc)
+				usage_with_options(map_usage, map_options);
+		}
 		sched.tp_handler = &map_ops;
 		setup_sorting(&sched, latency_options, latency_usage);
 		return perf_sched__map(&sched);
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 4/8] perf tools sched: Use color_fprintf for output
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (2 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:44   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global Jiri Olsa
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

As preparation for next patch.

Link: http://lkml.kernel.org/n/tip-96g57gf3byte2tb7wgo9v0z1@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-sched.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 64dd94667055..9ef28973f198 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/cloexec.h"
+#include "util/color.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -1357,6 +1358,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	int i, this_cpu = sample->cpu;
 	int cpus_nr;
 	bool new_cpu = false;
+	const char *color = PERF_COLOR_NORMAL;
 
 	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
@@ -1422,26 +1424,26 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
 
 		if (cpu != this_cpu)
-			printf(" ");
+			color_fprintf(stdout, color, " ");
 		else
-			printf("*");
+			color_fprintf(stdout, color, "*");
 
 		if (sched->curr_thread[cpu])
-			printf("%2s ", sched->curr_thread[cpu]->shortname);
+			color_fprintf(stdout, color, "%2s ", sched->curr_thread[cpu]->shortname);
 		else
-			printf("   ");
+			color_fprintf(stdout, color, "   ");
 	}
 
-	printf("  %12.6f secs ", (double)timestamp/1e9);
+	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		printf("%s => %s:%d",
+		color_fprintf(stdout, color, "%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
 	}
 
 	if (sched->map.comp && new_cpu)
-		printf(" (CPU %d)", this_cpu);
+		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-	printf("\n");
+	color_fprintf(stdout, color, "\n");
 
 	thread__put(sched_in);
 
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (3 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 4/8] perf tools sched: Use color_fprintf for output Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:44   ` [tip:perf/core] perf thread_map: Make new_by_tid_str constructor public tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 6/8] perf tools sched: Collor given pids Jiri Olsa
                   ` (3 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

It will be used in following patch.

Link: http://lkml.kernel.org/n/tip-wj8grobfu4ff8a043qo2sakx@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/thread_map.c | 2 +-
 tools/perf/util/thread_map.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 878ac0687b0a..5654fe15e036 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -260,7 +260,7 @@ struct thread_map *thread_map__new_dummy(void)
 	return threads;
 }
 
-static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
+struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
 {
 	struct thread_map *threads = NULL, *nt;
 	int ntasks = 0;
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 9a065ea69ff1..bd3b971588da 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -31,6 +31,8 @@ void thread_map__put(struct thread_map *map);
 struct thread_map *thread_map__new_str(const char *pid,
 		const char *tid, uid_t uid);
 
+struct thread_map *thread_map__new_by_tid_str(const char *tid_str);
+
 size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
 
 static inline int thread_map__nr(struct thread_map *threads)
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 6/8] perf tools sched: Collor given pids
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (4 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:45   ` [tip:perf/core] perf sched map: Color " tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 7/8] perf tools sched: Collor given cpus Jiri Olsa
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Adding --color-pids option to display selected pids
in color (blue by default). It helps on navigating
through the perf sched map output.

Link: http://lkml.kernel.org/n/tip-gmo3z75xp4xtyfaq097ns867@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-sched.c | 77 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 73 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 9ef28973f198..b5361a1d20e1 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/cloexec.h"
+#include "util/thread_map.h"
 #include "util/color.h"
 
 #include <subcmd/parse-options.h>
@@ -123,10 +124,14 @@ struct trace_sched_handler {
 				  struct machine *machine);
 };
 
+#define COLOR_PIDS PERF_COLOR_BLUE
+
 struct perf_sched_map {
 	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
 	int			*comp_cpus;
 	bool			 comp;
+	struct thread_map	*color_pids;
+	const char		*color_pids_str;
 };
 
 struct perf_sched {
@@ -1347,6 +1352,38 @@ static int process_sched_wakeup_event(struct perf_tool *tool,
 	return 0;
 }
 
+union map_priv {
+	void	*ptr;
+	bool	 color;
+};
+
+static bool thread__has_color(struct thread *thread)
+{
+	union map_priv priv = {
+		.ptr = thread__priv(thread),
+	};
+
+	return priv.color;
+}
+
+static struct thread*
+map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid)
+{
+	struct thread *thread = machine__findnew_thread(machine, pid, tid);
+	union map_priv priv = {
+		.color = false,
+	};
+
+	if (!sched->map.color_pids || !thread || thread__priv(thread))
+		return thread;
+
+	if (thread_map__has(sched->map.color_pids, tid))
+		priv.color = true;
+
+	thread__set_priv(thread, priv.ptr);
+	return thread;
+}
+
 static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			    struct perf_sample *sample, struct machine *machine)
 {
@@ -1386,7 +1423,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		return -1;
 	}
 
-	sched_in = machine__findnew_thread(machine, -1, next_pid);
+	sched_in = map__findnew_thread(sched, machine, -1, next_pid);
 	if (sched_in == NULL)
 		return -1;
 
@@ -1422,6 +1459,11 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 
 	for (i = 0; i < cpus_nr; i++) {
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
+		struct thread *curr_thread = sched->curr_thread[cpu];
+		const char *pid_color = color;
+
+		if (curr_thread && thread__has_color(curr_thread))
+			pid_color = COLOR_PIDS;
 
 		if (cpu != this_cpu)
 			color_fprintf(stdout, color, " ");
@@ -1429,14 +1471,19 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			color_fprintf(stdout, color, "*");
 
 		if (sched->curr_thread[cpu])
-			color_fprintf(stdout, color, "%2s ", sched->curr_thread[cpu]->shortname);
+			color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname);
 		else
 			color_fprintf(stdout, color, "   ");
 	}
 
 	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		color_fprintf(stdout, color, "%s => %s:%d",
+		const char *pid_color = color;
+
+		if (thread__has_color(sched_in))
+			pid_color = COLOR_PIDS;
+
+		color_fprintf(stdout, pid_color, "%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
 	}
 
@@ -1712,11 +1759,31 @@ static int setup_map_cpus(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_color_pids(struct perf_sched *sched)
+{
+	struct thread_map *map;
+
+	if (!sched->map.color_pids_str)
+		return 0;
+
+	map = thread_map__new_by_tid_str(sched->map.color_pids_str);
+	if (!map) {
+		pr_err("failed to get thread map from %s\n", sched->map.color_pids_str);
+		return -1;
+	}
+
+	sched->map.color_pids = map;
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
 	if (setup_map_cpus(sched))
 		return -1;
 
+	if (setup_color_pids(sched))
+		return -1;
+
 	setup_pager();
 	if (perf_sched__read_events(sched))
 		return -1;
@@ -1872,6 +1939,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	const struct option map_options[] = {
 	OPT_BOOLEAN(0, "compact", &sched.map.comp,
 		    "map output in compact mode"),
+	OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids",
+		   "highlight given pids in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {
@@ -1935,7 +2004,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		return perf_sched__lat(&sched);
 	} else if (!strcmp(argv[0], "map")) {
 		if (argc) {
-			argc = parse_options(argc, argv, map_options, replay_usage, 0);
+			argc = parse_options(argc, argv, map_options, map_usage, 0);
 			if (argc)
 				usage_with_options(map_usage, map_options);
 		}
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 7/8] perf tools sched: Collor given cpus
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (5 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 6/8] perf tools sched: Collor given pids Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:45   ` [tip:perf/core] perf sched map: Color " tip-bot for Jiri Olsa
  2016-04-12 13:29 ` [PATCH 8/8] perf tools sched: Display only " Jiri Olsa
  2016-04-12 14:38 ` [PATCH 0/8] perf tools: Add sched map changes Arnaldo Carvalho de Melo
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Adding --color-cpus option to display selected
cpus with background color (red by default).
It helps on navigating through the perf sched
map output.

Link: http://lkml.kernel.org/n/tip-pcgjno3j1qm5xp1jdtowosgm@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-sched.c | 36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index b5361a1d20e1..7de04b297c14 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -125,6 +125,7 @@ struct trace_sched_handler {
 };
 
 #define COLOR_PIDS PERF_COLOR_BLUE
+#define COLOR_CPUS PERF_COLOR_BG_RED
 
 struct perf_sched_map {
 	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
@@ -132,6 +133,8 @@ struct perf_sched_map {
 	bool			 comp;
 	struct thread_map	*color_pids;
 	const char		*color_pids_str;
+	struct cpu_map		*color_cpus;
+	const char		*color_cpus_str;
 };
 
 struct perf_sched {
@@ -1461,14 +1464,18 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
 		struct thread *curr_thread = sched->curr_thread[cpu];
 		const char *pid_color = color;
+		const char *cpu_color = color;
 
 		if (curr_thread && thread__has_color(curr_thread))
 			pid_color = COLOR_PIDS;
 
+		if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu))
+			cpu_color = COLOR_CPUS;
+
 		if (cpu != this_cpu)
-			color_fprintf(stdout, color, " ");
+			color_fprintf(stdout, cpu_color, " ");
 		else
-			color_fprintf(stdout, color, "*");
+			color_fprintf(stdout, cpu_color, "*");
 
 		if (sched->curr_thread[cpu])
 			color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname);
@@ -1753,7 +1760,8 @@ static int setup_map_cpus(struct perf_sched *sched)
 
 	if (sched->map.comp) {
 		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
-		return sched->map.comp_cpus ? 0 : -1;
+		if (!sched->map.comp_cpus)
+			return -1;
 	}
 
 	return 0;
@@ -1776,6 +1784,23 @@ static int setup_color_pids(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_color_cpus(struct perf_sched *sched)
+{
+	struct cpu_map *map;
+
+	if (!sched->map.color_cpus_str)
+		return 0;
+
+	map = cpu_map__new(sched->map.color_cpus_str);
+	if (!map) {
+		pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str);
+		return -1;
+	}
+
+	sched->map.color_cpus = map;
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
 	if (setup_map_cpus(sched))
@@ -1784,6 +1809,9 @@ static int perf_sched__map(struct perf_sched *sched)
 	if (setup_color_pids(sched))
 		return -1;
 
+	if (setup_color_cpus(sched))
+		return -1;
+
 	setup_pager();
 	if (perf_sched__read_events(sched))
 		return -1;
@@ -1941,6 +1969,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "map output in compact mode"),
 	OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids",
 		   "highlight given pids in map"),
+	OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus",
+                    "highlight given CPUs in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH 8/8] perf tools sched: Display only given cpus
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (6 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 7/8] perf tools sched: Collor given cpus Jiri Olsa
@ 2016-04-12 13:29 ` Jiri Olsa
  2016-04-14  5:46   ` [tip:perf/core] perf sched map: " tip-bot for Jiri Olsa
  2016-04-12 14:38 ` [PATCH 0/8] perf tools: Add sched map changes Arnaldo Carvalho de Melo
  8 siblings, 1 reply; 20+ messages in thread
From: Jiri Olsa @ 2016-04-12 13:29 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Introducing --cpus option that will display
only given cpus. Could be used together with
color-cpus option.

  $ perf sched map  --cpus 0,1
        *A0   309999.786924 secs A0 => rcu_sched:7
        *.    309999.786930 secs
    *B0  .    309999.786931 secs B0 => rcuos/2:25
     B0 *A0   309999.786947 secs

Link: http://lkml.kernel.org/n/tip-ygiqyv4ouh9r03c9zcvw49tv@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-sched.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 7de04b297c14..afa057666c2a 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -135,6 +135,8 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct cpu_map		*color_cpus;
 	const char		*color_cpus_str;
+	struct cpu_map		*cpus;
+	const char		*cpus_str;
 };
 
 struct perf_sched {
@@ -1469,6 +1471,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		if (curr_thread && thread__has_color(curr_thread))
 			pid_color = COLOR_PIDS;
 
+		if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu))
+			continue;
+
 		if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu))
 			cpu_color = COLOR_CPUS;
 
@@ -1483,6 +1488,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			color_fprintf(stdout, color, "   ");
 	}
 
+	if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu))
+		goto out;
+
 	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
 		const char *pid_color = color;
@@ -1497,6 +1505,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	if (sched->map.comp && new_cpu)
 		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
+out:
 	color_fprintf(stdout, color, "\n");
 
 	thread__put(sched_in);
@@ -1756,6 +1765,8 @@ static int perf_sched__lat(struct perf_sched *sched)
 
 static int setup_map_cpus(struct perf_sched *sched)
 {
+	struct cpu_map *map;
+
 	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
 
 	if (sched->map.comp) {
@@ -1764,6 +1775,16 @@ static int setup_map_cpus(struct perf_sched *sched)
 			return -1;
 	}
 
+	if (!sched->map.cpus_str)
+		return 0;
+
+	map = cpu_map__new(sched->map.cpus_str);
+	if (!map) {
+		pr_err("failed to get cpus map from %s\n", sched->map.cpus_str);
+		return -1;
+	}
+
+	sched->map.cpus = map;
 	return 0;
 }
 
@@ -1971,6 +1992,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "highlight given pids in map"),
 	OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus",
                     "highlight given CPUs in map"),
+	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
+                    "display given CPUs in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {
-- 
2.4.11

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/8] perf tools sched: Add compact display option
  2016-04-12 13:29 ` [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa
@ 2016-04-12 14:09   ` Arnaldo Carvalho de Melo
  2016-04-12 14:18     ` Arnaldo Carvalho de Melo
  2016-04-14  5:44   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
  1 sibling, 1 reply; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-12 14:09 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Em Tue, Apr 12, 2016 at 03:29:26PM +0200, Jiri Olsa escreveu:
> Add compact map display that does not output the whole
> cpu matrix, only cpus that got event.
> 
>   $ perf sched map -c

I was going to point out that you better use --compact, as one-letter
otpions are for some... but then I realized you already did that, will
update your changelog comment :-)

Testing it I noticed that the first few lines get unaligned, is that by
design? Haven't looked at the code.

  *.    31203.236293 secs .  => swapper:0 (CPU 3)
   .  *A0   31203.236964 secs A0 => rcu_sched:7 (CPU 0)
   .  *.    31203.236968 secs 
   .   .  *B0   31203.236968 secs B0 => rcuos/2:28 (CPU 1)
   .   .   B0 *C0   31203.236973 secs C0 => rcuos/3:36 (CPU 2)
   .  *A0  B0  C0   31203.236973 secs 
   .   A0 *.   C0   31203.236974 secs 
   .  *.   .   C0   31203.236975 secs 
   .   .   .  *.    31203.236986 secs 
   .  *A0  .   .    31203.239952 secs 


- Arnaldo

>     *A0   1082427.094098 secs A0 => perf:19404 (CPU 2)
>      A0 *.    1082427.094127 secs .  => swapper:0 (CPU 1)
>      A0  .  *B0   1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
>      A0  .  *.    1082427.094177 secs
>     *C0  .   .    1082427.094187 secs C0 => migration/2:21
>      C0 *A0  .    1082427.094193 secs
>     *.   A0  .    1082427.094195 secs
>     *D0  A0  .    1082427.094402 secs D0 => rngd:968
>     *.   A0  .    1082427.094406 secs
>      .  *E0  .    1082427.095221 secs E0 => kworker/1:1:5333
>      .   E0 *F0   1082427.095227 secs F0 => xterm:3342
> 
> It helps to display sane output for small thread loads
> on big cpu servers.
> 
> Link: http://lkml.kernel.org/n/tip-f38ysxz8v6nxoklp7gc4odti@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 56 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> index 871b55ae22a4..64dd94667055 100644
> --- a/tools/perf/builtin-sched.c
> +++ b/tools/perf/builtin-sched.c
> @@ -122,6 +122,12 @@ struct trace_sched_handler {
>  				  struct machine *machine);
>  };
>  
> +struct perf_sched_map {
> +	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
> +	int			*comp_cpus;
> +	bool			 comp;
> +};
> +
>  struct perf_sched {
>  	struct perf_tool tool;
>  	const char	 *sort_order;
> @@ -173,6 +179,7 @@ struct perf_sched {
>  	struct list_head sort_list, cmp_pid;
>  	bool force;
>  	bool skip_merge;
> +	struct perf_sched_map map;
>  };
>  
>  static u64 get_nsecs(void)
> @@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
>  	int new_shortname;
>  	u64 timestamp0, timestamp = sample->time;
>  	s64 delta;
> -	int cpu, this_cpu = sample->cpu;
> +	int i, this_cpu = sample->cpu;
> +	int cpus_nr;
> +	bool new_cpu = false;
>  
>  	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
>  
>  	if (this_cpu > sched->max_cpu)
>  		sched->max_cpu = this_cpu;
>  
> +	if (sched->map.comp) {
> +		cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
> +		if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) {
> +			sched->map.comp_cpus[cpus_nr++] = this_cpu;
> +			new_cpu = true;
> +		}
> +	} else
> +		cpus_nr = sched->max_cpu;
> +
>  	timestamp0 = sched->cpu_last_switched[this_cpu];
>  	sched->cpu_last_switched[this_cpu] = timestamp;
>  	if (timestamp0)
> @@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
>  		new_shortname = 1;
>  	}
>  
> -	for (cpu = 0; cpu <= sched->max_cpu; cpu++) {
> +	for (i = 0; i < cpus_nr; i++) {
> +		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
> +
>  		if (cpu != this_cpu)
>  			printf(" ");
>  		else
> @@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
>  
>  	printf("  %12.6f secs ", (double)timestamp/1e9);
>  	if (new_shortname) {
> -		printf("%s => %s:%d\n",
> +		printf("%s => %s:%d",
>  		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
> -	} else {
> -		printf("\n");
>  	}
>  
> +	if (sched->map.comp && new_cpu)
> +		printf(" (CPU %d)", this_cpu);
> +
> +	printf("\n");
> +
>  	thread__put(sched_in);
>  
>  	return 0;
> @@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)
>  	return 0;
>  }
>  
> +static int setup_map_cpus(struct perf_sched *sched)
> +{
> +	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
> +
> +	if (sched->map.comp) {
> +		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
> +		return sched->map.comp_cpus ? 0 : -1;
> +	}
> +
> +	return 0;
> +}
> +
>  static int perf_sched__map(struct perf_sched *sched)
>  {
> -	sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF);
> +	if (setup_map_cpus(sched))
> +		return -1;
>  
>  	setup_pager();
>  	if (perf_sched__read_events(sched))
> @@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
>  		    "dump raw trace in ASCII"),
>  	OPT_END()
>  	};
> +	const struct option map_options[] = {
> +	OPT_BOOLEAN(0, "compact", &sched.map.comp,
> +		    "map output in compact mode"),
> +	OPT_END()
> +	};
>  	const char * const latency_usage[] = {
>  		"perf sched latency [<options>]",
>  		NULL
> @@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
>  		"perf sched replay [<options>]",
>  		NULL
>  	};
> +	const char * const map_usage[] = {
> +		"perf sched map [<options>]",
> +		NULL
> +	};
>  	const char *const sched_subcommands[] = { "record", "latency", "map",
>  						  "replay", "script", NULL };
>  	const char *sched_usage[] = {
> @@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
>  		setup_sorting(&sched, latency_options, latency_usage);
>  		return perf_sched__lat(&sched);
>  	} else if (!strcmp(argv[0], "map")) {
> +		if (argc) {
> +			argc = parse_options(argc, argv, map_options, replay_usage, 0);
> +			if (argc)
> +				usage_with_options(map_usage, map_options);
> +		}
>  		sched.tp_handler = &map_ops;
>  		setup_sorting(&sched, latency_options, latency_usage);
>  		return perf_sched__map(&sched);
> -- 
> 2.4.11

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 3/8] perf tools sched: Add compact display option
  2016-04-12 14:09   ` Arnaldo Carvalho de Melo
@ 2016-04-12 14:18     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-12 14:18 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Em Tue, Apr 12, 2016 at 11:09:47AM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Tue, Apr 12, 2016 at 03:29:26PM +0200, Jiri Olsa escreveu:
> > Add compact map display that does not output the whole
> > cpu matrix, only cpus that got event.
> > 
> >   $ perf sched map -c
> 
> I was going to point out that you better use --compact, as one-letter
> otpions are for some... but then I realized you already did that, will
> update your changelog comment :-)
> 
> Testing it I noticed that the first few lines get unaligned, is that by
> design? Haven't looked at the code.
> 
>   *.    31203.236293 secs .  => swapper:0 (CPU 3)
>    .  *A0   31203.236964 secs A0 => rcu_sched:7 (CPU 0)
>    .  *.    31203.236968 secs 
>    .   .  *B0   31203.236968 secs B0 => rcuos/2:28 (CPU 1)
>    .   .   B0 *C0   31203.236973 secs C0 => rcuos/3:36 (CPU 2)
>    .  *A0  B0  C0   31203.236973 secs 
>    .   A0 *.   C0   31203.236974 secs 
>    .  *.   .   C0   31203.236975 secs 
>    .   .   .  *.    31203.236986 secs 
>    .  *A0  .   .    31203.239952 secs 
> 

Got it, by design, applied.
 
> - Arnaldo
> 
> >     *A0   1082427.094098 secs A0 => perf:19404 (CPU 2)
> >      A0 *.    1082427.094127 secs .  => swapper:0 (CPU 1)
> >      A0  .  *B0   1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
> >      A0  .  *.    1082427.094177 secs
> >     *C0  .   .    1082427.094187 secs C0 => migration/2:21
> >      C0 *A0  .    1082427.094193 secs
> >     *.   A0  .    1082427.094195 secs
> >     *D0  A0  .    1082427.094402 secs D0 => rngd:968
> >     *.   A0  .    1082427.094406 secs
> >      .  *E0  .    1082427.095221 secs E0 => kworker/1:1:5333
> >      .   E0 *F0   1082427.095227 secs F0 => xterm:3342
> > 
> > It helps to display sane output for small thread loads
> > on big cpu servers.
> > 
> > Link: http://lkml.kernel.org/n/tip-f38ysxz8v6nxoklp7gc4odti@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/builtin-sched.c | 62 +++++++++++++++++++++++++++++++++++++++++-----
> >  1 file changed, 56 insertions(+), 6 deletions(-)
> > 
> > diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
> > index 871b55ae22a4..64dd94667055 100644
> > --- a/tools/perf/builtin-sched.c
> > +++ b/tools/perf/builtin-sched.c
> > @@ -122,6 +122,12 @@ struct trace_sched_handler {
> >  				  struct machine *machine);
> >  };
> >  
> > +struct perf_sched_map {
> > +	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
> > +	int			*comp_cpus;
> > +	bool			 comp;
> > +};
> > +
> >  struct perf_sched {
> >  	struct perf_tool tool;
> >  	const char	 *sort_order;
> > @@ -173,6 +179,7 @@ struct perf_sched {
> >  	struct list_head sort_list, cmp_pid;
> >  	bool force;
> >  	bool skip_merge;
> > +	struct perf_sched_map map;
> >  };
> >  
> >  static u64 get_nsecs(void)
> > @@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
> >  	int new_shortname;
> >  	u64 timestamp0, timestamp = sample->time;
> >  	s64 delta;
> > -	int cpu, this_cpu = sample->cpu;
> > +	int i, this_cpu = sample->cpu;
> > +	int cpus_nr;
> > +	bool new_cpu = false;
> >  
> >  	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
> >  
> >  	if (this_cpu > sched->max_cpu)
> >  		sched->max_cpu = this_cpu;
> >  
> > +	if (sched->map.comp) {
> > +		cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
> > +		if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) {
> > +			sched->map.comp_cpus[cpus_nr++] = this_cpu;
> > +			new_cpu = true;
> > +		}
> > +	} else
> > +		cpus_nr = sched->max_cpu;
> > +
> >  	timestamp0 = sched->cpu_last_switched[this_cpu];
> >  	sched->cpu_last_switched[this_cpu] = timestamp;
> >  	if (timestamp0)
> > @@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
> >  		new_shortname = 1;
> >  	}
> >  
> > -	for (cpu = 0; cpu <= sched->max_cpu; cpu++) {
> > +	for (i = 0; i < cpus_nr; i++) {
> > +		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
> > +
> >  		if (cpu != this_cpu)
> >  			printf(" ");
> >  		else
> > @@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
> >  
> >  	printf("  %12.6f secs ", (double)timestamp/1e9);
> >  	if (new_shortname) {
> > -		printf("%s => %s:%d\n",
> > +		printf("%s => %s:%d",
> >  		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
> > -	} else {
> > -		printf("\n");
> >  	}
> >  
> > +	if (sched->map.comp && new_cpu)
> > +		printf(" (CPU %d)", this_cpu);
> > +
> > +	printf("\n");
> > +
> >  	thread__put(sched_in);
> >  
> >  	return 0;
> > @@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)
> >  	return 0;
> >  }
> >  
> > +static int setup_map_cpus(struct perf_sched *sched)
> > +{
> > +	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
> > +
> > +	if (sched->map.comp) {
> > +		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
> > +		return sched->map.comp_cpus ? 0 : -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> >  static int perf_sched__map(struct perf_sched *sched)
> >  {
> > -	sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF);
> > +	if (setup_map_cpus(sched))
> > +		return -1;
> >  
> >  	setup_pager();
> >  	if (perf_sched__read_events(sched))
> > @@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
> >  		    "dump raw trace in ASCII"),
> >  	OPT_END()
> >  	};
> > +	const struct option map_options[] = {
> > +	OPT_BOOLEAN(0, "compact", &sched.map.comp,
> > +		    "map output in compact mode"),
> > +	OPT_END()
> > +	};
> >  	const char * const latency_usage[] = {
> >  		"perf sched latency [<options>]",
> >  		NULL
> > @@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
> >  		"perf sched replay [<options>]",
> >  		NULL
> >  	};
> > +	const char * const map_usage[] = {
> > +		"perf sched map [<options>]",
> > +		NULL
> > +	};
> >  	const char *const sched_subcommands[] = { "record", "latency", "map",
> >  						  "replay", "script", NULL };
> >  	const char *sched_usage[] = {
> > @@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
> >  		setup_sorting(&sched, latency_options, latency_usage);
> >  		return perf_sched__lat(&sched);
> >  	} else if (!strcmp(argv[0], "map")) {
> > +		if (argc) {
> > +			argc = parse_options(argc, argv, map_options, replay_usage, 0);
> > +			if (argc)
> > +				usage_with_options(map_usage, map_options);
> > +		}
> >  		sched.tp_handler = &map_ops;
> >  		setup_sorting(&sched, latency_options, latency_usage);
> >  		return perf_sched__map(&sched);
> > -- 
> > 2.4.11

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH 0/8] perf tools: Add sched map changes
  2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
                   ` (7 preceding siblings ...)
  2016-04-12 13:29 ` [PATCH 8/8] perf tools sched: Display only " Jiri Olsa
@ 2016-04-12 14:38 ` Arnaldo Carvalho de Melo
  8 siblings, 0 replies; 20+ messages in thread
From: Arnaldo Carvalho de Melo @ 2016-04-12 14:38 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: lkml, David Ahern, Ingo Molnar, Namhyung Kim, Peter Zijlstra

Em Tue, Apr 12, 2016 at 03:29:23PM +0200, Jiri Olsa escreveu:
> hi,
> sending few perf sched map changes I found
> useful recently.
> 
> Also available in:
>   git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
>   perf/fixes

Applied, after adding a "OPTIONS perf sched map" to 'perf sched's man
page and entries in the patches adding new options.

Pushed to acme/perf/core

- Arnaldo
 
> thanks,
> jirka
> 
> 
> ---
> Jiri Olsa (8):
>       perf tools: Add thread_map__has function
>       perf tools: Add cpu_map__has function
>       perf tools sched: Add compact display option
>       perf tools sched: Use color_fprintf for output
>       perf tools sched: Make thread_map__new_by_tid_str global
>       perf tools sched: Collor given pids
>       perf tools sched: Collor given cpus
>       perf tools sched: Display only given cpus
> 
>  tools/perf/builtin-sched.c   | 198 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
>  tools/perf/util/cpumap.c     |  12 ++++++++
>  tools/perf/util/cpumap.h     |   2 ++
>  tools/perf/util/thread_map.c |  14 ++++++++-
>  tools/perf/util/thread_map.h |   3 ++
>  5 files changed, 216 insertions(+), 13 deletions(-)

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf thread_map: Add has() method
  2016-04-12 13:29 ` [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa
@ 2016-04-14  5:43   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, hpa, mingo, acme, namhyung, jolsa, linux-kernel,
	dsahern, tglx

Commit-ID:  3407df8bbc3a91d9aa4910130026ab6b3a261b87
Gitweb:     http://git.kernel.org/tip/3407df8bbc3a91d9aa4910130026ab6b3a261b87
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:24 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:50 -0300

perf thread_map: Add has() method

Adding thread_map__has() to return bool of pid presence in threads map.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-2-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/thread_map.c | 12 ++++++++++++
 tools/perf/util/thread_map.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 267112b..878ac06 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -436,3 +436,15 @@ struct thread_map *thread_map__new_event(struct thread_map_event *event)
 
 	return threads;
 }
+
+bool thread_map__has(struct thread_map *threads, pid_t pid)
+{
+	int i;
+
+	for (i = 0; i < threads->nr; ++i) {
+		if (threads->map[i].pid == pid)
+			return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 85e4c7c..9a065ea 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -55,4 +55,5 @@ static inline char *thread_map__comm(struct thread_map *map, int thread)
 }
 
 void thread_map__read_comms(struct thread_map *threads);
+bool thread_map__has(struct thread_map *threads, pid_t pid);
 #endif	/* __PERF_THREAD_MAP_H */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf cpu_map: Add has() method
  2016-04-12 13:29 ` [PATCH 2/8] perf tools: Add cpu_map__has function Jiri Olsa
@ 2016-04-14  5:43   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:43 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, hpa, mingo, a.p.zijlstra, tglx, jolsa, acme, dsahern,
	linux-kernel

Commit-ID:  e632aa69c919462a7f93c8799b97c8a9ddd48fc2
Gitweb:     http://git.kernel.org/tip/e632aa69c919462a7f93c8799b97c8a9ddd48fc2
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:25 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:50 -0300

perf cpu_map: Add has() method

Adding cpu_map__has() to return bool of cpu presence in cpus map.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-3-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/cpumap.c | 12 ++++++++++++
 tools/perf/util/cpumap.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 9bcf2be..02d8016 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -587,3 +587,15 @@ int cpu__setup_cpunode_map(void)
 	closedir(dir1);
 	return 0;
 }
+
+bool cpu_map__has(struct cpu_map *cpus, int cpu)
+{
+	int i;
+
+	for (i = 0; i < cpus->nr; ++i) {
+		if (cpus->map[i] == cpu)
+			return true;
+	}
+
+	return false;
+}
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 81a2562..1a0a350 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -66,4 +66,6 @@ int cpu__get_node(int cpu);
 int cpu_map__build_map(struct cpu_map *cpus, struct cpu_map **res,
 		       int (*f)(struct cpu_map *map, int cpu, void *data),
 		       void *data);
+
+bool cpu_map__has(struct cpu_map *cpus, int cpu);
 #endif /* __PERF_CPUMAP_H */

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf sched: Add compact display option
  2016-04-12 13:29 ` [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa
  2016-04-12 14:09   ` Arnaldo Carvalho de Melo
@ 2016-04-14  5:44   ` tip-bot for Jiri Olsa
  1 sibling, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, dsahern, tglx, hpa, namhyung, acme, linux-kernel, mingo,
	a.p.zijlstra

Commit-ID:  99623c628f5425f09b5321cf621af1da29c0c47d
Gitweb:     http://git.kernel.org/tip/99623c628f5425f09b5321cf621af1da29c0c47d
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:26 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:51 -0300

perf sched: Add compact display option

Add compact map display that does not output the whole cpu matrix, only
cpus that got event.

  $ perf sched map --compact
    *A0   1082427.094098 secs A0 => perf:19404 (CPU 2)
     A0 *.    1082427.094127 secs .  => swapper:0 (CPU 1)
     A0  .  *B0   1082427.094174 secs B0 => rcuos/2:25 (CPU 3)
     A0  .  *.    1082427.094177 secs
    *C0  .   .    1082427.094187 secs C0 => migration/2:21
     C0 *A0  .    1082427.094193 secs
    *.   A0  .    1082427.094195 secs
    *D0  A0  .    1082427.094402 secs D0 => rngd:968
    *.   A0  .    1082427.094406 secs
     .  *E0  .    1082427.095221 secs E0 => kworker/1:1:5333
     .   E0 *F0   1082427.095227 secs F0 => xterm:3342

It helps to display sane output for small thread loads on big cpu
servers.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-4-git-send-email-jolsa@kernel.org
[ Add entry in 'perf sched' man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  7 ++++
 tools/perf/builtin-sched.c              | 62 +++++++++++++++++++++++++++++----
 2 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 8ff4df9..89b0c5b 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -50,6 +50,13 @@ OPTIONS
 --dump-raw-trace=::
         Display verbose dump of the sched data.
 
+OPTIONS for 'perf sched map'
+----------------------------
+
+--compact::
+	Show only CPUs with activity. Helps visualizing on high core
+	count systems.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 871b55ae..64dd946 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -122,6 +122,12 @@ struct trace_sched_handler {
 				  struct machine *machine);
 };
 
+struct perf_sched_map {
+	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
+	int			*comp_cpus;
+	bool			 comp;
+};
+
 struct perf_sched {
 	struct perf_tool tool;
 	const char	 *sort_order;
@@ -173,6 +179,7 @@ struct perf_sched {
 	struct list_head sort_list, cmp_pid;
 	bool force;
 	bool skip_merge;
+	struct perf_sched_map map;
 };
 
 static u64 get_nsecs(void)
@@ -1347,13 +1354,24 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	int new_shortname;
 	u64 timestamp0, timestamp = sample->time;
 	s64 delta;
-	int cpu, this_cpu = sample->cpu;
+	int i, this_cpu = sample->cpu;
+	int cpus_nr;
+	bool new_cpu = false;
 
 	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
 	if (this_cpu > sched->max_cpu)
 		sched->max_cpu = this_cpu;
 
+	if (sched->map.comp) {
+		cpus_nr = bitmap_weight(sched->map.comp_cpus_mask, MAX_CPUS);
+		if (!test_and_set_bit(this_cpu, sched->map.comp_cpus_mask)) {
+			sched->map.comp_cpus[cpus_nr++] = this_cpu;
+			new_cpu = true;
+		}
+	} else
+		cpus_nr = sched->max_cpu;
+
 	timestamp0 = sched->cpu_last_switched[this_cpu];
 	sched->cpu_last_switched[this_cpu] = timestamp;
 	if (timestamp0)
@@ -1400,7 +1418,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		new_shortname = 1;
 	}
 
-	for (cpu = 0; cpu <= sched->max_cpu; cpu++) {
+	for (i = 0; i < cpus_nr; i++) {
+		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
+
 		if (cpu != this_cpu)
 			printf(" ");
 		else
@@ -1414,12 +1434,15 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 
 	printf("  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		printf("%s => %s:%d\n",
+		printf("%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
-	} else {
-		printf("\n");
 	}
 
+	if (sched->map.comp && new_cpu)
+		printf(" (CPU %d)", this_cpu);
+
+	printf("\n");
+
 	thread__put(sched_in);
 
 	return 0;
@@ -1675,9 +1698,22 @@ static int perf_sched__lat(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_map_cpus(struct perf_sched *sched)
+{
+	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
+
+	if (sched->map.comp) {
+		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
+		return sched->map.comp_cpus ? 0 : -1;
+	}
+
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
-	sched->max_cpu = sysconf(_SC_NPROCESSORS_CONF);
+	if (setup_map_cpus(sched))
+		return -1;
 
 	setup_pager();
 	if (perf_sched__read_events(sched))
@@ -1831,6 +1867,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "dump raw trace in ASCII"),
 	OPT_END()
 	};
+	const struct option map_options[] = {
+	OPT_BOOLEAN(0, "compact", &sched.map.comp,
+		    "map output in compact mode"),
+	OPT_END()
+	};
 	const char * const latency_usage[] = {
 		"perf sched latency [<options>]",
 		NULL
@@ -1839,6 +1880,10 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		"perf sched replay [<options>]",
 		NULL
 	};
+	const char * const map_usage[] = {
+		"perf sched map [<options>]",
+		NULL
+	};
 	const char *const sched_subcommands[] = { "record", "latency", "map",
 						  "replay", "script", NULL };
 	const char *sched_usage[] = {
@@ -1887,6 +1932,11 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		setup_sorting(&sched, latency_options, latency_usage);
 		return perf_sched__lat(&sched);
 	} else if (!strcmp(argv[0], "map")) {
+		if (argc) {
+			argc = parse_options(argc, argv, map_options, replay_usage, 0);
+			if (argc)
+				usage_with_options(map_usage, map_options);
+		}
 		sched.tp_handler = &map_ops;
 		setup_sorting(&sched, latency_options, latency_usage);
 		return perf_sched__map(&sched);

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf sched: Use color_fprintf for output
  2016-04-12 13:29 ` [PATCH 4/8] perf tools sched: Use color_fprintf for output Jiri Olsa
@ 2016-04-14  5:44   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: hpa, mingo, dsahern, jolsa, a.p.zijlstra, namhyung, tglx,
	linux-kernel, acme

Commit-ID:  8cd91195e5efc5166fc48eec6cf83ef93133b7b6
Gitweb:     http://git.kernel.org/tip/8cd91195e5efc5166fc48eec6cf83ef93133b7b6
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:27 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:51 -0300

perf sched: Use color_fprintf for output

As preparation for next patch.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-5-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-sched.c | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 64dd946..9ef2897 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/cloexec.h"
+#include "util/color.h"
 
 #include <subcmd/parse-options.h>
 #include "util/trace-event.h"
@@ -1357,6 +1358,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	int i, this_cpu = sample->cpu;
 	int cpus_nr;
 	bool new_cpu = false;
+	const char *color = PERF_COLOR_NORMAL;
 
 	BUG_ON(this_cpu >= MAX_CPUS || this_cpu < 0);
 
@@ -1422,26 +1424,26 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
 
 		if (cpu != this_cpu)
-			printf(" ");
+			color_fprintf(stdout, color, " ");
 		else
-			printf("*");
+			color_fprintf(stdout, color, "*");
 
 		if (sched->curr_thread[cpu])
-			printf("%2s ", sched->curr_thread[cpu]->shortname);
+			color_fprintf(stdout, color, "%2s ", sched->curr_thread[cpu]->shortname);
 		else
-			printf("   ");
+			color_fprintf(stdout, color, "   ");
 	}
 
-	printf("  %12.6f secs ", (double)timestamp/1e9);
+	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		printf("%s => %s:%d",
+		color_fprintf(stdout, color, "%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
 	}
 
 	if (sched->map.comp && new_cpu)
-		printf(" (CPU %d)", this_cpu);
+		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
-	printf("\n");
+	color_fprintf(stdout, color, "\n");
 
 	thread__put(sched_in);
 

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf thread_map: Make new_by_tid_str constructor public
  2016-04-12 13:29 ` [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global Jiri Olsa
@ 2016-04-14  5:44   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:44 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: tglx, a.p.zijlstra, acme, linux-kernel, namhyung, mingo, dsahern,
	jolsa, hpa

Commit-ID:  097be0f5034fc9edaf84253b773b14bc2af9a708
Gitweb:     http://git.kernel.org/tip/097be0f5034fc9edaf84253b773b14bc2af9a708
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:28 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:51 -0300

perf thread_map: Make new_by_tid_str constructor public

It will be used in following patch.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-6-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/thread_map.c | 2 +-
 tools/perf/util/thread_map.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/thread_map.c b/tools/perf/util/thread_map.c
index 878ac06..5654fe1 100644
--- a/tools/perf/util/thread_map.c
+++ b/tools/perf/util/thread_map.c
@@ -260,7 +260,7 @@ struct thread_map *thread_map__new_dummy(void)
 	return threads;
 }
 
-static struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
+struct thread_map *thread_map__new_by_tid_str(const char *tid_str)
 {
 	struct thread_map *threads = NULL, *nt;
 	int ntasks = 0;
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 9a065ea..bd3b971 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -31,6 +31,8 @@ void thread_map__put(struct thread_map *map);
 struct thread_map *thread_map__new_str(const char *pid,
 		const char *tid, uid_t uid);
 
+struct thread_map *thread_map__new_by_tid_str(const char *tid_str);
+
 size_t thread_map__fprintf(struct thread_map *threads, FILE *fp);
 
 static inline int thread_map__nr(struct thread_map *threads)

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf sched map: Color given pids
  2016-04-12 13:29 ` [PATCH 6/8] perf tools sched: Collor given pids Jiri Olsa
@ 2016-04-14  5:45   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: namhyung, jolsa, linux-kernel, mingo, hpa, tglx, dsahern,
	a.p.zijlstra, acme

Commit-ID:  a151a37a760aab41c115af8d5016e449228e8d2e
Gitweb:     http://git.kernel.org/tip/a151a37a760aab41c115af8d5016e449228e8d2e
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:29 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:51 -0300

perf sched map: Color given pids

Adding --color-pids option to display selected pids in color (blue by
default). It helps on navigating through the 'perf sched map' output.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-7-git-send-email-jolsa@kernel.org
[ Added entry to man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  3 ++
 tools/perf/builtin-sched.c              | 77 +++++++++++++++++++++++++++++++--
 2 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 89b0c5b..67913de 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map'
 	Show only CPUs with activity. Helps visualizing on high core
 	count systems.
 
+--color-pids::
+	Highlight the given pids.
+
 SEE ALSO
 --------
 linkperf:perf-record[1]
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 9ef2897..b5361a1d 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -11,6 +11,7 @@
 #include "util/session.h"
 #include "util/tool.h"
 #include "util/cloexec.h"
+#include "util/thread_map.h"
 #include "util/color.h"
 
 #include <subcmd/parse-options.h>
@@ -123,10 +124,14 @@ struct trace_sched_handler {
 				  struct machine *machine);
 };
 
+#define COLOR_PIDS PERF_COLOR_BLUE
+
 struct perf_sched_map {
 	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
 	int			*comp_cpus;
 	bool			 comp;
+	struct thread_map	*color_pids;
+	const char		*color_pids_str;
 };
 
 struct perf_sched {
@@ -1347,6 +1352,38 @@ static int process_sched_wakeup_event(struct perf_tool *tool,
 	return 0;
 }
 
+union map_priv {
+	void	*ptr;
+	bool	 color;
+};
+
+static bool thread__has_color(struct thread *thread)
+{
+	union map_priv priv = {
+		.ptr = thread__priv(thread),
+	};
+
+	return priv.color;
+}
+
+static struct thread*
+map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid, pid_t tid)
+{
+	struct thread *thread = machine__findnew_thread(machine, pid, tid);
+	union map_priv priv = {
+		.color = false,
+	};
+
+	if (!sched->map.color_pids || !thread || thread__priv(thread))
+		return thread;
+
+	if (thread_map__has(sched->map.color_pids, tid))
+		priv.color = true;
+
+	thread__set_priv(thread, priv.ptr);
+	return thread;
+}
+
 static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			    struct perf_sample *sample, struct machine *machine)
 {
@@ -1386,7 +1423,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		return -1;
 	}
 
-	sched_in = machine__findnew_thread(machine, -1, next_pid);
+	sched_in = map__findnew_thread(sched, machine, -1, next_pid);
 	if (sched_in == NULL)
 		return -1;
 
@@ -1422,6 +1459,11 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 
 	for (i = 0; i < cpus_nr; i++) {
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
+		struct thread *curr_thread = sched->curr_thread[cpu];
+		const char *pid_color = color;
+
+		if (curr_thread && thread__has_color(curr_thread))
+			pid_color = COLOR_PIDS;
 
 		if (cpu != this_cpu)
 			color_fprintf(stdout, color, " ");
@@ -1429,14 +1471,19 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			color_fprintf(stdout, color, "*");
 
 		if (sched->curr_thread[cpu])
-			color_fprintf(stdout, color, "%2s ", sched->curr_thread[cpu]->shortname);
+			color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname);
 		else
 			color_fprintf(stdout, color, "   ");
 	}
 
 	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
-		color_fprintf(stdout, color, "%s => %s:%d",
+		const char *pid_color = color;
+
+		if (thread__has_color(sched_in))
+			pid_color = COLOR_PIDS;
+
+		color_fprintf(stdout, pid_color, "%s => %s:%d",
 		       sched_in->shortname, thread__comm_str(sched_in), sched_in->tid);
 	}
 
@@ -1712,11 +1759,31 @@ static int setup_map_cpus(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_color_pids(struct perf_sched *sched)
+{
+	struct thread_map *map;
+
+	if (!sched->map.color_pids_str)
+		return 0;
+
+	map = thread_map__new_by_tid_str(sched->map.color_pids_str);
+	if (!map) {
+		pr_err("failed to get thread map from %s\n", sched->map.color_pids_str);
+		return -1;
+	}
+
+	sched->map.color_pids = map;
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
 	if (setup_map_cpus(sched))
 		return -1;
 
+	if (setup_color_pids(sched))
+		return -1;
+
 	setup_pager();
 	if (perf_sched__read_events(sched))
 		return -1;
@@ -1872,6 +1939,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 	const struct option map_options[] = {
 	OPT_BOOLEAN(0, "compact", &sched.map.comp,
 		    "map output in compact mode"),
+	OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids",
+		   "highlight given pids in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {
@@ -1935,7 +2004,7 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		return perf_sched__lat(&sched);
 	} else if (!strcmp(argv[0], "map")) {
 		if (argc) {
-			argc = parse_options(argc, argv, map_options, replay_usage, 0);
+			argc = parse_options(argc, argv, map_options, map_usage, 0);
 			if (argc)
 				usage_with_options(map_usage, map_options);
 		}

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf sched map: Color given cpus
  2016-04-12 13:29 ` [PATCH 7/8] perf tools sched: Collor given cpus Jiri Olsa
@ 2016-04-14  5:45   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:45 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: a.p.zijlstra, dsahern, acme, tglx, jolsa, mingo, hpa, namhyung,
	linux-kernel

Commit-ID:  cf294f24f8c83bca6aa8e96b5cc4f78bed887f92
Gitweb:     http://git.kernel.org/tip/cf294f24f8c83bca6aa8e96b5cc4f78bed887f92
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:30 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:51 -0300

perf sched map: Color given cpus

Adding --color-cpus option to display selected cpus with background
color (red by default).  It helps on navigating through the perf sched
map output.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-8-git-send-email-jolsa@kernel.org
[ Added entry to man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  3 +++
 tools/perf/builtin-sched.c              | 36 ++++++++++++++++++++++++++++++---
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 67913de..58bff6c 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map'
 	Show only CPUs with activity. Helps visualizing on high core
 	count systems.
 
+--color-cpus::
+	Highlight the given cpus.
+
 --color-pids::
 	Highlight the given pids.
 
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index b5361a1d..7de04b2 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -125,6 +125,7 @@ struct trace_sched_handler {
 };
 
 #define COLOR_PIDS PERF_COLOR_BLUE
+#define COLOR_CPUS PERF_COLOR_BG_RED
 
 struct perf_sched_map {
 	DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
@@ -132,6 +133,8 @@ struct perf_sched_map {
 	bool			 comp;
 	struct thread_map	*color_pids;
 	const char		*color_pids_str;
+	struct cpu_map		*color_cpus;
+	const char		*color_cpus_str;
 };
 
 struct perf_sched {
@@ -1461,14 +1464,18 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		int cpu = sched->map.comp ? sched->map.comp_cpus[i] : i;
 		struct thread *curr_thread = sched->curr_thread[cpu];
 		const char *pid_color = color;
+		const char *cpu_color = color;
 
 		if (curr_thread && thread__has_color(curr_thread))
 			pid_color = COLOR_PIDS;
 
+		if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu))
+			cpu_color = COLOR_CPUS;
+
 		if (cpu != this_cpu)
-			color_fprintf(stdout, color, " ");
+			color_fprintf(stdout, cpu_color, " ");
 		else
-			color_fprintf(stdout, color, "*");
+			color_fprintf(stdout, cpu_color, "*");
 
 		if (sched->curr_thread[cpu])
 			color_fprintf(stdout, pid_color, "%2s ", sched->curr_thread[cpu]->shortname);
@@ -1753,7 +1760,8 @@ static int setup_map_cpus(struct perf_sched *sched)
 
 	if (sched->map.comp) {
 		sched->map.comp_cpus = zalloc(sched->max_cpu * sizeof(int));
-		return sched->map.comp_cpus ? 0 : -1;
+		if (!sched->map.comp_cpus)
+			return -1;
 	}
 
 	return 0;
@@ -1776,6 +1784,23 @@ static int setup_color_pids(struct perf_sched *sched)
 	return 0;
 }
 
+static int setup_color_cpus(struct perf_sched *sched)
+{
+	struct cpu_map *map;
+
+	if (!sched->map.color_cpus_str)
+		return 0;
+
+	map = cpu_map__new(sched->map.color_cpus_str);
+	if (!map) {
+		pr_err("failed to get thread map from %s\n", sched->map.color_cpus_str);
+		return -1;
+	}
+
+	sched->map.color_cpus = map;
+	return 0;
+}
+
 static int perf_sched__map(struct perf_sched *sched)
 {
 	if (setup_map_cpus(sched))
@@ -1784,6 +1809,9 @@ static int perf_sched__map(struct perf_sched *sched)
 	if (setup_color_pids(sched))
 		return -1;
 
+	if (setup_color_cpus(sched))
+		return -1;
+
 	setup_pager();
 	if (perf_sched__read_events(sched))
 		return -1;
@@ -1941,6 +1969,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		    "map output in compact mode"),
 	OPT_STRING(0, "color-pids", &sched.map.color_pids_str, "pids",
 		   "highlight given pids in map"),
+	OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus",
+                    "highlight given CPUs in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {

^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [tip:perf/core] perf sched map: Display only given cpus
  2016-04-12 13:29 ` [PATCH 8/8] perf tools sched: Display only " Jiri Olsa
@ 2016-04-14  5:46   ` tip-bot for Jiri Olsa
  0 siblings, 0 replies; 20+ messages in thread
From: tip-bot for Jiri Olsa @ 2016-04-14  5:46 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: jolsa, linux-kernel, a.p.zijlstra, tglx, hpa, dsahern, namhyung,
	acme, mingo

Commit-ID:  73643bb6a21c85509c7ae4c316f502c5a19cce65
Gitweb:     http://git.kernel.org/tip/73643bb6a21c85509c7ae4c316f502c5a19cce65
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Tue, 12 Apr 2016 15:29:31 +0200
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 13 Apr 2016 10:11:52 -0300

perf sched map: Display only given cpus

Introducing --cpus option that will display only given cpus. Could be
used together with color-cpus option.

  $ perf sched map  --cpus 0,1
        *A0   309999.786924 secs A0 => rcu_sched:7
        *.    309999.786930 secs
    *B0  .    309999.786931 secs B0 => rcuos/2:25
     B0 *A0   309999.786947 secs

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1460467771-26532-9-git-send-email-jolsa@kernel.org
[ Added entry to man page ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/Documentation/perf-sched.txt |  3 +++
 tools/perf/builtin-sched.c              | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/tools/perf/Documentation/perf-sched.txt b/tools/perf/Documentation/perf-sched.txt
index 58bff6c..1cc08cc 100644
--- a/tools/perf/Documentation/perf-sched.txt
+++ b/tools/perf/Documentation/perf-sched.txt
@@ -57,6 +57,9 @@ OPTIONS for 'perf sched map'
 	Show only CPUs with activity. Helps visualizing on high core
 	count systems.
 
+--cpus::
+	Show just entries with activities for the given CPUs.
+
 --color-cpus::
 	Highlight the given cpus.
 
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 7de04b2..afa0576 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -135,6 +135,8 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct cpu_map		*color_cpus;
 	const char		*color_cpus_str;
+	struct cpu_map		*cpus;
+	const char		*cpus_str;
 };
 
 struct perf_sched {
@@ -1469,6 +1471,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 		if (curr_thread && thread__has_color(curr_thread))
 			pid_color = COLOR_PIDS;
 
+		if (sched->map.cpus && !cpu_map__has(sched->map.cpus, cpu))
+			continue;
+
 		if (sched->map.color_cpus && cpu_map__has(sched->map.color_cpus, cpu))
 			cpu_color = COLOR_CPUS;
 
@@ -1483,6 +1488,9 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 			color_fprintf(stdout, color, "   ");
 	}
 
+	if (sched->map.cpus && !cpu_map__has(sched->map.cpus, this_cpu))
+		goto out;
+
 	color_fprintf(stdout, color, "  %12.6f secs ", (double)timestamp/1e9);
 	if (new_shortname) {
 		const char *pid_color = color;
@@ -1497,6 +1505,7 @@ static int map_switch_event(struct perf_sched *sched, struct perf_evsel *evsel,
 	if (sched->map.comp && new_cpu)
 		color_fprintf(stdout, color, " (CPU %d)", this_cpu);
 
+out:
 	color_fprintf(stdout, color, "\n");
 
 	thread__put(sched_in);
@@ -1756,6 +1765,8 @@ static int perf_sched__lat(struct perf_sched *sched)
 
 static int setup_map_cpus(struct perf_sched *sched)
 {
+	struct cpu_map *map;
+
 	sched->max_cpu  = sysconf(_SC_NPROCESSORS_CONF);
 
 	if (sched->map.comp) {
@@ -1764,6 +1775,16 @@ static int setup_map_cpus(struct perf_sched *sched)
 			return -1;
 	}
 
+	if (!sched->map.cpus_str)
+		return 0;
+
+	map = cpu_map__new(sched->map.cpus_str);
+	if (!map) {
+		pr_err("failed to get cpus map from %s\n", sched->map.cpus_str);
+		return -1;
+	}
+
+	sched->map.cpus = map;
 	return 0;
 }
 
@@ -1971,6 +1992,8 @@ int cmd_sched(int argc, const char **argv, const char *prefix __maybe_unused)
 		   "highlight given pids in map"),
 	OPT_STRING(0, "color-cpus", &sched.map.color_cpus_str, "cpus",
                     "highlight given CPUs in map"),
+	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
+                    "display given CPUs in map"),
 	OPT_END()
 	};
 	const char * const latency_usage[] = {

^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2016-04-14  5:46 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-12 13:29 [PATCH 0/8] perf tools: Add sched map changes Jiri Olsa
2016-04-12 13:29 ` [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa
2016-04-14  5:43   ` [tip:perf/core] perf thread_map: Add has() method tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 2/8] perf tools: Add cpu_map__has function Jiri Olsa
2016-04-14  5:43   ` [tip:perf/core] perf cpu_map: Add has() method tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa
2016-04-12 14:09   ` Arnaldo Carvalho de Melo
2016-04-12 14:18     ` Arnaldo Carvalho de Melo
2016-04-14  5:44   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 4/8] perf tools sched: Use color_fprintf for output Jiri Olsa
2016-04-14  5:44   ` [tip:perf/core] perf " tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global Jiri Olsa
2016-04-14  5:44   ` [tip:perf/core] perf thread_map: Make new_by_tid_str constructor public tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 6/8] perf tools sched: Collor given pids Jiri Olsa
2016-04-14  5:45   ` [tip:perf/core] perf sched map: Color " tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 7/8] perf tools sched: Collor given cpus Jiri Olsa
2016-04-14  5:45   ` [tip:perf/core] perf sched map: Color " tip-bot for Jiri Olsa
2016-04-12 13:29 ` [PATCH 8/8] perf tools sched: Display only " Jiri Olsa
2016-04-14  5:46   ` [tip:perf/core] perf sched map: " tip-bot for Jiri Olsa
2016-04-12 14:38 ` [PATCH 0/8] perf tools: Add sched map changes Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).