diff options
author | Steven Rostedt <srostedt@redhat.com> | 2010-06-17 17:36:11 -0400 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2010-06-17 19:43:42 -0400 |
commit | 73d4526db94a19330d59d27f2fa474592d4916bd (patch) | |
tree | d34f7a0581da5f208b7b09cef00548f97c5e7359 | |
parent | 0f15820a184a5b54541dd0e19fd6f1f807a846b4 (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>
-rw-r--r-- | parse-events.c | 32 | ||||
-rw-r--r-- | parse-events.h | 4 | ||||
-rw-r--r-- | plugin_hrtimer.c | 42 | ||||
-rw-r--r-- | plugin_mac80211.c | 34 |
4 files changed, 47 insertions, 65 deletions
diff --git a/parse-events.c b/parse-events.c index d95dda4..8fd93ec 100644 --- a/parse-events.c +++ b/parse-events.c | |||
@@ -4421,6 +4421,38 @@ int pevent_parse_event(struct pevent *pevent, | |||
4421 | return -1; | 4421 | return -1; |
4422 | } | 4422 | } |
4423 | 4423 | ||
4424 | /** | ||
4425 | * pevent_print_num_field - print a field and a format | ||
4426 | * @s: The seq to print to | ||
4427 | * @fmt: The printf format to print the field with. | ||
4428 | * @event: the event that the field is for | ||
4429 | * @name: The name of the field | ||
4430 | * @record: The record with the field name. | ||
4431 | * @err: print default error if failed. | ||
4432 | * | ||
4433 | * Returns: 0 on success, -1 field not fould, or 1 if buffer is full. | ||
4434 | */ | ||
4435 | int pevent_print_num_field(struct trace_seq *s, const char *fmt, | ||
4436 | struct event_format *event, const char *name, | ||
4437 | struct record *record, int err) | ||
4438 | { | ||
4439 | struct format_field *field = pevent_find_field(event, name); | ||
4440 | unsigned long long val; | ||
4441 | |||
4442 | if (!field) | ||
4443 | goto failed; | ||
4444 | |||
4445 | if (pevent_read_number_field(field, record->data, &val)) | ||
4446 | goto failed; | ||
4447 | |||
4448 | return trace_seq_printf(s, fmt, val); | ||
4449 | |||
4450 | failed: | ||
4451 | if (err) | ||
4452 | trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); | ||
4453 | return -1; | ||
4454 | } | ||
4455 | |||
4424 | static void free_func_handle(struct pevent_function_handler *func) | 4456 | static void free_func_handle(struct pevent_function_handler *func) |
4425 | { | 4457 | { |
4426 | struct pevent_func_params *params; | 4458 | struct pevent_func_params *params; |
diff --git a/parse-events.h b/parse-events.h index fdbe617..d90a698 100644 --- a/parse-events.h +++ b/parse-events.h | |||
@@ -448,6 +448,10 @@ int pevent_parse_header_page(struct pevent *pevent, char *buf, unsigned long siz | |||
448 | int pevent_parse_event(struct pevent *pevent, const char *buf, | 448 | int pevent_parse_event(struct pevent *pevent, const char *buf, |
449 | unsigned long size, const char *sys); | 449 | unsigned long size, const char *sys); |
450 | 450 | ||
451 | int pevent_print_num_field(struct trace_seq *s, const char *fmt, | ||
452 | struct event_format *event, const char *name, | ||
453 | struct record *record, int err); | ||
454 | |||
451 | int pevent_register_event_handler(struct pevent *pevent, int id, char *sys_name, char *event_name, | 455 | int pevent_register_event_handler(struct pevent *pevent, int id, char *sys_name, char *event_name, |
452 | pevent_event_handler_func func, void *context); | 456 | pevent_event_handler_func func, void *context); |
453 | int pevent_register_print_function(struct pevent *pevent, | 457 | int pevent_register_print_function(struct pevent *pevent, |
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) */ | ||
29 | static 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) */ | ||
45 | static 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 | |||
54 | static int timer_expire_handler(struct trace_seq *s, struct record *record, | 28 | static 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 | } |
diff --git a/plugin_mac80211.c b/plugin_mac80211.c index e194ec2..3a2747f 100644 --- a/plugin_mac80211.c +++ b/plugin_mac80211.c | |||
@@ -26,32 +26,6 @@ | |||
26 | 26 | ||
27 | #define INDENT 65 | 27 | #define INDENT 65 |
28 | 28 | ||
29 | /* return -1 (field not found/not valid number), 0 (ok), 1 (buffer full) */ | ||
30 | static int _print_field(struct trace_seq *s, const char *fmt, | ||
31 | struct event_format *event, const char *name, const void *data) | ||
32 | { | ||
33 | struct format_field *f = pevent_find_field(event, name); | ||
34 | unsigned long long val; | ||
35 | |||
36 | if (!f) | ||
37 | return -1; | ||
38 | |||
39 | if (pevent_read_number_field(f, data, &val)) | ||
40 | return -1; | ||
41 | |||
42 | return trace_seq_printf(s, fmt, val); | ||
43 | } | ||
44 | |||
45 | /* return 0 (ok), 1 (buffer full) */ | ||
46 | static void print_field(struct trace_seq *s, const char *fmt, | ||
47 | struct event_format *event, const char *name, const void *data) | ||
48 | { | ||
49 | int ret = _print_field(s, fmt, event, name, data); | ||
50 | |||
51 | if (ret == -1) | ||
52 | trace_seq_printf(s, "NOTFOUND:%s", name); | ||
53 | } | ||
54 | |||
55 | static void print_string(struct trace_seq *s, struct event_format *event, | 29 | static void print_string(struct trace_seq *s, struct event_format *event, |
56 | const char *name, const void *data) | 30 | const char *name, const void *data) |
57 | { | 31 | { |
@@ -161,8 +135,8 @@ static void _print_flag(struct trace_seq *s, struct event_format *event, | |||
161 | _print_flag(s, ev, name, data, __n, sizeof(__n)/sizeof(__n[0])); \ | 135 | _print_flag(s, ev, name, data, __n, sizeof(__n)/sizeof(__n[0])); \ |
162 | }) | 136 | }) |
163 | 137 | ||
164 | #define SF(fn) _print_field(s, fn ":%d", event, fn, data) | 138 | #define SF(fn) pevent_print_num_field(s, fn ":%d", event, fn, record, 0) |
165 | #define SFX(fn) _print_field(s, fn ":%#x", event, fn, data) | 139 | #define SFX(fn) pevent_print_num_field(s, fn ":%#x", event, fn, record, 0) |
166 | #define SP() trace_seq_putc(s, ' ') | 140 | #define SP() trace_seq_putc(s, ' ') |
167 | 141 | ||
168 | static int drv_bss_info_changed(struct trace_seq *s, struct record *record, | 142 | static int drv_bss_info_changed(struct trace_seq *s, struct record *record, |
@@ -173,7 +147,7 @@ static int drv_bss_info_changed(struct trace_seq *s, struct record *record, | |||
173 | print_string(s, event, "wiphy_name", data); | 147 | print_string(s, event, "wiphy_name", data); |
174 | trace_seq_printf(s, " vif:"); | 148 | trace_seq_printf(s, " vif:"); |
175 | print_string(s, event, "vif_name", data); | 149 | print_string(s, event, "vif_name", data); |
176 | print_field(s, "(%d)", event, "vif_type", data); | 150 | pevent_print_num_field(s, "(%d)", event, "vif_type", record, 1); |
177 | 151 | ||
178 | trace_seq_printf(s, "\n%*s", INDENT, ""); | 152 | trace_seq_printf(s, "\n%*s", INDENT, ""); |
179 | SF("assoc"); SP(); | 153 | SF("assoc"); SP(); |
@@ -206,7 +180,7 @@ static int drv_config(struct trace_seq *s, struct record *record, | |||
206 | { 2, "IDLE" }, | 180 | { 2, "IDLE" }, |
207 | { 3, "QOS"}, | 181 | { 3, "QOS"}, |
208 | ); | 182 | ); |
209 | print_field(s, " chan:%d/", event, "center_freq", data); | 183 | pevent_print_num_field(s, " chan:%d/", event, "center_freq", record, 1); |
210 | print_enum(s, event, "channel_type", data, | 184 | print_enum(s, event, "channel_type", data, |
211 | { 0, "noht" }, | 185 | { 0, "noht" }, |
212 | { 1, "ht20" }, | 186 | { 1, "ht20" }, |