Skip to contentSkip to conversation

perf sched map: Add command-name, fuzzy-name options to filter the output map

PATCH Superseded Madadi Vineeth Reddy 2 participants 3 messages Jun 17, 2024 – Jun 18, 2024 perf events

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 perf sched map: Add command-name, fuzzy-name options 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(s) for which the map has to be shown. This would help in analyzing the CPU usage patterns easier for that specific command(s). Since multiple PID's might have the same command name, using command-name filter would be more useful for debugging.

Multiple command names can be given with a comma separator without whitespace.

The --fuzzy-name option can be used if fuzzy name matching is required. For example, "taskname" can be matched to any string that contains "taskname" as its substring.

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(s) 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).

When using the --command-name option, the sched-out time is represented by a '+'. Since not all task sched-in events are printed, the sched-out time of the relevant commands might be lost. This representation ensures that the sched-out time of the interested commands is not overlooked. The sched-out values for non-current CPUs are skipped because the sched-out symbol would be irrelevant.

6.10.0-rc1
==========

*A0                     794225.687532 secs A0 => migration/0:18
  *.                    794225.687544 secs .  => swapper:0
   .  *B0               794225.687628 secs B0 => migration/1:21
   .  *.                794225.687639 secs
   .   .  *C0           794225.687704 secs C0 => migration/2:26
   .   .  *.            794225.687715 secs
  *D0  .   .            794225.687829 secs D0 => perf-exec:332914
   D0  .   .  *.        794225.687926 secs
   D0  .   .  *E0       794225.689369 secs E0 => schbench:332916
   D0  .  *F0  E0       794225.689409 secs F0 => schbench:332917

6.10.0-rc1 + patch (--command-name perf)
=============

   ** *A0  **  **       794226.581112 secs A0 => perf:332915
      +A0               794226.581145 secs
   ** *A0  **  **       794227.582150 secs
      +A0               794227.582162 secs
   ** *A0  .   .        794228.583167 secs
      +A0               794228.583177 secs
   ** *A0  **  **       794229.634027 secs
      +A0               794229.634040 secs
   ** *A0  .   **       794230.635045 secs
      +A0               794230.635058 secs
   **  **  ** *B0       794231.204272 secs B0 => perf:332912
              +B0       794231.204352 secs

This helps in visualizing how a benchmark or a task 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.

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

---
Changes in v3:
- Print the sched-out timestamp as a row when using the --command-name option. (Namhyung Kim)
- Refactor the code.
- Rebase against perf-tools-next commit eae7044b67a6 ("perf hist: Honor symbol conf.skip_empty")
- Link to v2: https://lore.kernel.org/lkml/[email protected]/

Changes in v2:
- Add support for giving multiple command-names in CSV. (Namhyung Kim)
- Add fuzzy name matching option. (Chen Yu)
- Add Reviewed-and-tested-by tag from Athira Rajeev.
- Rebase against perf-tools-next commit d2307fd4f989 ("perf maps: Add/use
a sorted insert for fixup overlap and insert")
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

---
 tools/perf/Documentation/perf-sched.txt |  10 ++
 tools/perf/builtin-sched.c              | 205 +++++++++++++++++++-----
 2 files changed, 178 insertions(+), 37 deletions(-)
tools/perf/Documentation/perf-sched.txt +10 -0
index a216d2991b19..28637d097ddb 100644
@@ -130,6 +130,16 @@ OPTIONS for 'perf sched map'
 --color-pids::
 	Highlight the given pids.
 
+--command-name::
+	Map output only for the given command name(s). Separate the
+	command names with a comma (without whitespace). The sched-out
+	time is printed and is represented by '+' for the given command
+	name(s).
+	(** indicates other tasks while . is idle).
+
+--fuzzy-name::
+	Given command name can be partially matched (fuzzy matching).
+
 OPTIONS for 'perf sched timehist'
 ---------------------------------
 -k::
tools/perf/builtin-sched.c +168 -37

294 lines not on this page · raw message

Signature · 1 line
2.43.2
#1 lore raw

tools/perf/builtin-sched.c map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid · line 1551

Quoted 3 lines · Madadi Vineeth Reddy
tools/perf/builtin-sched.c +3 -0
+static struct CommandList *parse_commands(const char *commands)
+{
+	char *commands_copy = strdup(commands);

Should we check if commands_copy is NULL in case of allocation failure?

tools/perf/builtin-sched.c map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid · line 1564

Quoted 13 lines
tools/perf/builtin-sched.c +13 -0
+	char *token = strtok(commands_copy, ",");
+	struct CommandList *cmd_list = malloc(sizeof(struct CommandList));
+
+	if (cmd_list == NULL)
+		return NULL;
+
+	cmd_list->command_count = 0;
+	cmd_list->command_list = NULL;
+
+	while (token != NULL) {
+		cmd_list->command_list = realloc(cmd_list->command_list, sizeof(char *)
+							*(cmd_list->command_count + 1));
+		cmd_list->command_list[cmd_list->command_count] = strdup(token);

ditto.

thanks,
Chenyu

#2 lore raw

Hi Chen Yu,

Quoted 8 lines · Chen Yu

tools/perf/builtin-sched.c map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid · line 1551

Quoted 3 lines · Madadi Vineeth Reddy
tools/perf/builtin-sched.c +3 -0
+static struct CommandList *parse_commands(const char *commands)
+{
+	char *commands_copy = strdup(commands);

Should we check if commands_copy is NULL in case of allocation failure?

Thank you for the suggestion. I will fix it and send a v4.

Thanks and Regards
Madadi Vineeth Reddy

Quoted 18 lines

tools/perf/builtin-sched.c map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid · line 1564

Quoted 13 lines
tools/perf/builtin-sched.c +13 -0
+	char *token = strtok(commands_copy, ",");
+	struct CommandList *cmd_list = malloc(sizeof(struct CommandList));
+
+	if (cmd_list == NULL)
+		return NULL;
+
+	cmd_list->command_count = 0;
+	cmd_list->command_list = NULL;
+
+	while (token != NULL) {
+		cmd_list->command_list = realloc(cmd_list->command_list, sizeof(char *)
+							*(cmd_list->command_count + 1));
+		cmd_list->command_list[cmd_list->command_count] = strdup(token);

ditto.

thanks,
Chenyu