aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_hrtimer.c
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-06-17 17:36:11 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-06-17 19:43:42 -0400
commit73d4526db94a19330d59d27f2fa474592d4916bd (patch)
treed34f7a0581da5f208b7b09cef00548f97c5e7359 /plugin_hrtimer.c
parent0f15820a184a5b54541dd0e19fd6f1f807a846b4 (diff)
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 <rostedt@goodmis.org>
Diffstat (limited to 'plugin_hrtimer.c')
-rw-r--r--plugin_hrtimer.c42
1 files changed, 7 insertions, 35 deletions
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 @@
25 25
26#include "parse-events.h" 26#include "parse-events.h"
27 27
28/* return -1 (field not found/not valid number), 0 (ok), 1 (buffer full) */
29static int _print_field(struct trace_seq *s, const char *fmt,
30 struct event_format *event, const char *name, const void *data)
31{
32 struct format_field *f = pevent_find_field(event, name);
33 unsigned long long val;
34
35 if (!f)
36 return -1;
37
38 if (pevent_read_number_field(f, data, &val))
39 return -1;
40
41 return trace_seq_printf(s, fmt, val);
42}
43
44/* return 0 (ok), 1 (buffer full) */
45static void print_field(struct trace_seq *s, const char *fmt,
46 struct event_format *event, const char *name, const void *data)
47{
48 int ret = _print_field(s, fmt, event, name, data);
49
50 if (ret == -1)
51 trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
52}
53
54static int timer_expire_handler(struct trace_seq *s, struct record *record, 28static int timer_expire_handler(struct trace_seq *s, struct record *record,
55 struct event_format *event, void *context) 29 struct event_format *event, void *context)
56{ 30{
57 void *data = record->data;
58
59 trace_seq_printf(s, "hrtimer="); 31 trace_seq_printf(s, "hrtimer=");
60 32
61 if (_print_field(s, "0x%llx", event, "timer", data) == -1) 33 if (pevent_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1)
62 print_field(s, "0x%llx", event, "hrtimer", data); 34 pevent_print_num_field(s, "0x%llx", event, "hrtimer", record, 1);
63 35
64 trace_seq_printf(s, " now="); 36 trace_seq_printf(s, " now=");
65 37
66 print_field(s, "%llu", event, "now", data); 38 pevent_print_num_field(s, "%llu", event, "now", record, 1);
67 39
68 return 0; 40 return 0;
69} 41}
@@ -77,8 +49,8 @@ static int timer_start_handler(struct trace_seq *s, struct record *record,
77 49
78 trace_seq_printf(s, "hrtimer="); 50 trace_seq_printf(s, "hrtimer=");
79 51
80 if (_print_field(s, "0x%llx", event, "timer", data) == -1) 52 if (pevent_print_num_field(s, "0x%llx", event, "timer", record, 0) == -1)
81 print_field(s, "0x%llx", event, "hrtimer", data); 53 pevent_print_num_field(s, "0x%llx", event, "hrtimer", record, 1);
82 54
83 if (!fn) { 55 if (!fn) {
84 trace_seq_printf(s, " function=MISSING"); 56 trace_seq_printf(s, " function=MISSING");
@@ -95,10 +67,10 @@ static int timer_start_handler(struct trace_seq *s, struct record *record,
95 } 67 }
96 68
97 trace_seq_printf(s, " expires="); 69 trace_seq_printf(s, " expires=");
98 print_field(s, "%llu", event, "expires", data); 70 pevent_print_num_field(s, "%llu", event, "expires", record, 1);
99 71
100 trace_seq_printf(s, " softexpires="); 72 trace_seq_printf(s, " softexpires=");
101 print_field(s, "%llu", event, "softexpires", data); 73 pevent_print_num_field(s, "%llu", event, "softexpires", record, 1);
102 74
103 return 0; 75 return 0;
104} 76}