Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1376802

[PATCH 6/8] perf tools sched: Collor given pids

From Jiri Olsa <jolsa@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 6/8] perf tools sched: Collor given pids
Date 2016-04-12 15:40 +0200
Message-ID <rn6HT-89g-3@gated-at.bofh.it> (permalink)
References <rn6ye-83Y-13@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 0/8] perf tools: Add sched map changes Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:30 +0200
  [PATCH 2/8] perf tools: Add cpu_map__has function Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:30 +0200
    [tip:perf/core] perf cpu_map: Add has() method tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 1/8] perf tools: Add thread_map__has function Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:30 +0200
    [tip:perf/core] perf thread_map: Add has() method tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 6/8] perf tools sched: Collor given pids Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    [tip:perf/core] perf sched map: Color given pids tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 7/8] perf tools sched: Collor given cpus Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    [tip:perf/core] perf sched map: Color given cpus tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 4/8] perf tools sched: Use color_fprintf for output Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    [tip:perf/core] perf sched: Use color_fprintf for output tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 8/8] perf tools sched: Display only given cpus Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    [tip:perf/core] perf sched map: Display only given cpus tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 5/8] perf tools sched: Make thread_map__new_by_tid_str global Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    [tip:perf/core] perf thread_map: Make new_by_tid_str constructor  public tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  [PATCH 3/8] perf tools sched: Add compact display option Jiri Olsa <jolsa@kernel.org> - 2016-04-12 15:40 +0200
    Re: [PATCH 3/8] perf tools sched: Add compact display option Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-12 16:20 +0200
    Re: [PATCH 3/8] perf tools sched: Add compact display option Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-12 16:20 +0200
    [tip:perf/core] perf sched: Add compact display option tip-bot for Jiri Olsa <tipbot@zytor.com> - 2016-04-14 07:50 +0200
  Re: [PATCH 0/8] perf tools: Add sched map changes Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-04-12 16:40 +0200

csiph-web