Message ID | 20230726121618.19198-4-zegao@tencent.com (mailing list archive) |
---|---|
State | Handled Elsewhere |
Headers | show |
Series | report task state in symbolic chars from sched tracepoint | expand |
On Wed, 26 Jul 2023 20:16:18 +0800 Ze Gao <zegao2021@gmail.com> wrote: > Since the sched_switch tracepoint introduces a new variable to > report sched-out task state in symbolic char, we switch to use > that instead to spare from knowing internal implementations > in kernel. This needs to be changed to check if the "prev_state_char" field exists, and if not, then it must use the old method. Same for perf. The tools must work with older kernels. -- Steve > > Signed-off-by: Ze Gao <zegao@tencent.com> > --- > plugins/plugin_sched_switch.c | 29 ++++------------------------- > 1 file changed, 4 insertions(+), 25 deletions(-) > > diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c > index 8752cae..5dbdc28 100644 > --- a/plugins/plugin_sched_switch.c > +++ b/plugins/plugin_sched_switch.c > @@ -9,27 +9,6 @@ > #include "event-parse.h" > #include "trace-seq.h" > > -static void write_state(struct trace_seq *s, int val) > -{ > - const char states[] = "SDTtZXxW"; > - int found = 0; > - int i; > - > - for (i = 0; i < (sizeof(states) - 1); i++) { > - if (!(val & (1 << i))) > - continue; > - > - if (found) > - trace_seq_putc(s, '|'); > - > - found = 1; > - trace_seq_putc(s, states[i]); > - } > - > - if (!found) > - trace_seq_putc(s, 'R'); > -} > - > static void write_and_save_comm(struct tep_format_field *field, > struct tep_record *record, > struct trace_seq *s, int pid) > @@ -97,10 +76,10 @@ static int sched_switch_handler(struct trace_seq *s, > trace_seq_printf(s, "%lld ", val); > > if (tep_get_field_val(s, event, "prev_prio", record, &val, 1) == > 0) > - trace_seq_printf(s, "[%d] ", (int) val); > + trace_seq_printf(s, "[%d] ", (short) val); > > - if (tep_get_field_val(s, event, "prev_state", record, &val, 1) > == 0) > - write_state(s, val); > + if (tep_get_field_val(s, event, "prev_state_char", record, > &val, 1) == 0) > + trace_seq_putc(s, (char) val); > > trace_seq_puts(s, " ==> "); > > @@ -115,7 +94,7 @@ static int sched_switch_handler(struct trace_seq *s, > trace_seq_printf(s, "%lld", val); > > if (tep_get_field_val(s, event, "next_prio", record, &val, 1) == > 0) > - trace_seq_printf(s, " [%d]", (int) val); > + trace_seq_printf(s, " [%d]", (short) val); > > return 0; > }
Roger that! Thanks, Ze On Mon, Jul 31, 2023 at 11:40 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Wed, 26 Jul 2023 20:16:18 +0800 > Ze Gao <zegao2021@gmail.com> wrote: > > > Since the sched_switch tracepoint introduces a new variable to > > report sched-out task state in symbolic char, we switch to use > > that instead to spare from knowing internal implementations > > in kernel. > > This needs to be changed to check if the "prev_state_char" field exists, > and if not, then it must use the old method. Same for perf. The tools must > work with older kernels. > > -- Steve > > > > > Signed-off-by: Ze Gao <zegao@tencent.com> > > --- > > plugins/plugin_sched_switch.c | 29 ++++------------------------- > > 1 file changed, 4 insertions(+), 25 deletions(-) > > > > diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c > > index 8752cae..5dbdc28 100644 > > --- a/plugins/plugin_sched_switch.c > > +++ b/plugins/plugin_sched_switch.c > > @@ -9,27 +9,6 @@ > > #include "event-parse.h" > > #include "trace-seq.h" > > > > -static void write_state(struct trace_seq *s, int val) > > -{ > > - const char states[] = "SDTtZXxW"; > > - int found = 0; > > - int i; > > - > > - for (i = 0; i < (sizeof(states) - 1); i++) { > > - if (!(val & (1 << i))) > > - continue; > > - > > - if (found) > > - trace_seq_putc(s, '|'); > > - > > - found = 1; > > - trace_seq_putc(s, states[i]); > > - } > > - > > - if (!found) > > - trace_seq_putc(s, 'R'); > > -} > > - > > static void write_and_save_comm(struct tep_format_field *field, > > struct tep_record *record, > > struct trace_seq *s, int pid) > > @@ -97,10 +76,10 @@ static int sched_switch_handler(struct trace_seq *s, > > trace_seq_printf(s, "%lld ", val); > > > > if (tep_get_field_val(s, event, "prev_prio", record, &val, 1) == > > 0) > > - trace_seq_printf(s, "[%d] ", (int) val); > > + trace_seq_printf(s, "[%d] ", (short) val); > > > > - if (tep_get_field_val(s, event, "prev_state", record, &val, 1) > > == 0) > > - write_state(s, val); > > + if (tep_get_field_val(s, event, "prev_state_char", record, > > &val, 1) == 0) > > + trace_seq_putc(s, (char) val); > > > > trace_seq_puts(s, " ==> "); > > > > @@ -115,7 +94,7 @@ static int sched_switch_handler(struct trace_seq *s, > > trace_seq_printf(s, "%lld", val); > > > > if (tep_get_field_val(s, event, "next_prio", record, &val, 1) == > > 0) > > - trace_seq_printf(s, " [%d]", (int) val); > > + trace_seq_printf(s, " [%d]", (short) val); > > > > return 0; > > } >
diff --git a/plugins/plugin_sched_switch.c b/plugins/plugin_sched_switch.c index 8752cae..5dbdc28 100644 --- a/plugins/plugin_sched_switch.c +++ b/plugins/plugin_sched_switch.c @@ -9,27 +9,6 @@ #include "event-parse.h" #include "trace-seq.h" -static void write_state(struct trace_seq *s, int val) -{ - const char states[] = "SDTtZXxW"; - int found = 0; - int i; - - for (i = 0; i < (sizeof(states) - 1); i++) { - if (!(val & (1 << i))) - continue; - - if (found) - trace_seq_putc(s, '|'); - - found = 1; - trace_seq_putc(s, states[i]); - } - - if (!found) - trace_seq_putc(s, 'R'); -} - static void write_and_save_comm(struct tep_format_field *field, struct tep_record *record, struct trace_seq *s, int pid) @@ -97,10 +76,10 @@ static int sched_switch_handler(struct trace_seq *s, trace_seq_printf(s, "%lld ", val); if (tep_get_field_val(s, event, "prev_prio", record, &val, 1) == 0) - trace_seq_printf(s, "[%d] ", (int) val); + trace_seq_printf(s, "[%d] ", (short) val); - if (tep_get_field_val(s, event, "prev_state", record, &val, 1) == 0) - write_state(s, val); + if (tep_get_field_val(s, event, "prev_state_char", record, &val, 1) == 0) + trace_seq_putc(s, (char) val); trace_seq_puts(s, " ==> "); @@ -115,7 +94,7 @@ static int sched_switch_handler(struct trace_seq *s, trace_seq_printf(s, "%lld", val); if (tep_get_field_val(s, event, "next_prio", record, &val, 1) == 0) - trace_seq_printf(s, " [%d]", (int) val); + trace_seq_printf(s, " [%d]", (short) val); return 0; }
Since the sched_switch tracepoint introduces a new variable to report sched-out task state in symbolic char, we switch to use that instead to spare from knowing internal implementations in kernel. Signed-off-by: Ze Gao <zegao@tencent.com> --- plugins/plugin_sched_switch.c | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-)