aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_hrtimer.c
diff options
context:
space:
mode:
authorJohannes Berg <johannes@sipsolutions.net>2009-11-25 06:13:23 -0500
committerJohannes Berg <johannes@sipsolutions.net>2009-11-25 06:16:22 -0500
commit1074d79e65eef6580983bd06703364036e94d98d (patch)
treefccf5c6b21d04c90a2a933291a0507aa0662aabf /plugin_hrtimer.c
parentcd5a5a4d1600b0df073f47c899173f585fd7698c (diff)
hrtimer plugin: use new field infrastructure
This should make the plugin able to read data from both 32 and 64 bit platforms regardless of the machine it is running on. Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Diffstat (limited to 'plugin_hrtimer.c')
-rw-r--r--plugin_hrtimer.c111
1 files changed, 53 insertions, 58 deletions
diff --git a/plugin_hrtimer.c b/plugin_hrtimer.c
index 3b921ad..9d9b969 100644
--- a/plugin_hrtimer.c
+++ b/plugin_hrtimer.c
@@ -4,89 +4,84 @@
4 4
5#include "parse-events.h" 5#include "parse-events.h"
6 6
7static int _get_offset(struct event *event, char *name) 7static int _print_field(struct trace_seq *s, const char *fmt,
8 struct event *event, const char *name, const void *data)
8{ 9{
9 struct format_field *field; 10 struct format_field *f = pevent_find_field(event, name);
11 unsigned long long val;
10 12
11 field = pevent_find_field(event, name); 13 if (!f)
12 if (field) 14 return 0;
13 return field->offset; 15
16 if (pevent_read_number_field(f, data, &val))
17 return 0;
14 18
15 return -1; 19 return trace_seq_printf(s, fmt, val);
16} 20}
17 21
18static int get_offset(struct trace_seq *s, struct event *event, char *name) 22static int print_field(struct trace_seq *s, const char *fmt,
23 struct event *event, const char *name, const void *data)
19{ 24{
20 int r = _get_offset(event, name); 25 int ret = _print_field(s, fmt, event, name, data);
21 26
22 if (r < 0) 27 if (ret == 0)
23 trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name); 28 ret = trace_seq_printf(s, "CAN'T FIND FIELD \"%s\"", name);
24 29
25 return r; 30 return ret;
26} 31}
27 32
28static int timer_expire_handler(struct trace_seq *s, void *data, int size, 33static int timer_expire_handler(struct trace_seq *s, void *data, int size,
29 struct event *event) 34 struct event *event)
30{ 35{
31 void *hrtimer; 36 int ret = 0, tmp;
32 long long now;
33 int offset;
34 int ret;
35
36 offset = _get_offset(event, "timer");
37 if (offset < 0)
38 offset = get_offset(s, event, "hrtimer");
39 if (offset < 0)
40 return 0;
41 hrtimer = *(void **)(data + offset);
42 37
43 offset = get_offset(s, event, "now"); 38 ret += trace_seq_printf(s, "hrtimer=");
44 if (offset < 0) 39 tmp = _print_field(s, "0x%llx", event, "timer", data);
45 return 0; 40 if (tmp)
46 now = *(long long *)(data + offset); 41 ret += tmp;
42 else
43 ret += print_field(s, "0x%llx", event, "hrtimer", data);
44
45 ret += trace_seq_printf(s, " now=");
46
47 ret += print_field(s, "%llu", event, "now", data);
47 48
48 ret = trace_seq_printf(s, "hrtimer=%p now=%llu",
49 hrtimer, now);
50 return ret; 49 return ret;
51} 50}
52 51
53static int timer_start_handler(struct trace_seq *s, void *data, int size, 52static int timer_start_handler(struct trace_seq *s, void *data, int size,
54 struct event *event) 53 struct event *event)
55{ 54{
56 const char *func; 55 struct format_field *fn = pevent_find_field(event, "function");
57 void *hrtimer; 56 int ret = 0, tmp;
58 void *function;
59 long long expires;
60 long long soft;
61 int offset;
62 int ret;
63
64 offset = _get_offset(event, "timer");
65 if (offset < 0)
66 offset = get_offset(s, event, "hrtimer");
67 if (offset < 0)
68 return 0;
69 hrtimer = *(void **)(data + offset);
70 57
71 offset = get_offset(s, event, "function"); 58 ret += trace_seq_printf(s, "hrtimer=");
72 if (offset < 0) 59 tmp = _print_field(s, "0x%llx", event, "timer", data);
73 return 0; 60 if (tmp)
74 function = *(void **)(data + offset); 61 ret += tmp;
75 func = pevent_find_function((unsigned long long)function); 62 else
63 ret += print_field(s, "0x%llx", event, "hrtimer", data);
76 64
77 offset = get_offset(s, event, "expires"); 65 if (!fn) {
78 if (offset < 0) 66 ret += trace_seq_printf(s, " function=MISSING");
79 return 0; 67 } else {
80 expires = *(long long *)(data + offset); 68 unsigned long long function;
69 const char *func;
81 70
82 offset = get_offset(s, event, "softexpires"); 71 if (pevent_read_number_field(fn, data, &function))
83 if (offset < 0) 72 ret += trace_seq_printf(s, " function=INVALID");
84 return 0; 73
85 soft = *(long long *)(data + offset); 74 func = pevent_find_function(function);
75
76 ret += trace_seq_printf(s, " function=%s", func);
77 }
78
79 ret += trace_seq_printf(s, " expires=");
80 ret += print_field(s, "%llu", event, "expires", data);
81
82 ret += trace_seq_printf(s, " softexpires=");
83 ret += print_field(s, "%llu", event, "softexpires", data);
86 84
87 ret = trace_seq_printf(s, "hrtimer=%p function=%s expires=%llu softexpires=%llu",
88 hrtimer, func,
89 expires, soft);
90 return ret; 85 return ret;
91} 86}
92 87