Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tools lib traceevent: Add builtin handler for trace_marker_raw

When something is written into trace_marker_raw, it goes in as a binary.
But the printk_fmt() of the event that is created (raw_data)'s format
file only prints the first byte of data:

print fmt: "id:%04x %08x", REC->id, (int)REC->buf[0]

This is not very useful if we want to see the full data output.

Implement the processing of the raw_data event like it is in the kernel.

Link: http://lore.kernel.org/linux-trace-devel/20200702174950.123454-5-tz.stoyanov@gmail.com

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
[ Ported from trace-cmd.git ]
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-trace-devel@vger.kernel.org
Link: http://lore.kernel.org/lkml/20200702185705.445969275@goodmis.org
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Steven Rostedt (VMware) and committed by
Arnaldo Carvalho de Melo
9b8179b3 0dfceeff

+41
+41
tools/lib/traceevent/plugins/plugin_function.c
··· 222 222 return 0; 223 223 } 224 224 225 + static int 226 + trace_raw_data_handler(struct trace_seq *s, struct tep_record *record, 227 + struct tep_event *event, void *context) 228 + { 229 + struct tep_format_field *field; 230 + unsigned long long id; 231 + int long_size; 232 + void *data = record->data; 233 + 234 + if (tep_get_field_val(s, event, "id", record, &id, 1)) 235 + return trace_seq_putc(s, '!'); 236 + 237 + trace_seq_printf(s, "# %llx", id); 238 + 239 + field = tep_find_any_field(event, "buf"); 240 + if (!field) { 241 + trace_seq_printf(s, "<CANT FIND FIELD %s>", "buf"); 242 + return 0; 243 + } 244 + 245 + long_size = tep_get_long_size(event->tep); 246 + 247 + for (data += field->offset; data < record->data + record->size; 248 + data += long_size) { 249 + int size = sizeof(long); 250 + int left = (record->data + record->size) - data; 251 + int i; 252 + 253 + if (size > left) 254 + size = left; 255 + 256 + for (i = 0; i < size; i++) 257 + trace_seq_printf(s, " %02x", *(unsigned char *)(data + i)); 258 + } 259 + 260 + return 0; 261 + } 262 + 225 263 int TEP_PLUGIN_LOADER(struct tep_handle *tep) 226 264 { 227 265 tep_register_event_handler(tep, -1, "ftrace", "function", ··· 267 229 268 230 tep_register_event_handler(tep, -1, "ftrace", "kernel_stack", 269 231 trace_stack_handler, NULL); 232 + 233 + tep_register_event_handler(tep, -1, "ftrace", "raw_data", 234 + trace_raw_data_handler, NULL); 270 235 271 236 tep_plugin_add_options("ftrace", plugin_options); 272 237