Skip to contentSkip to conversation

perf sched map: Add command-name option to filter the output map

PATCH Superseded Madadi Vineeth Reddy 4 participants 7 messages Apr 17, 2024 – Jun 7, 2024 perf events

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf sched map: Add command-name option to filter the output map

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +4 -0
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +14 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 			tr->shortname[0] = sched->next_shortname1;
 			tr->shortname[1] = sched->next_shortname2;
 
@@ -1618,10 +1618,18 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 				else
 					sched->next_shortname2 = '0';
 			}
+		} else {
+			tr->shortname[0] = '*';
+			tr->shortname[1] = '*';
 		}
 		new_shortname = 1;
 	}
 
+	if (sched->map.command && strcmp(thread__comm_str(sched_in), sched->map.command))
+		goto skip;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1678,6 +1686,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 out:
 	color_fprintf(stdout, color, "\n");
 
+skip:
 	thread__put(sched_in);
 
 	return 0;
@@ -3560,6 +3569,8 @@ int cmd_sched(int argc, const char **argv)
                     "highlight given CPUs in map"),
 	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
                     "display given CPUs in map"),
+	OPT_STRING(0, "command-name", &sched.map.command, "command",
+		"map output only for the given command name"),
 	OPT_PARENT(sched_options)
 	};
 	const struct option timehist_options[] = {
Signature · 1 line
2.39.1
#1 lore raw
Quoted 119 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +4 -0
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +12 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 			tr->shortname[0] = sched->next_shortname1;
 			tr->shortname[1] = sched->next_shortname2;
 
@@ -1618,10 +1618,18 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 				else
 					sched->next_shortname2 = '0';
 			}
+		} else {
+			tr->shortname[0] = '*';
+			tr->shortname[1] = '*';
 		}
 		new_shortname = 1;
 	}
 
+	if (sched->map.command && strcmp(thread__comm_str(sched_in), sched->map.command))
+		goto skip;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1678,6 +1686,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 out:
 	color_fprintf(stdout, color, "\n");
 
+skip:
 	thread__put(sched_in);
 
 	return 0;

tools/perf/builtin-sched.c int cmd_sched(int argc, const char **argv) · line 3576

Quoted 8 lines
tools/perf/builtin-sched.c +2 -0
@@ -3560,6 +3569,8 @@ int cmd_sched(int argc, const char **argv)
                     "highlight given CPUs in map"),
 	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
                     "display given CPUs in map"),
+	OPT_STRING(0, "command-name", &sched.map.command, "command",
+		"map output only for the given command name"),
 	OPT_PARENT(sched_options)
 	};
 	const struct option timehist_options[] = {

Ping.

Hi all, any comments on this patch?

Thanks and Regards
Madadi Vineeth Reddy

#2 lore raw
In reply to Madadi Vineeth Reddy
Quoted 39 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

 *A0                   213864.670142 secs A0 => migration/0:18
 *.                    213864.670148 secs .  => swapper:0
  .  *B0               213864.670217 secs B0 => migration/1:21
  .  *.                213864.670223 secs
  .   .  *C0           213864.670247 secs C0 => migration/2:26
  .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

  **  .   ** *A0       213864.671055 secs A0 => schbench:104834
 *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
 *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
 *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
 *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
  E0  .  *D0  A0
Quoted 5 lines

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

Tested the patch and looks good to me

Command to record: perf sched record sleep 5

With the patch, tested below and checked it filters and provides results for “sleep” and “perf”

perf sched map --command-name sleep
perf sched map --command-name perf

Reviewed-and-tested-by Athira Rajeev <[email protected] <mailto:[email protected]>>

Thanks
Athira

Quoted 91 lines

---
tools/perf/Documentation/perf-sched.txt | 4 ++++
tools/perf/builtin-sched.c | 17 ++++++++++++++---

2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +0 -1
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
--color-pids::

Highlight the given pids.

+--command-name::
+ Map output only for the given command name.
+ (** indicates other tasks while . is idle).
+
OPTIONS for 'perf sched timehist'
---------------------------------

tools/perf/Documentation/perf-sched.txt +0 -1
-k::
tools/perf/builtin-sched.c +3 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 const char *color_pids_str;
 struct perf_cpu_map *color_cpus;
 const char *color_cpus_str;
+ const char *command;
 struct perf_cpu_map *cpus;
 const char *cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
- printf("  ");
-
 new_shortname = 0;
 if (!tr->shortname[0]) {
 if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 */
 tr->shortname[0] = '.';
 tr->shortname[1] = ' ';
- } else {
+ } else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+ sched->map.command)) {
 tr->shortname[0] = sched->next_shortname1;
 tr->shortname[1] = sched->next_shortname2;
 
@@ -1618,10 +1618,18 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,

else
sched->next_shortname2 = '0';
}
+ } else {
+ tr->shortname[0] = '*';
+ tr->shortname[1] = '*';
}
new_shortname = 1;
}

+ if (sched->map.command && strcmp(thread__comm_str(sched_in), sched->map.command))
+ goto skip;

tools/perf/builtin-sched.c +3 -0
+
+ printf("  ");
+

for (i = 0; i < cpus_nr; i++) {
struct perf_cpu cpu = {
.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,

tools/perf/builtin-sched.c +0 -0
@@ -1678,6 +1686,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,

out:
color_fprintf(stdout, color, "\n");

+skip:
thread__put(sched_in);

return 0;

tools/perf/builtin-sched.c +2 -0
@@ -3560,6 +3569,8 @@ int cmd_sched(int argc, const char **argv)
                    "highlight given CPUs in map"),
 OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
                    "display given CPUs in map"),
+ OPT_STRING(0, "command-name", &sched.map.command, "command",
+ "map output only for the given command name"),
 OPT_PARENT(sched_options)
 };
 const struct option timehist_options[] = {
Signature · 1 line
2.39.1
maintainer
#3 lore raw
In reply to Madadi Vineeth Reddy

Hello,

Sorry for the late reply.

Quoted 35 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0
Quoted 3 lines

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

Yeah I think this is good! Thanks for working on this.

But I guess people want to see when the tasks were sched out as well. Can you please add that too?

Quoted 12 lines
---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +0 -0
index 5fbe42bd599b..b04a37560935 100644

tools/perf/Documentation/perf-sched.txt OPTIONS for 'perf sched map' · line 99

Quoted 6 lines
tools/perf/Documentation/perf-sched.txt +3 -0
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).

Probably we can support multiple names in CSV.

Thanks,
Namhyung

Quoted 74 lines
tools/perf/Documentation/perf-sched.txt +1 -0
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +14 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 			tr->shortname[0] = sched->next_shortname1;
 			tr->shortname[1] = sched->next_shortname2;
 
@@ -1618,10 +1618,18 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 				else
 					sched->next_shortname2 = '0';
 			}
+		} else {
+			tr->shortname[0] = '*';
+			tr->shortname[1] = '*';
 		}
 		new_shortname = 1;
 	}
 
+	if (sched->map.command && strcmp(thread__comm_str(sched_in), sched->map.command))
+		goto skip;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1678,6 +1686,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 out:
 	color_fprintf(stdout, color, "\n");
 
+skip:
 	thread__put(sched_in);
 
 	return 0;
@@ -3560,6 +3569,8 @@ int cmd_sched(int argc, const char **argv)
                     "highlight given CPUs in map"),
 	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
                     "display given CPUs in map"),
+	OPT_STRING(0, "command-name", &sched.map.command, "command",
+		"map output only for the given command name"),
 	OPT_PARENT(sched_options)
 	};
 	const struct option timehist_options[] = {
Signature · 1 line
2.39.1
#4 lore raw

Hi Namhyung,

Quoted 40 lines · Namhyung Kim

Hello,

Sorry for the late reply.

Quoted 35 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0
Quoted 9 lines
Quoted 3 lines

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

Yeah I think this is good! Thanks for working on this.

But I guess people want to see when the tasks were sched out as well. Can you please add that too?

In the current implementation, we will know when a task is scheduled out implicitly.

For instance, from the above example,

 **  .   ** *A0       213864.671055 secs A0 => schbench:104834
*B0  .   .   A0       213864.671156 secs B0 => schbench:104835
*C0  .   .   A0       213864.671187 secs C0 => schbench:104836

In CPU0 (first column), the sched-in of C0 in last line indicates that B0 is scheduled out. Similarly down the line if A0 is scheduled out, we will know it by some other task being scheduled-in.

I hope this is fine. Let me know if you have any ideas or suggestions.

Quoted 15 lines
Quoted 15 lines
---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +0 -0
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
Quoted 6 lines

tools/perf/Documentation/perf-sched.txt OPTIONS for 'perf sched map' · line 99

Quoted 3 lines
tools/perf/Documentation/perf-sched.txt +3 -0
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).

Probably we can support multiple names in CSV.

Yes, that's a good idea. I will implement it in v2. Thank you for taking a look.

Thanks and Regards
Madadi Vineeth Reddy

Quoted 78 lines

Thanks,
Namhyung

Quoted 74 lines
tools/perf/Documentation/perf-sched.txt +1 -0
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +14 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 			tr->shortname[0] = sched->next_shortname1;
 			tr->shortname[1] = sched->next_shortname2;
 
@@ -1618,10 +1618,18 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 				else
 					sched->next_shortname2 = '0';
 			}
+		} else {
+			tr->shortname[0] = '*';
+			tr->shortname[1] = '*';
 		}
 		new_shortname = 1;
 	}
 
+	if (sched->map.command && strcmp(thread__comm_str(sched_in), sched->map.command))
+		goto skip;
+
+	printf("  ");
+
 	for (i = 0; i < cpus_nr; i++) {
 		struct perf_cpu cpu = {
 			.cpu = sched->map.comp ? sched->map.comp_cpus[i].cpu : i,
@@ -1678,6 +1686,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 out:
 	color_fprintf(stdout, color, "\n");
 
+skip:
 	thread__put(sched_in);
 
 	return 0;
@@ -3560,6 +3569,8 @@ int cmd_sched(int argc, const char **argv)
                     "highlight given CPUs in map"),
 	OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
                     "display given CPUs in map"),
+	OPT_STRING(0, "command-name", &sched.map.command, "command",
+		"map output only for the given command name"),
 	OPT_PARENT(sched_options)
 	};
 	const struct option timehist_options[] = {
Signature · 1 line
2.39.1
#5 lore raw
In reply to Madadi Vineeth Reddy
Quoted 82 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +4 -0
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +1 -2
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {

tools/perf/builtin-sched.c static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, · line 1609

Quoted 7 lines
tools/perf/builtin-sched.c +2 -1
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 

I've tested on my machine and it looks good. One minor question, can we do fuzzy name matching? Say, there are many tasks 'a-taskname-b', and we can filter them via
perf sched map --command-name=taskname

thanks,
Chenyu

#6 lore raw

Hi Chen Yu,

Quoted 87 lines · Chen Yu
Quoted 86 lines · Madadi Vineeth Reddy

By default, perf sched map prints sched-in events for all the tasks which may not be required all the time as it prints lot of symbols and rows to the terminal.

With --command-name option, one could specify the specific command for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command. Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

For other tasks, instead of printing the symbol, ** is printed and the same . is used to represent idle. ** is used instead of symbol for other tasks because it helps in clear visualization of command of interest and secondly the symbol itself doesn't mean anything because the sched-in of that symbol will not be printed(first sched-in contains pid and the corresponding symbol).

6.8.0
======

  *A0                   213864.670142 secs A0 => migration/0:18
  *.                    213864.670148 secs .  => swapper:0
   .  *B0               213864.670217 secs B0 => migration/1:21
   .  *.                213864.670223 secs
   .   .  *C0           213864.670247 secs C0 => migration/2:26
   .   .  *.            213864.670252 secs

6.8.0 + patch (--command-name = schbench)
=============

   **  .   ** *A0       213864.671055 secs A0 => schbench:104834
  *B0  .   .   A0       213864.671156 secs B0 => schbench:104835
  *C0  .   .   A0       213864.671187 secs C0 => schbench:104836
  *D0  .   .   A0       213864.671219 secs D0 => schbench:104837
  *E0  .   .   A0       213864.671250 secs E0 => schbench:104838
   E0  .  *D0  A0

This helps in visualizing how a benchmark like schbench is spread over the available cpus while also knowing which cpus are idle(.) and which are not(**). This will be more useful as number of CPUs increase.

---
 tools/perf/Documentation/perf-sched.txt |  4 ++++
 tools/perf/builtin-sched.c              | 17 ++++++++++++++---
 2 files changed, 18 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-sched.txt +4 -0
index 5fbe42bd599b..b04a37560935 100644
@@ -94,6 +94,10 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name.
+	(** indicates other tasks while . is idle).
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +1 -3
index 0fce7d8986c0..e60836da53e5 100644
@@ -156,6 +156,7 @@ struct perf_sched_map {
 	const char		*color_pids_str;
 	struct perf_cpu_map	*color_cpus;
 	const char		*color_cpus_str;
+	const char		*command;
 	struct perf_cpu_map	*cpus;
 	const char		*cpus_str;
 };
@@ -1594,8 +1595,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 
 	sched->curr_thread[this_cpu.cpu] = thread__get(sched_in);
 
-	printf("  ");
-
 	new_shortname = 0;
 	if (!tr->shortname[0]) {
 		if (!strcmp(thread__comm_str(sched_in), "swapper")) {
@@ -1605,7 +1604,8 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
 			 */
 			tr->shortname[0] = '.';
 			tr->shortname[1] = ' ';
-		} else {
Quoted 8 lines

tools/perf/builtin-sched.c static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, · line 1611

Quoted 3 lines
tools/perf/builtin-sched.c +2 -0
+		} else if (!sched->map.command || !strcmp(thread__comm_str(sched_in),
+								sched->map.command)) {
 

I've tested on my machine and it looks good. One minor question, can we do fuzzy name matching? Say, there are many tasks 'a-taskname-b', and we can filter them via
perf sched map --command-name=taskname

Yes, maybe I will try to find a way to do both fuzzy name matching and exact name matching. Thanks for taking a look. I will implement it in v2.

Thanks and Regards
Madadi Vineeth Reddy

Quoted 3 lines

thanks,
Chenyu