Skip to content

Commit 9cc0afe

Browse files
vineethribmnamhyung
authored andcommitted
perf sched map: Add support for multiple task names using CSV
To track the scheduling patterns of multiple tasks simultaneously, multiple task names can be specified using a comma separator without any whitespace. Sample output for --task-name perf,wdavdaemon ============= . *A0 . . . . - . 131040.641346 secs A0 => wdavdaemon:62509 . A0 *B0 . . . - . 131040.641378 secs B0 => wdavdaemon:62274 . *- B0 . . . - . 131040.641379 secs *C0 . B0 . . . . . 131040.641572 secs C0 => wdavdaemon:62283 ... . *- . . . . . . 131041.395649 secs . . . . . . . *X2 131041.403969 secs X2 => perf:70211 . . . . . . . *- 131041.404006 secs Suggested-by: Namhyung Kim <[email protected]> Reviewed-and-tested-by: Athira Rajeev <[email protected]> Signed-off-by: Madadi Vineeth Reddy <[email protected]> Cc: Chen Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 3116d60 commit 9cc0afe

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

tools/perf/Documentation/perf-sched.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ OPTIONS for 'perf sched map'
131131
Highlight the given pids.
132132

133133
--task-name <task>::
134-
Map output only for the given task name. The sched-out
134+
Map output only for the given task name(s). Separate the
135+
task names with a comma (without whitespace). The sched-out
135136
time is printed and is represented by '*-' for the given
136-
task name
137+
task name(s).
137138
('-' indicates other tasks while '.' is idle).
138139

139140
OPTIONS for 'perf sched timehist'

tools/perf/builtin-sched.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct perf_sched_map {
157157
struct perf_cpu_map *color_cpus;
158158
const char *color_cpus_str;
159159
const char *task_name;
160+
struct strlist *task_names;
160161
struct perf_cpu_map *cpus;
161162
const char *cpus_str;
162163
};
@@ -1540,6 +1541,18 @@ map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid
15401541
return thread;
15411542
}
15421543

1544+
static bool sched_match_task(const char *comm_str, struct strlist *task_names)
1545+
{
1546+
struct str_node *node;
1547+
1548+
strlist__for_each_entry(node, task_names) {
1549+
if (strcmp(comm_str, node->s) == 0)
1550+
return true;
1551+
}
1552+
1553+
return false;
1554+
}
1555+
15431556
static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, int cpus_nr,
15441557
const char *color, bool sched_out)
15451558
{
@@ -1609,6 +1622,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
16091622
const char *color = PERF_COLOR_NORMAL;
16101623
char stimestamp[32];
16111624
const char *str;
1625+
struct strlist *task_names = sched->map.task_names;
16121626

16131627
BUG_ON(this_cpu.cpu >= MAX_CPUS || this_cpu.cpu < 0);
16141628

@@ -1660,7 +1674,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
16601674
*/
16611675
tr->shortname[0] = '.';
16621676
tr->shortname[1] = ' ';
1663-
} else if (!sched->map.task_name || !strcmp(str, sched->map.task_name)) {
1677+
} else if (!sched->map.task_name || sched_match_task(str, task_names)) {
16641678
tr->shortname[0] = sched->next_shortname1;
16651679
tr->shortname[1] = sched->next_shortname2;
16661680

@@ -1689,15 +1703,15 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
16891703
* Check which of sched_in and sched_out matches the passed --task-name
16901704
* arguments and call the corresponding print_sched_map.
16911705
*/
1692-
if (sched->map.task_name && strcmp(str, sched->map.task_name)) {
1693-
if (strcmp(thread__comm_str(sched_out), sched->map.task_name))
1706+
if (sched->map.task_name && !sched_match_task(str, task_names)) {
1707+
if (!sched_match_task(thread__comm_str(sched_out), task_names))
16941708
goto out;
16951709
else
16961710
goto sched_out;
16971711

16981712
} else {
16991713
str = thread__comm_str(sched_out);
1700-
if (!(sched->map.task_name && strcmp(str, sched->map.task_name)))
1714+
if (!(sched->map.task_name && !sched_match_task(str, task_names)))
17011715
proceed = 1;
17021716
}
17031717

@@ -3640,7 +3654,7 @@ int cmd_sched(int argc, const char **argv)
36403654
OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
36413655
"display given CPUs in map"),
36423656
OPT_STRING(0, "task-name", &sched.map.task_name, "task",
3643-
"map output only for the given task name"),
3657+
"map output only for the given task name(s)."),
36443658
OPT_PARENT(sched_options)
36453659
};
36463660
const struct option timehist_options[] = {
@@ -3739,6 +3753,14 @@ int cmd_sched(int argc, const char **argv)
37393753
argc = parse_options(argc, argv, map_options, map_usage, 0);
37403754
if (argc)
37413755
usage_with_options(map_usage, map_options);
3756+
3757+
if (sched.map.task_name) {
3758+
sched.map.task_names = strlist__new(sched.map.task_name, NULL);
3759+
if (sched.map.task_names == NULL) {
3760+
fprintf(stderr, "Failed to parse task names\n");
3761+
return -1;
3762+
}
3763+
}
37423764
}
37433765
sched.tp_handler = &map_ops;
37443766
setup_sorting(&sched, latency_options, latency_usage);

0 commit comments

Comments
 (0)