perf util: Add helpers to parse task state string from libtraceevent
authorZe Gao <zegao2021@gmail.com>
Mon, 22 Jan 2024 07:08:57 +0000 (02:08 -0500)
committerNamhyung Kim <namhyung@kernel.org>
Tue, 23 Jan 2024 07:02:08 +0000 (23:02 -0800)
commit2f29a74f1dffe463d457b11cb39421a45c82044f
treee463f3e96c159c98eebbd065e767026de25c7801
parentccc606a7d3122200c102a250d2b73c394a7c3888
perf util: Add helpers to parse task state string from libtraceevent

Perf uses a hard coded string "RSDTtXZPI" to index the sched_switch
prev_state field raw bitmask value. This works well except for when
the kernel changes this string, in which case this will break again.

Instead we add a new way to parse task state string from tracepoint
print format already recorded by perf, which eliminates the further
dependencies with this hardcode and unmaintainable macro, and this
is exactly what libtraceevent[1] does for now.

So we borrow the print flags parsing logic from libtraceevent[1].
And in get_states(), we walk the print arguments until the
__print_flags() for the target state field is found, and use that to
build the states string for future parsing.

[1]: https://lore.kernel.org/linux-trace-devel/20231224140732.7d41698d@rorschach.local.home/

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Ze Gao <zegao@tencent.com>
Link: https://lore.kernel.org/r/20240122070859.1394479-4-zegao@tencent.com
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/evsel.c