From 73d4526db94a19330d59d27f2fa474592d4916bd Mon Sep 17 00:00:00 2001 From: Steven Rostedt Date: Thu, 17 Jun 2010 17:36:11 -0400 Subject: parse-events: Add helper function pevent_print_num_field() The _print_field() and print_field() functions were being used by multiple plugins. Each implementing their own helper function to get a field and print its value. Instead of having multiple functions to do the same job in different plugins, just add it to the core code. Signed-off-by: Steven Rostedt --- plugin_hrtimer.c | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) (limited to 'plugin_hrtimer.c') diff --git a/plugin_hrtimer.c b/plugin_hrtimer.c index eafcbbd..3db6047 100644 --- a/plugin_hrtimer.c +++ b/plugin_hrtimer.c @@ -25,45 +25,17 @@ #include "parse-events.h" -/* return -1 (field not found/not valid number), 0 (ok), 1 (buffer full) */ -static int _print_field(struct trace_seq *s, const char *fmt, - struct event_format *event, const char *name, const void *data) -{ - struct format_field *f = pevent_find_field(event, name); - unsigned long long val; - - if (!f) - return -1; - - if (pevent_read_number_field(f, data, &val)) - return -1; - - return trace_seq_printf(s, fmt, val); -} - -/* return 0 (ok), 1 (buffer full) */ -static void print_field(struct trace_seq *s, const char *fmt, - struct event_format *event, const char *name, const void *data) -{ - int ret = _print_field(s, fmt, event, name, data); - - if (ret == -1) - trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); -} - static int timer_expire_handler(struct trace_seq *s, struct record *record, struct event_format *event, void *context) { - void *data = record->data; - trace_seq_printf(s, "hrtimer="); - if (_print_field(s, "0x%llx", event, "timer", data) == -1) - print_field(s, "0x%llx", event, "hrtimer", data); + if (pevent_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1) + pevent_print_num_field(s, "0x%llx", event, "hrtimer", record, 1); trace_seq_printf(s, " now="); - print_field(s, "%llu", event, "now", data); + pevent_print_num_field(s, "%llu", event, "now", record, 1); return 0; } @@ -77,8 +49,8 @@ static int timer_start_handler(struct trace_seq *s, struct record *record, trace_seq_printf(s, "hrtimer="); - if (_print_field(s, "0x%llx", event, "timer", data) == -1) - print_field(s, "0x%llx", event, "hrtimer", data); + if (pevent_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1) + pevent_print_num_field(s, "0x%llx", event, "hrtimer", record, 1); if (!fn) { trace_seq_printf(s, " function=MISSING"); @@ -95,10 +67,10 @@ static int timer_start_handler(struct trace_seq *s, struct record *record, } trace_seq_printf(s, " expires="); - print_field(s, "%llu", event, "expires", data); + pevent_print_num_field(s, "%llu", event, "expires", record, 1); trace_seq_printf(s, " softexpires="); - print_field(s, "%llu", event, "softexpires", data); + pevent_print_num_field(s, "%llu", event, "softexpires", record, 1); return 0; } -- cgit v1.2.2