diff options
| author | Namhyung Kim <namhyung@kernel.org> | 2015-12-23 08:08:41 -0500 |
|---|---|---|
| committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-01-06 18:11:11 -0500 |
| commit | be45d40efec96558c489579bbf93465e90b10abe (patch) | |
| tree | d525ab0ff5cf272ccb90028d4ca98e8877986b06 /tools/lib/traceevent | |
| parent | 723928340c9d28d92dcaff8b8fbc9100a1cf9429 (diff) | |
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: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Steven 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.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/traceevent')
| -rw-r--r-- | tools/lib/traceevent/event-parse.c | 129 | ||||
| -rw-r--r-- | tools/lib/traceevent/event-parse.h | 4 |
2 files changed, 72 insertions, 61 deletions
diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c index 68276f35e323..ea69ce35e902 100644 --- a/tools/lib/traceevent/event-parse.c +++ b/tools/lib/traceevent/event-parse.c | |||
| @@ -4735,73 +4735,80 @@ static int is_printable_array(char *p, unsigned int len) | |||
| 4735 | return 1; | 4735 | return 1; |
| 4736 | } | 4736 | } |
| 4737 | 4737 | ||
| 4738 | static void print_event_fields(struct trace_seq *s, void *data, | 4738 | void pevent_print_field(struct trace_seq *s, void *data, |
| 4739 | int size __maybe_unused, | 4739 | struct format_field *field) |
| 4740 | struct event_format *event) | ||
| 4741 | { | 4740 | { |
| 4742 | struct format_field *field; | ||
| 4743 | unsigned long long val; | 4741 | unsigned long long val; |
| 4744 | unsigned int offset, len, i; | 4742 | unsigned int offset, len, i; |
| 4745 | 4743 | struct pevent *pevent = field->event->pevent; | |
| 4746 | field = event->format.fields; | 4744 | |
| 4747 | while (field) { | 4745 | if (field->flags & FIELD_IS_ARRAY) { |
| 4748 | trace_seq_printf(s, " %s=", field->name); | 4746 | offset = field->offset; |
| 4749 | if (field->flags & FIELD_IS_ARRAY) { | 4747 | len = field->size; |
| 4750 | offset = field->offset; | 4748 | if (field->flags & FIELD_IS_DYNAMIC) { |
| 4751 | len = field->size; | 4749 | val = pevent_read_number(pevent, data + offset, len); |
| 4752 | if (field->flags & FIELD_IS_DYNAMIC) { | 4750 | offset = val; |
| 4753 | val = pevent_read_number(event->pevent, data + offset, len); | 4751 | len = offset >> 16; |
| 4754 | offset = val; | 4752 | offset &= 0xffff; |
| 4755 | len = offset >> 16; | 4753 | } |
| 4756 | offset &= 0xffff; | 4754 | if (field->flags & FIELD_IS_STRING && |
| 4757 | } | 4755 | is_printable_array(data + offset, len)) { |
| 4758 | if (field->flags & FIELD_IS_STRING && | 4756 | trace_seq_printf(s, "%s", (char *)data + offset); |
| 4759 | is_printable_array(data + offset, len)) { | ||
| 4760 | trace_seq_printf(s, "%s", (char *)data + offset); | ||
| 4761 | } else { | ||
| 4762 | trace_seq_puts(s, "ARRAY["); | ||
| 4763 | for (i = 0; i < len; i++) { | ||
| 4764 | if (i) | ||
| 4765 | trace_seq_puts(s, ", "); | ||
| 4766 | trace_seq_printf(s, "%02x", | ||
| 4767 | *((unsigned char *)data + offset + i)); | ||
| 4768 | } | ||
| 4769 | trace_seq_putc(s, ']'); | ||
| 4770 | field->flags &= ~FIELD_IS_STRING; | ||
| 4771 | } | ||
| 4772 | } else { | 4757 | } else { |
| 4773 | val = pevent_read_number(event->pevent, data + field->offset, | 4758 | trace_seq_puts(s, "ARRAY["); |
| 4774 | field->size); | 4759 | for (i = 0; i < len; i++) { |
| 4775 | if (field->flags & FIELD_IS_POINTER) { | 4760 | if (i) |
| 4776 | trace_seq_printf(s, "0x%llx", val); | 4761 | trace_seq_puts(s, ", "); |
| 4777 | } else if (field->flags & FIELD_IS_SIGNED) { | 4762 | trace_seq_printf(s, "%02x", |
| 4778 | switch (field->size) { | 4763 | *((unsigned char *)data + offset + i)); |
| 4779 | case 4: | 4764 | } |
| 4780 | /* | 4765 | trace_seq_putc(s, ']'); |
| 4781 | * If field is long then print it in hex. | 4766 | field->flags &= ~FIELD_IS_STRING; |
| 4782 | * A long usually stores pointers. | 4767 | } |
| 4783 | */ | 4768 | } else { |
| 4784 | if (field->flags & FIELD_IS_LONG) | 4769 | val = pevent_read_number(pevent, data + field->offset, |
| 4785 | trace_seq_printf(s, "0x%x", (int)val); | 4770 | field->size); |
| 4786 | else | 4771 | if (field->flags & FIELD_IS_POINTER) { |
| 4787 | trace_seq_printf(s, "%d", (int)val); | 4772 | trace_seq_printf(s, "0x%llx", val); |
| 4788 | break; | 4773 | } else if (field->flags & FIELD_IS_SIGNED) { |
| 4789 | case 2: | 4774 | switch (field->size) { |
| 4790 | trace_seq_printf(s, "%2d", (short)val); | 4775 | case 4: |
| 4791 | break; | 4776 | /* |
| 4792 | case 1: | 4777 | * If field is long then print it in hex. |
| 4793 | trace_seq_printf(s, "%1d", (char)val); | 4778 | * A long usually stores pointers. |
| 4794 | break; | 4779 | */ |
| 4795 | default: | ||
| 4796 | trace_seq_printf(s, "%lld", val); | ||
| 4797 | } | ||
| 4798 | } else { | ||
| 4799 | if (field->flags & FIELD_IS_LONG) | 4780 | if (field->flags & FIELD_IS_LONG) |
| 4800 | trace_seq_printf(s, "0x%llx", val); | 4781 | trace_seq_printf(s, "0x%x", (int)val); |
| 4801 | else | 4782 | else |
| 4802 | trace_seq_printf(s, "%llu", val); | 4783 | trace_seq_printf(s, "%d", (int)val); |
| 4784 | break; | ||
| 4785 | case 2: | ||
| 4786 | trace_seq_printf(s, "%2d", (short)val); | ||
| 4787 | break; | ||
| 4788 | case 1: | ||
| 4789 | trace_seq_printf(s, "%1d", (char)val); | ||
| 4790 | break; | ||
| 4791 | default: | ||
| 4792 | trace_seq_printf(s, "%lld", val); | ||
| 4803 | } | 4793 | } |
| 4794 | } else { | ||
| 4795 | if (field->flags & FIELD_IS_LONG) | ||
| 4796 | trace_seq_printf(s, "0x%llx", val); | ||
| 4797 | else | ||
| 4798 | trace_seq_printf(s, "%llu", val); | ||
| 4804 | } | 4799 | } |
| 4800 | } | ||
| 4801 | } | ||
| 4802 | |||
| 4803 | void pevent_print_fields(struct trace_seq *s, void *data, | ||
| 4804 | int size __maybe_unused, struct event_format *event) | ||
| 4805 | { | ||
| 4806 | struct format_field *field; | ||
| 4807 | |||
| 4808 | field = event->format.fields; | ||
| 4809 | while (field) { | ||
| 4810 | trace_seq_printf(s, " %s=", field->name); | ||
| 4811 | pevent_print_field(s, data, field); | ||
| 4805 | field = field->next; | 4812 | field = field->next; |
| 4806 | } | 4813 | } |
| 4807 | } | 4814 | } |
| @@ -4827,7 +4834,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event | |||
| 4827 | 4834 | ||
| 4828 | if (event->flags & EVENT_FL_FAILED) { | 4835 | if (event->flags & EVENT_FL_FAILED) { |
| 4829 | trace_seq_printf(s, "[FAILED TO PARSE]"); | 4836 | trace_seq_printf(s, "[FAILED TO PARSE]"); |
| 4830 | print_event_fields(s, data, size, event); | 4837 | pevent_print_fields(s, data, size, event); |
| 4831 | return; | 4838 | return; |
| 4832 | } | 4839 | } |
| 4833 | 4840 | ||
| @@ -5301,7 +5308,7 @@ void pevent_event_info(struct trace_seq *s, struct event_format *event, | |||
| 5301 | int print_pretty = 1; | 5308 | int print_pretty = 1; |
| 5302 | 5309 | ||
| 5303 | if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) | 5310 | if (event->pevent->print_raw || (event->flags & EVENT_FL_PRINTRAW)) |
| 5304 | print_event_fields(s, record->data, record->size, event); | 5311 | pevent_print_fields(s, record->data, record->size, event); |
| 5305 | else { | 5312 | else { |
| 5306 | 5313 | ||
| 5307 | if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) | 5314 | if (event->handler && !(event->flags & EVENT_FL_NOHANDLE)) |
diff --git a/tools/lib/traceevent/event-parse.h b/tools/lib/traceevent/event-parse.h index 6fc83c7edbe9..706d9bc24066 100644 --- a/tools/lib/traceevent/event-parse.h +++ b/tools/lib/traceevent/event-parse.h | |||
| @@ -705,6 +705,10 @@ struct cmdline *pevent_data_pid_from_comm(struct pevent *pevent, const char *com | |||
| 705 | struct cmdline *next); | 705 | struct cmdline *next); |
| 706 | int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline); | 706 | int pevent_cmdline_pid(struct pevent *pevent, struct cmdline *cmdline); |
| 707 | 707 | ||
| 708 | void pevent_print_field(struct trace_seq *s, void *data, | ||
| 709 | struct format_field *field); | ||
| 710 | void pevent_print_fields(struct trace_seq *s, void *data, | ||
| 711 | int size __maybe_unused, struct event_format *event); | ||
| 708 | void pevent_event_info(struct trace_seq *s, struct event_format *event, | 712 | void pevent_event_info(struct trace_seq *s, struct event_format *event, |
| 709 | struct pevent_record *record); | 713 | struct pevent_record *record); |
| 710 | int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, | 714 | int pevent_strerror(struct pevent *pevent, enum pevent_errno errnum, |
