diff options
| author | Johannes Berg <johannes@sipsolutions.net> | 2009-11-25 10:12:46 -0500 |
|---|---|---|
| committer | Johannes Berg <johannes@sipsolutions.net> | 2009-11-25 10:12:46 -0500 |
| commit | 2a0cf9ebb12ebc7d4fd417d897819d2c2cb6b3f6 (patch) | |
| tree | cdbf9afb3d8e4f9aa9f72ecb05684728f5c70b25 | |
| parent | 93341c3407d8098efb955494ac6723d61ec2294e (diff) | |
correct and simplify hrtimer plugin
The current hrtimer plugin code is broken wrt.
the return values, but it can now ignore the
trace_seq_* return values completely and focus
on parsing the data. Also, the handler API
should return 0 (all OK) or negative numbers
on errors.
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
| -rw-r--r-- | plugin_hrtimer.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/plugin_hrtimer.c b/plugin_hrtimer.c index 9d9b969..2a074e7 100644 --- a/plugin_hrtimer.c +++ b/plugin_hrtimer.c | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include "parse-events.h" | 5 | #include "parse-events.h" |
| 6 | 6 | ||
| 7 | /* return -1 (field not found/not valid number), 0 (ok), 1 (buffer full) */ | ||
| 7 | static int _print_field(struct trace_seq *s, const char *fmt, | 8 | static int _print_field(struct trace_seq *s, const char *fmt, |
| 8 | struct event *event, const char *name, const void *data) | 9 | struct event *event, const char *name, const void *data) |
| 9 | { | 10 | { |
| @@ -11,78 +12,70 @@ static int _print_field(struct trace_seq *s, const char *fmt, | |||
| 11 | unsigned long long val; | 12 | unsigned long long val; |
| 12 | 13 | ||
| 13 | if (!f) | 14 | if (!f) |
| 14 | return 0; | 15 | return -1; |
| 15 | 16 | ||
| 16 | if (pevent_read_number_field(f, data, &val)) | 17 | if (pevent_read_number_field(f, data, &val)) |
| 17 | return 0; | 18 | return -1; |
| 18 | 19 | ||
| 19 | return trace_seq_printf(s, fmt, val); | 20 | return trace_seq_printf(s, fmt, val); |
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | static int print_field(struct trace_seq *s, const char *fmt, | 23 | /* return 0 (ok), 1 (buffer full) */ |
| 23 | struct event *event, const char *name, const void *data) | 24 | static void print_field(struct trace_seq *s, const char *fmt, |
| 25 | struct event *event, const char *name, const void *data) | ||
| 24 | { | 26 | { |
| 25 | int ret = _print_field(s, fmt, event, name, data); | 27 | int ret = _print_field(s, fmt, event, name, data); |
| 26 | 28 | ||
| 27 | if (ret == 0) | 29 | if (ret == -1) |
| 28 | ret = trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); | 30 | trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); |
| 29 | |||
| 30 | return ret; | ||
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | static int timer_expire_handler(struct trace_seq *s, void *data, int size, | 33 | static int timer_expire_handler(struct trace_seq *s, void *data, int size, |
| 34 | struct event *event) | 34 | struct event *event) |
| 35 | { | 35 | { |
| 36 | int ret = 0, tmp; | 36 | trace_seq_printf(s, "hrtimer="); |
| 37 | 37 | ||
| 38 | ret += trace_seq_printf(s, "hrtimer="); | 38 | if (_print_field(s, "0x%llx", event, "timer", data) == -1) |
| 39 | tmp = _print_field(s, "0x%llx", event, "timer", data); | 39 | print_field(s, "0x%llx", event, "hrtimer", data); |
| 40 | if (tmp) | ||
| 41 | ret += tmp; | ||
| 42 | else | ||
| 43 | ret += print_field(s, "0x%llx", event, "hrtimer", data); | ||
| 44 | 40 | ||
| 45 | ret += trace_seq_printf(s, " now="); | 41 | trace_seq_printf(s, " now="); |
| 46 | 42 | ||
| 47 | ret += print_field(s, "%llu", event, "now", data); | 43 | print_field(s, "%llu", event, "now", data); |
| 48 | 44 | ||
| 49 | return ret; | 45 | return 0; |
| 50 | } | 46 | } |
| 51 | 47 | ||
| 52 | static int timer_start_handler(struct trace_seq *s, void *data, int size, | 48 | static int timer_start_handler(struct trace_seq *s, void *data, int size, |
| 53 | struct event *event) | 49 | struct event *event) |
| 54 | { | 50 | { |
| 55 | struct format_field *fn = pevent_find_field(event, "function"); | 51 | struct format_field *fn = pevent_find_field(event, "function"); |
| 56 | int ret = 0, tmp; | ||
| 57 | 52 | ||
| 58 | ret += trace_seq_printf(s, "hrtimer="); | 53 | trace_seq_printf(s, "hrtimer="); |
| 59 | tmp = _print_field(s, "0x%llx", event, "timer", data); | 54 | |
| 60 | if (tmp) | 55 | if (_print_field(s, "0x%llx", event, "timer", data) == -1) |
| 61 | ret += tmp; | 56 | print_field(s, "0x%llx", event, "hrtimer", data); |
| 62 | else | ||
| 63 | ret += print_field(s, "0x%llx", event, "hrtimer", data); | ||
| 64 | 57 | ||
| 65 | if (!fn) { | 58 | if (!fn) { |
| 66 | ret += trace_seq_printf(s, " function=MISSING"); | 59 | trace_seq_printf(s, " function=MISSING"); |
| 67 | } else { | 60 | } else { |
| 68 | unsigned long long function; | 61 | unsigned long long function; |
| 69 | const char *func; | 62 | const char *func; |
| 70 | 63 | ||
| 71 | if (pevent_read_number_field(fn, data, &function)) | 64 | if (pevent_read_number_field(fn, data, &function)) |
| 72 | ret += trace_seq_printf(s, " function=INVALID"); | 65 | trace_seq_printf(s, " function=INVALID"); |
| 73 | 66 | ||
| 74 | func = pevent_find_function(function); | 67 | func = pevent_find_function(function); |
| 75 | 68 | ||
| 76 | ret += trace_seq_printf(s, " function=%s", func); | 69 | trace_seq_printf(s, " function=%s", func); |
| 77 | } | 70 | } |
| 78 | 71 | ||
| 79 | ret += trace_seq_printf(s, " expires="); | 72 | trace_seq_printf(s, " expires="); |
| 80 | ret += print_field(s, "%llu", event, "expires", data); | 73 | print_field(s, "%llu", event, "expires", data); |
| 81 | 74 | ||
| 82 | ret += trace_seq_printf(s, " softexpires="); | 75 | trace_seq_printf(s, " softexpires="); |
| 83 | ret += print_field(s, "%llu", event, "softexpires", data); | 76 | print_field(s, "%llu", event, "softexpires", data); |
| 84 | 77 | ||
| 85 | return ret; | 78 | return 0; |
| 86 | } | 79 | } |
| 87 | 80 | ||
| 88 | int PEVENT_PLUGIN_LOADER(void) | 81 | int PEVENT_PLUGIN_LOADER(void) |
