1 // SPDX-License-Identifier: LGPL-2.1
3 * Copyright (C) 2009, 2010 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
9 #include "event-parse.h"
10 #include "trace-seq.h"
12 static void write_state(struct trace_seq
*s
, int val
)
14 const char states
[] = "SDTtZXxW";
18 for (i
= 0; i
< (sizeof(states
) - 1); i
++) {
19 if (!(val
& (1 << i
)))
23 trace_seq_putc(s
, '|');
26 trace_seq_putc(s
, states
[i
]);
30 trace_seq_putc(s
, 'R');
33 static void write_and_save_comm(struct tep_format_field
*field
,
34 struct tep_record
*record
,
35 struct trace_seq
*s
, int pid
)
40 comm
= (char *)(record
->data
+ field
->offset
);
42 trace_seq_printf(s
, "%.*s",
45 /* make sure the comm has a \0 at the end. */
46 trace_seq_terminate(s
);
47 comm
= &s
->buffer
[len
];
49 /* Help out the comm to ids. This will handle dups */
50 tep_register_comm(field
->event
->tep
, comm
, pid
);
53 static int sched_wakeup_handler(struct trace_seq
*s
,
54 struct tep_record
*record
,
55 struct tep_event
*event
, void *context
)
57 struct tep_format_field
*field
;
58 unsigned long long val
;
60 if (tep_get_field_val(s
, event
, "pid", record
, &val
, 1))
61 return trace_seq_putc(s
, '!');
63 field
= tep_find_any_field(event
, "comm");
65 write_and_save_comm(field
, record
, s
, val
);
66 trace_seq_putc(s
, ':');
68 trace_seq_printf(s
, "%lld", val
);
70 if (tep_get_field_val(s
, event
, "prio", record
, &val
, 0) == 0)
71 trace_seq_printf(s
, " [%lld]", val
);
73 if (tep_get_field_val(s
, event
, "success", record
, &val
, 1) == 0)
74 trace_seq_printf(s
, " success=%lld", val
);
76 if (tep_get_field_val(s
, event
, "target_cpu", record
, &val
, 0) == 0)
77 trace_seq_printf(s
, " CPU:%03llu", val
);
82 static int sched_switch_handler(struct trace_seq
*s
,
83 struct tep_record
*record
,
84 struct tep_event
*event
, void *context
)
86 struct tep_format_field
*field
;
87 unsigned long long val
;
89 if (tep_get_field_val(s
, event
, "prev_pid", record
, &val
, 1))
90 return trace_seq_putc(s
, '!');
92 field
= tep_find_any_field(event
, "prev_comm");
94 write_and_save_comm(field
, record
, s
, val
);
95 trace_seq_putc(s
, ':');
97 trace_seq_printf(s
, "%lld ", val
);
99 if (tep_get_field_val(s
, event
, "prev_prio", record
, &val
, 0) == 0)
100 trace_seq_printf(s
, "[%d] ", (int) val
);
102 if (tep_get_field_val(s
, event
, "prev_state", record
, &val
, 0) == 0)
105 trace_seq_puts(s
, " ==> ");
107 if (tep_get_field_val(s
, event
, "next_pid", record
, &val
, 1))
108 return trace_seq_putc(s
, '!');
110 field
= tep_find_any_field(event
, "next_comm");
112 write_and_save_comm(field
, record
, s
, val
);
113 trace_seq_putc(s
, ':');
115 trace_seq_printf(s
, "%lld", val
);
117 if (tep_get_field_val(s
, event
, "next_prio", record
, &val
, 0) == 0)
118 trace_seq_printf(s
, " [%d]", (int) val
);
123 int TEP_PLUGIN_LOADER(struct tep_handle
*tep
)
125 tep_register_event_handler(tep
, -1, "sched", "sched_switch",
126 sched_switch_handler
, NULL
);
128 tep_register_event_handler(tep
, -1, "sched", "sched_wakeup",
129 sched_wakeup_handler
, NULL
);
131 tep_register_event_handler(tep
, -1, "sched", "sched_wakeup_new",
132 sched_wakeup_handler
, NULL
);
136 void TEP_PLUGIN_UNLOADER(struct tep_handle
*tep
)
138 tep_unregister_event_handler(tep
, -1, "sched", "sched_switch",
139 sched_switch_handler
, NULL
);
141 tep_unregister_event_handler(tep
, -1, "sched", "sched_wakeup",
142 sched_wakeup_handler
, NULL
);
144 tep_unregister_event_handler(tep
, -1, "sched", "sched_wakeup_new",
145 sched_wakeup_handler
, NULL
);