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 int header_page_size_size;
32 int header_page_ts_size;
33 int header_page_data_offset;
35 struct pevent *perf_pevent;
36 static struct pevent *pevent;
40 int read_trace_init(int file_bigendian, int host_bigendian)
45 perf_pevent = pevent_alloc();
48 pevent_set_flag(pevent, PEVENT_NSEC_OUTPUT);
49 pevent_set_file_bigendian(pevent, file_bigendian);
50 pevent_set_host_bigendian(pevent, host_bigendian);
55 static int get_common_field(struct scripting_context *context,
56 int *offset, int *size, const char *type)
58 struct event_format *event;
59 struct format_field *field;
65 event = pevent->events[0];
66 field = pevent_find_common_field(event, type);
69 *offset = field->offset;
73 return pevent_read_number(pevent, context->event_data + *offset, *size);
76 int common_lock_depth(struct scripting_context *context)
82 ret = get_common_field(context, &size, &offset,
90 int common_flags(struct scripting_context *context)
96 ret = get_common_field(context, &size, &offset,
104 int common_pc(struct scripting_context *context)
110 ret = get_common_field(context, &size, &offset,
111 "common_preempt_count");
119 raw_field_value(struct event_format *event, const char *name, void *data)
121 struct format_field *field;
122 unsigned long long val;
124 field = pevent_find_any_field(event, name);
128 pevent_read_number_field(field, data, &val);
133 void *raw_field_ptr(struct event_format *event, const char *name, void *data)
135 struct format_field *field;
137 field = pevent_find_any_field(event, name);
141 if (field->flags & FIELD_IS_DYNAMIC) {
144 offset = *(int *)(data + field->offset);
147 return data + offset;
150 return data + field->offset;
153 int trace_parse_common_type(void *data)
155 struct pevent_record record;
158 return pevent_data_type(pevent, &record);
161 int trace_parse_common_pid(void *data)
163 struct pevent_record record;
166 return pevent_data_pid(pevent, &record);
169 unsigned long long read_size(void *ptr, int size)
171 return pevent_read_number(pevent, ptr, size);
174 struct event_format *trace_find_event(int type)
176 return pevent_find_event(pevent, type);
180 void print_trace_event(int cpu, void *data, int size)
182 struct event_format *event;
183 struct pevent_record record;
187 type = trace_parse_common_type(data);
189 event = trace_find_event(type);
191 warning("ug! no event found for type %d", type);
195 memset(&record, 0, sizeof(record));
201 pevent_event_info(&s, event, &record);
202 trace_seq_do_printf(&s);
205 void print_event(int cpu, void *data, int size, unsigned long long nsecs,
208 struct pevent_record record;
212 pevent->latency_format = latency_format;
218 pid = pevent_data_pid(pevent, &record);
220 if (!pevent_pid_is_registered(pevent, pid))
221 pevent_register_comm(pevent, comm, pid);
224 pevent_print_event(pevent, &s, &record);
225 trace_seq_do_printf(&s);
229 void parse_proc_kallsyms(char *file, unsigned int size __unused)
231 unsigned long long addr;
239 line = strtok_r(file, "\n", &next);
242 sscanf(line, "%as %c %as\t[%as",
243 (float *)(void *)&addr_str, /* workaround gcc warning */
244 &ch, (float *)(void *)&func, (float *)(void *)&mod);
245 addr = strtoull(addr_str, NULL, 16);
248 /* truncate the extra ']' */
250 mod[strlen(mod) - 1] = 0;
252 pevent_register_function(pevent, func, addr, mod);
256 line = strtok_r(NULL, "\n", &next);
260 void parse_ftrace_printk(char *file, unsigned int size __unused)
262 unsigned long long addr;
269 line = strtok_r(file, "\n", &next);
271 addr_str = strtok_r(line, ":", &fmt);
273 warning("printk format with empty entry");
276 addr = strtoull(addr_str, NULL, 16);
277 /* fmt still has a space, skip it */
278 printk = strdup(fmt+1);
279 line = strtok_r(NULL, "\n", &next);
280 pevent_register_print_string(pevent, printk, addr);
284 int parse_ftrace_file(char *buf, unsigned long size)
286 return pevent_parse_event(pevent, buf, size, "ftrace");
289 int parse_event_file(char *buf, unsigned long size, char *sys)
291 return pevent_parse_event(pevent, buf, size, sys);
294 struct event_format *trace_find_next_event(struct event_format *event)
303 return pevent->events[0];
306 if (idx < pevent->nr_events && event == pevent->events[idx]) {
308 if (idx == pevent->nr_events)
310 return pevent->events[idx];
313 for (idx = 1; idx < pevent->nr_events; idx++) {
314 if (event == pevent->events[idx - 1])
315 return pevent->events[idx];
322 unsigned long long value;
325 static const struct flag flags[] = {
327 { "TIMER_SOFTIRQ", 1 },
328 { "NET_TX_SOFTIRQ", 2 },
329 { "NET_RX_SOFTIRQ", 3 },
330 { "BLOCK_SOFTIRQ", 4 },
331 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
332 { "TASKLET_SOFTIRQ", 6 },
333 { "SCHED_SOFTIRQ", 7 },
334 { "HRTIMER_SOFTIRQ", 8 },
335 { "RCU_SOFTIRQ", 9 },
337 { "HRTIMER_NORESTART", 0 },
338 { "HRTIMER_RESTART", 1 },
341 unsigned long long eval_flag(const char *flag)
346 * Some flags in the format files do not get converted.
347 * If the flag is not numeric, see if it is something that
348 * we already know about.
350 if (isdigit(flag[0]))
351 return strtoull(flag, NULL, 0);
353 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
354 if (strcmp(flags[i].name, flag) == 0)
355 return flags[i].value;