Commit be45d40e authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo

tools lib traceevent: Factor out and export print_event_field[s]()

The print_event_field() and print_event_fields() functions print basic
information of a given field or event without the print format.  They'll
be used by dynamic sort keys later.

Committer note:

Rename it to pevent_print_field[s]() to get proper namespacing, as
discussed with Steven Rostedt.
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Acked-by: default avatarJiri Olsa <jolsa@kernel.org>
Acked-by: default avatarSteven Rostedt <rostedt@goodmis.org>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/r/1450876121-22494-1-git-send-email-namhyung@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 72392834
...@@ -4735,73 +4735,80 @@ static int is_printable_array(char *p, unsigned int len) ...@@ -4735,73 +4735,80 @@ static int is_printable_array(char *p, unsigned int len)
return 1; return 1;
} }
static void print_event_fields(struct trace_seq *s, void *data, void pevent_print_field(struct trace_seq *s, void *data,
int size __maybe_unused, struct format_field *field)
struct event_format *event)
{ {
struct format_field *field;
unsigned long long val; unsigned long long val;
unsigned int offset, len, i; unsigned int offset, len, i;
struct pevent *pevent = field->event->pevent;
field = event->format.fields;
while (field) { if (field->flags & FIELD_IS_ARRAY) {
trace_seq_printf(s, " %s=", field->name); offset = field->offset;
if (field->flags & FIELD_IS_ARRAY) { len = field->size;
offset = field->offset; if (field->flags & FIELD_IS_DYNAMIC) {
len = field->size; val = pevent_read_number(pevent, data + offset, len);
if (field->flags & FIELD_IS_DYNAMIC) { offset = val;
val = pevent_read_number(event->pevent, data + offset, len); len = offset >> 16;
offset = val; offset &= 0xffff;
len = offset >> 16; }
offset &= 0xffff; if (field->flags & FIELD_IS_STRING &&
} is_printable_array(data + offset, len)) {
if (field->flags & FIELD_IS_STRING && trace_seq_printf(s, "%s", (char *)data + offset);
is_printable_array(data + offset, len)) {
trace_seq_printf(s, "%s", (char *)data + offset);
} else {
trace_seq_puts(s, "ARRAY[");
for (i = 0; i < len; i++) {
if (i)
trace_seq_puts(s, ", ");
trace_seq_printf(s, "%02x",
*((unsigned char *)data + offset + i));
}
trace_seq_putc(s, ']');
field->flags &= ~FIELD_IS_STRING;
}
} else { } else {
val = pevent_read_number(event->pevent, data + field->offset, trace_seq_puts(s, "ARRAY[");
field->size); for (i = 0; i < len; i++) {
if (field->flags & FIELD_IS_POINTER) { if (i)
trace_seq_printf(s, "0x%llx", val); trace_seq_puts(s, ", ");
} else if (field->flags & FIELD_IS_SIGNED) { trace_seq_printf(s, "%02x",
switch (field->size) { *((unsigned char *)data + offset + i));
case 4: }
/* trace_seq_putc(s, ']');
* If field is long then print it in hex. field->flags &= ~FIELD_IS_STRING;
* A long usually stores pointers. }
*/ } else {
if (field->flags & FIELD_IS_LONG) val = pevent_read_number(pevent, data + field->offset,
trace_seq_printf(s, "0x%x", (int)val); field->size);
else if (field->flags & FIELD_IS_POINTER) {
trace_seq_printf(s, "%d", (int)val); trace_seq_printf(s, "0x%llx", val);
break; } else if (field->flags & FIELD_IS_SIGNED) {
case 2: switch (field->size) {
trace_seq_printf(s, "%2d", (short)val); case 4:
break; /*
case 1: * If field is long then print it in hex.
trace_seq_printf(s, "%1d", (char)val); * A long usually stores pointers.
break; */
default:
trace_seq_printf(s, "%lld", val);
}
} else {
if (field->flags & FIELD_IS_LONG) if (field->flags & FIELD_IS_LONG)
trace_seq_printf(s, "0x%llx", val); trace_seq_printf(s, "0x%x", (int)val);
else else
trace_seq_printf(s, "%llu", val); trace_seq_printf(s, "%d", (int)val);
break;
case 2:
trace_seq_printf(s, "%2d", (short)val);
break;
case 1:
trace_seq_printf(s, "%1d", (char)val);
break;
default:
trace_seq_printf(s, "%lld", val);
} }
} else {
if (field->flags & FIELD_IS_LONG)
trace_seq_printf(s, "0x%llx", val);
else
trace_seq_printf(s, "%llu", val);
} }
}
}
void pevent_print_fields(struct trace_seq *s, void *data,
int size __maybe_unused, struct event_format *event)
{
struct format_field *field;
field = event->format.fields;
while (field) {
trace_seq_printf(s, " %s=", field->name);
pevent_print_field(s, data, field);
field = field->next; field = field->next;
} }
} }
...@@ -4827,7 +4834,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event ...@@ -4827,7 +4834,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
if (event->flags & EVENT_FL_FAILED) { if (event->flags & EVENT_FL_FAILED) {
trace_seq_printf(s, "[FAILED TO PARSE]"); trace_seq_printf(s, "[FAILED TO PARSE]");
print_event_fields(s, data, size, event); pevent_print_fields(s, data, size, event);
return; return;
} }
...@@ -5301,7 +5308,7 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event, ...@@ -5301,7 +5308,7 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event,
int print_pretty = 1; int print_pretty = 1;
if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW))
print_event_fields(s, record->data, record->size, event); pevent_print_fields(s, record->data, record->size, event);
else { else {
if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) if (event->handler && !(event->flags & EVENT_FL_NOHANDLE))
......
...@@ -705,6 +705,10 @@ struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *com ...@@ -705,6 +705,10 @@ struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *com
struct cmdline *next); struct cmdline *next);
int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline); int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline);
void pevent_print_field(struct trace_seq *s, void *data,
struct format_field *field);
void pevent_print_fields(struct trace_seq *s, void *data,
int size __maybe_unused, struct event_format *event);
void pevent_event_info(struct trace_seq *s, struct event_format *event, void pevent_event_info(struct trace_seq *s, struct event_format *event,
struct pevent_record *record); struct pevent_record *record);
int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment