2 * Copyright (C) 2009, Steven Rostedt <srostedt@redhat.com>
4 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License (not later!)
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
29 #include "trace-event.h"
31 struct pevent
*read_trace_init(int file_bigendian
, int host_bigendian
)
33 struct pevent
*pevent
= pevent_alloc();
36 pevent_set_flag(pevent
, PEVENT_NSEC_OUTPUT
);
37 pevent_set_file_bigendian(pevent
, file_bigendian
);
38 pevent_set_host_bigendian(pevent
, host_bigendian
);
44 static int get_common_field(struct scripting_context
*context
,
45 int *offset
, int *size
, const char *type
)
47 struct pevent
*pevent
= context
->pevent
;
48 struct event_format
*event
;
49 struct format_field
*field
;
55 event
= pevent
->events
[0];
56 field
= pevent_find_common_field(event
, type
);
59 *offset
= field
->offset
;
63 return pevent_read_number(pevent
, context
->event_data
+ *offset
, *size
);
66 int common_lock_depth(struct scripting_context
*context
)
72 ret
= get_common_field(context
, &size
, &offset
,
80 int common_flags(struct scripting_context
*context
)
86 ret
= get_common_field(context
, &size
, &offset
,
94 int common_pc(struct scripting_context
*context
)
100 ret
= get_common_field(context
, &size
, &offset
,
101 "common_preempt_count");
109 raw_field_value(struct event_format
*event
, const char *name
, void *data
)
111 struct format_field
*field
;
112 unsigned long long val
;
114 field
= pevent_find_any_field(event
, name
);
118 pevent_read_number_field(field
, data
, &val
);
123 void *raw_field_ptr(struct event_format
*event
, const char *name
, void *data
)
125 struct format_field
*field
;
127 field
= pevent_find_any_field(event
, name
);
131 if (field
->flags
& FIELD_IS_DYNAMIC
) {
134 offset
= *(int *)(data
+ field
->offset
);
137 return data
+ offset
;
140 return data
+ field
->offset
;
143 int trace_parse_common_type(struct pevent
*pevent
, void *data
)
145 struct pevent_record record
;
148 return pevent_data_type(pevent
, &record
);
151 int trace_parse_common_pid(struct pevent
*pevent
, void *data
)
153 struct pevent_record record
;
156 return pevent_data_pid(pevent
, &record
);
159 unsigned long long read_size(struct event_format
*event
, void *ptr
, int size
)
161 return pevent_read_number(event
->pevent
, ptr
, size
);
164 void event_format__print(struct event_format
*event
,
165 int cpu
, void *data
, int size
)
167 struct pevent_record record
;
170 memset(&record
, 0, sizeof(record
));
176 pevent_event_info(&s
, event
, &record
);
177 trace_seq_do_printf(&s
);
180 void parse_proc_kallsyms(struct pevent
*pevent
,
181 char *file
, unsigned int size __maybe_unused
)
183 unsigned long long addr
;
191 line
= strtok_r(file
, "\n", &next
);
194 addr_str
= strtok_r(line
, " ", &fmt
);
195 addr
= strtoull(addr_str
, NULL
, 16);
197 strtok_r(NULL
, " ", &fmt
);
198 func
= strtok_r(NULL
, "\t", &fmt
);
199 mod
= strtok_r(NULL
, "]", &fmt
);
200 /* truncate the extra '[' */
204 pevent_register_function(pevent
, func
, addr
, mod
);
206 line
= strtok_r(NULL
, "\n", &next
);
210 void parse_ftrace_printk(struct pevent
*pevent
,
211 char *file
, unsigned int size __maybe_unused
)
213 unsigned long long addr
;
220 line
= strtok_r(file
, "\n", &next
);
222 addr_str
= strtok_r(line
, ":", &fmt
);
224 warning("printk format with empty entry");
227 addr
= strtoull(addr_str
, NULL
, 16);
228 /* fmt still has a space, skip it */
229 printk
= strdup(fmt
+1);
230 line
= strtok_r(NULL
, "\n", &next
);
231 pevent_register_print_string(pevent
, printk
, addr
);
235 int parse_ftrace_file(struct pevent
*pevent
, char *buf
, unsigned long size
)
237 return pevent_parse_event(pevent
, buf
, size
, "ftrace");
240 int parse_event_file(struct pevent
*pevent
,
241 char *buf
, unsigned long size
, char *sys
)
243 return pevent_parse_event(pevent
, buf
, size
, sys
);
246 struct event_format
*trace_find_next_event(struct pevent
*pevent
,
247 struct event_format
*event
)
251 if (!pevent
|| !pevent
->events
)
256 return pevent
->events
[0];
259 if (idx
< pevent
->nr_events
&& event
== pevent
->events
[idx
]) {
261 if (idx
== pevent
->nr_events
)
263 return pevent
->events
[idx
];
266 for (idx
= 1; idx
< pevent
->nr_events
; idx
++) {
267 if (event
== pevent
->events
[idx
- 1])
268 return pevent
->events
[idx
];
275 unsigned long long value
;
278 static const struct flag flags
[] = {
280 { "TIMER_SOFTIRQ", 1 },
281 { "NET_TX_SOFTIRQ", 2 },
282 { "NET_RX_SOFTIRQ", 3 },
283 { "BLOCK_SOFTIRQ", 4 },
284 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
285 { "TASKLET_SOFTIRQ", 6 },
286 { "SCHED_SOFTIRQ", 7 },
287 { "HRTIMER_SOFTIRQ", 8 },
288 { "RCU_SOFTIRQ", 9 },
290 { "HRTIMER_NORESTART", 0 },
291 { "HRTIMER_RESTART", 1 },
294 unsigned long long eval_flag(const char *flag
)
299 * Some flags in the format files do not get converted.
300 * If the flag is not numeric, see if it is something that
301 * we already know about.
303 if (isdigit(flag
[0]))
304 return strtoull(flag
, NULL
, 0);
306 for (i
= 0; i
< (int)(sizeof(flags
)/sizeof(flags
[0])); i
++)
307 if (strcmp(flags
[i
].name
, flag
) == 0)
308 return flags
[i
].value
;