Re: [PATCH] perf sched: parse task state from tracepoint print format

From: Ze Gao
Date: Sun Aug 13 2023 - 22:34:44 EST


On Sat, Aug 12, 2023 at 1:28 AM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Thu, 10 Aug 2023 01:50:24 -0400
> Ze Gao <zegao2021@xxxxxxxxx> wrote:
>
> > Hi Steven,
> >
> > I managed to build task state char map dynamically by parsing
> > the tracepoint print format from data recorded by perf. And
> > likewise for libtraceevent.
> >
> > FYI, I tried TEP_PRINT_INFO but no shot. It turns out TEP_PRINT_INFO
> > stills relies on libtraceevent (i.e., sched_switch_handler() in
> > plugin_sched_switch.c) and we need to parse the print format on our own.
>
> There is a way to unload plugins:
>
> tep_unload_plugins(t->plugin_list, tep);
>
> Hmm, I should add:
>
> tep_unload_plugin(tep, t->plugin_list, "plugin-name");
>
> To unload a single plugin.
>
> I it can also just override what the plugin does by calling:
>
> static int sched_switch_handler(struct trace_seq *s,
> struct tep_record *record,
> struct tep_event *event, void *context)
> {
> // do whatever you want.
> }
>
> tep_register_event_handler(tep, -1, "sched", "sched_switch",
> sched_switch_handler, NULL);
>
Yes, I chose to fix libtraceevent in a similar way, to not break
users of this plugin,
like perf script, I decided to build state char mapping dynamically
for both instead
of overriding sched_switch_handler in libtraceevent. Here is the patch: