Commit 9cc0afed authored by Madadi Vineeth Reddy's avatar Madadi Vineeth Reddy Committed by Namhyung Kim

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: default avatarNamhyung Kim <namhyung@kernel.org>
Reviewed-and-tested-by: default avatarAthira Rajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: default avatarMadadi Vineeth Reddy <vineethr@linux.ibm.com>
Cc: Chen Yu <yu.c.chen@intel.com>
Link: https://lore.kernel.org/r/20240707182716.22054-3-vineethr@linux.ibm.comSigned-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
parent 3116d609
...@@ -131,9 +131,10 @@ OPTIONS for 'perf sched map' ...@@ -131,9 +131,10 @@ OPTIONS for 'perf sched map'
Highlight the given pids. Highlight the given pids.
--task-name <task>:: --task-name <task>::
Map output only for the given task name. The sched-out Map output only for the given task name(s). Separate the
task names with a comma (without whitespace). The sched-out
time is printed and is represented by '*-' for the given time is printed and is represented by '*-' for the given
task name task name(s).
('-' indicates other tasks while '.' is idle). ('-' indicates other tasks while '.' is idle).
OPTIONS for 'perf sched timehist' OPTIONS for 'perf sched timehist'
......
...@@ -157,6 +157,7 @@ struct perf_sched_map { ...@@ -157,6 +157,7 @@ struct perf_sched_map {
struct perf_cpu_map *color_cpus; struct perf_cpu_map *color_cpus;
const char *color_cpus_str; const char *color_cpus_str;
const char *task_name; const char *task_name;
struct strlist *task_names;
struct perf_cpu_map *cpus; struct perf_cpu_map *cpus;
const char *cpus_str; const char *cpus_str;
}; };
...@@ -1540,6 +1541,18 @@ map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid ...@@ -1540,6 +1541,18 @@ map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid
return thread; return thread;
} }
static bool sched_match_task(const char *comm_str, struct strlist *task_names)
{
struct str_node *node;
strlist__for_each_entry(node, task_names) {
if (strcmp(comm_str, node->s) == 0)
return true;
}
return false;
}
static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, int cpus_nr, static void print_sched_map(struct perf_sched *sched, struct perf_cpu this_cpu, int cpus_nr,
const char *color, bool sched_out) const char *color, bool sched_out)
{ {
...@@ -1609,6 +1622,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, ...@@ -1609,6 +1622,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
const char *color = PERF_COLOR_NORMAL; const char *color = PERF_COLOR_NORMAL;
char stimestamp[32]; char stimestamp[32];
const char *str; const char *str;
struct strlist *task_names = sched->map.task_names;
BUG_ON(this_cpu.cpu >= MAX_CPUS || this_cpu.cpu < 0); BUG_ON(this_cpu.cpu >= MAX_CPUS || this_cpu.cpu < 0);
...@@ -1660,7 +1674,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, ...@@ -1660,7 +1674,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
*/ */
tr->shortname[0] = '.'; tr->shortname[0] = '.';
tr->shortname[1] = ' '; tr->shortname[1] = ' ';
} else if (!sched->map.task_name || !strcmp(str, sched->map.task_name)) { } else if (!sched->map.task_name || sched_match_task(str, task_names)) {
tr->shortname[0] = sched->next_shortname1; tr->shortname[0] = sched->next_shortname1;
tr->shortname[1] = sched->next_shortname2; tr->shortname[1] = sched->next_shortname2;
...@@ -1689,15 +1703,15 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel, ...@@ -1689,15 +1703,15 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
* Check which of sched_in and sched_out matches the passed --task-name * Check which of sched_in and sched_out matches the passed --task-name
* arguments and call the corresponding print_sched_map. * arguments and call the corresponding print_sched_map.
*/ */
if (sched->map.task_name && strcmp(str, sched->map.task_name)) { if (sched->map.task_name && !sched_match_task(str, task_names)) {
if (strcmp(thread__comm_str(sched_out), sched->map.task_name)) if (!sched_match_task(thread__comm_str(sched_out), task_names))
goto out; goto out;
else else
goto sched_out; goto sched_out;
} else { } else {
str = thread__comm_str(sched_out); str = thread__comm_str(sched_out);
if (!(sched->map.task_name && strcmp(str, sched->map.task_name))) if (!(sched->map.task_name && !sched_match_task(str, task_names)))
proceed = 1; proceed = 1;
} }
...@@ -3640,7 +3654,7 @@ int cmd_sched(int argc, const char **argv) ...@@ -3640,7 +3654,7 @@ int cmd_sched(int argc, const char **argv)
OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus", OPT_STRING(0, "cpus", &sched.map.cpus_str, "cpus",
"display given CPUs in map"), "display given CPUs in map"),
OPT_STRING(0, "task-name", &sched.map.task_name, "task", OPT_STRING(0, "task-name", &sched.map.task_name, "task",
"map output only for the given task name"), "map output only for the given task name(s)."),
OPT_PARENT(sched_options) OPT_PARENT(sched_options)
}; };
const struct option timehist_options[] = { const struct option timehist_options[] = {
...@@ -3739,6 +3753,14 @@ int cmd_sched(int argc, const char **argv) ...@@ -3739,6 +3753,14 @@ int cmd_sched(int argc, const char **argv)
argc = parse_options(argc, argv, map_options, map_usage, 0); argc = parse_options(argc, argv, map_options, map_usage, 0);
if (argc) if (argc)
usage_with_options(map_usage, map_options); usage_with_options(map_usage, map_options);
if (sched.map.task_name) {
sched.map.task_names = strlist__new(sched.map.task_name, NULL);
if (sched.map.task_names == NULL) {
fprintf(stderr, "Failed to parse task names\n");
return -1;
}
}
} }
sched.tp_handler = &map_ops; sched.tp_handler = &map_ops;
setup_sorting(&sched, latency_options, latency_usage); setup_sorting(&sched, latency_options, latency_usage);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment