Skip to content

Commit 306f921

Browse files
vineethribmnamhyung
authored andcommitted
perf sched map: Add --fuzzy-name option for fuzzy matching in task names
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. Sample output for --task-name wdav --fuzzy-name ============= . *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 C0 . B0 . *D0 . . . 131040.641572 secs D0 => wdavdaemon:62277 C0 . B0 . D0 . *E0 . 131040.641578 secs E0 => wdavdaemon:62270 *- . B0 . D0 . E0 . 131040.641581 secs Suggested-by: Chen Yu <[email protected]> Reviewed-and-tested-by: Athira Rajeev <[email protected]> Signed-off-by: Madadi Vineeth Reddy <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Namhyung Kim <[email protected]>
1 parent 9cc0afe commit 306f921

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

tools/perf/Documentation/perf-sched.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ OPTIONS for 'perf sched map'
137137
task name(s).
138138
('-' indicates other tasks while '.' is idle).
139139

140+
--fuzzy-name::
141+
Given task name(s) can be partially matched (fuzzy matching).
142+
140143
OPTIONS for 'perf sched timehist'
141144
---------------------------------
142145
-k::

tools/perf/builtin-sched.c

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ struct perf_sched_map {
158158
const char *color_cpus_str;
159159
const char *task_name;
160160
struct strlist *task_names;
161+
bool fuzzy;
161162
struct perf_cpu_map *cpus;
162163
const char *cpus_str;
163164
};
@@ -1541,12 +1542,16 @@ map__findnew_thread(struct perf_sched *sched, struct machine *machine, pid_t pid
15411542
return thread;
15421543
}
15431544

1544-
static bool sched_match_task(const char *comm_str, struct strlist *task_names)
1545+
static bool sched_match_task(struct perf_sched *sched, const char *comm_str)
15451546
{
1547+
bool fuzzy_match = sched->map.fuzzy;
1548+
struct strlist *task_names = sched->map.task_names;
15461549
struct str_node *node;
15471550

15481551
strlist__for_each_entry(node, task_names) {
1549-
if (strcmp(comm_str, node->s) == 0)
1552+
bool match_found = fuzzy_match ? !!strstr(comm_str, node->s) :
1553+
!strcmp(comm_str, node->s);
1554+
if (match_found)
15501555
return true;
15511556
}
15521557

@@ -1622,7 +1627,6 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
16221627
const char *color = PERF_COLOR_NORMAL;
16231628
char stimestamp[32];
16241629
const char *str;
1625-
struct strlist *task_names = sched->map.task_names;
16261630

16271631
BUG_ON(this_cpu.cpu >= MAX_CPUS || this_cpu.cpu < 0);
16281632

@@ -1674,7 +1678,7 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
16741678
*/
16751679
tr->shortname[0] = '.';
16761680
tr->shortname[1] = ' ';
1677-
} else if (!sched->map.task_name || sched_match_task(str, task_names)) {
1681+
} else if (!sched->map.task_name || sched_match_task(sched, str)) {
16781682
tr->shortname[0] = sched->next_shortname1;
16791683
tr->shortname[1] = sched->next_shortname2;
16801684

@@ -1703,15 +1707,15 @@ static int map_switch_event(struct perf_sched *sched, struct evsel *evsel,
17031707
* Check which of sched_in and sched_out matches the passed --task-name
17041708
* arguments and call the corresponding print_sched_map.
17051709
*/
1706-
if (sched->map.task_name && !sched_match_task(str, task_names)) {
1707-
if (!sched_match_task(thread__comm_str(sched_out), task_names))
1710+
if (sched->map.task_name && !sched_match_task(sched, str)) {
1711+
if (!sched_match_task(sched, thread__comm_str(sched_out)))
17081712
goto out;
17091713
else
17101714
goto sched_out;
17111715

17121716
} else {
17131717
str = thread__comm_str(sched_out);
1714-
if (!(sched->map.task_name && !sched_match_task(str, task_names)))
1718+
if (!(sched->map.task_name && !sched_match_task(sched, str)))
17151719
proceed = 1;
17161720
}
17171721

@@ -3655,6 +3659,8 @@ int cmd_sched(int argc, const char **argv)
36553659
"display given CPUs in map"),
36563660
OPT_STRING(0, "task-name", &sched.map.task_name, "task",
36573661
"map output only for the given task name(s)."),
3662+
OPT_BOOLEAN(0, "fuzzy-name", &sched.map.fuzzy,
3663+
"given command name can be partially matched (fuzzy matching)"),
36583664
OPT_PARENT(sched_options)
36593665
};
36603666
const struct option timehist_options[] = {

0 commit comments

Comments
 (0)