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
;
37 struct pevent
*read_trace_init(int file_bigendian
, int host_bigendian
)
39 struct pevent
*pevent
= pevent_alloc();
42 pevent_set_flag(pevent
, PEVENT_NSEC_OUTPUT
);
43 pevent_set_file_bigendian(pevent
, file_bigendian
);
44 pevent_set_host_bigendian(pevent
, host_bigendian
);
50 static int get_common_field(struct scripting_context
*context
,
51 int *offset
, int *size
, const char *type
)
53 struct pevent
*pevent
= context
->pevent
;
54 struct event_format
*event
;
55 struct format_field
*field
;
61 event
= pevent
->events
[0];
62 field
= pevent_find_common_field(event
, type
);
65 *offset
= field
->offset
;
69 return pevent_read_number(pevent
, context
->event_data
+ *offset
, *size
);
72 int common_lock_depth(struct scripting_context
*context
)
78 ret
= get_common_field(context
, &size
, &offset
,
86 int common_flags(struct scripting_context
*context
)
92 ret
= get_common_field(context
, &size
, &offset
,
100 int common_pc(struct scripting_context
*context
)
106 ret
= get_common_field(context
, &size
, &offset
,
107 "common_preempt_count");
115 raw_field_value(struct event_format
*event
, const char *name
, void *data
)
117 struct format_field
*field
;
118 unsigned long long val
;
120 field
= pevent_find_any_field(event
, name
);
124 pevent_read_number_field(field
, data
, &val
);
129 void *raw_field_ptr(struct event_format
*event
, const char *name
, void *data
)
131 struct format_field
*field
;
133 field
= pevent_find_any_field(event
, name
);
137 if (field
->flags
& FIELD_IS_DYNAMIC
) {
140 offset
= *(int *)(data
+ field
->offset
);
143 return data
+ offset
;
146 return data
+ field
->offset
;
149 int trace_parse_common_type(struct pevent
*pevent
, void *data
)
151 struct pevent_record record
;
154 return pevent_data_type(pevent
, &record
);
157 int trace_parse_common_pid(struct pevent
*pevent
, void *data
)
159 struct pevent_record record
;
162 return pevent_data_pid(pevent
, &record
);
165 unsigned long long read_size(struct pevent
*pevent
, void *ptr
, int size
)
167 return pevent_read_number(pevent
, ptr
, size
);
170 void print_trace_event(struct pevent
*pevent
, int cpu
, void *data
, int size
)
172 struct event_format
*event
;
173 struct pevent_record record
;
177 type
= trace_parse_common_type(pevent
, data
);
179 event
= pevent_find_event(pevent
, type
);
181 warning("ug! no event found for type %d", type
);
185 memset(&record
, 0, sizeof(record
));
191 pevent_event_info(&s
, event
, &record
);
192 trace_seq_do_printf(&s
);
195 void print_event(struct pevent
*pevent
, int cpu
, void *data
, int size
,
196 unsigned long long nsecs
, char *comm
)
198 struct pevent_record record
;
202 pevent
->latency_format
= latency_format
;
208 pid
= pevent_data_pid(pevent
, &record
);
210 if (!pevent_pid_is_registered(pevent
, pid
))
211 pevent_register_comm(pevent
, comm
, pid
);
214 pevent_print_event(pevent
, &s
, &record
);
215 trace_seq_do_printf(&s
);
219 void parse_proc_kallsyms(struct pevent
*pevent
,
220 char *file
, unsigned int size __unused
)
222 unsigned long long addr
;
230 line
= strtok_r(file
, "\n", &next
);
233 sscanf(line
, "%as %c %as\t[%as",
234 (float *)(void *)&addr_str
, /* workaround gcc warning */
235 &ch
, (float *)(void *)&func
, (float *)(void *)&mod
);
236 addr
= strtoull(addr_str
, NULL
, 16);
239 /* truncate the extra ']' */
241 mod
[strlen(mod
) - 1] = 0;
243 pevent_register_function(pevent
, func
, addr
, mod
);
247 line
= strtok_r(NULL
, "\n", &next
);
251 void parse_ftrace_printk(struct pevent
*pevent
,
252 char *file
, unsigned int size __unused
)
254 unsigned long long addr
;
261 line
= strtok_r(file
, "\n", &next
);
263 addr_str
= strtok_r(line
, ":", &fmt
);
265 warning("printk format with empty entry");
268 addr
= strtoull(addr_str
, NULL
, 16);
269 /* fmt still has a space, skip it */
270 printk
= strdup(fmt
+1);
271 line
= strtok_r(NULL
, "\n", &next
);
272 pevent_register_print_string(pevent
, printk
, addr
);
276 int parse_ftrace_file(struct pevent
*pevent
, char *buf
, unsigned long size
)
278 return pevent_parse_event(pevent
, buf
, size
, "ftrace");
281 int parse_event_file(struct pevent
*pevent
,
282 char *buf
, unsigned long size
, char *sys
)
284 return pevent_parse_event(pevent
, buf
, size
, sys
);
287 struct event_format
*trace_find_next_event(struct pevent
*pevent
,
288 struct event_format
*event
)
297 return pevent
->events
[0];
300 if (idx
< pevent
->nr_events
&& event
== pevent
->events
[idx
]) {
302 if (idx
== pevent
->nr_events
)
304 return pevent
->events
[idx
];
307 for (idx
= 1; idx
< pevent
->nr_events
; idx
++) {
308 if (event
== pevent
->events
[idx
- 1])
309 return pevent
->events
[idx
];
316 unsigned long long value
;
319 static const struct flag flags
[] = {
321 { "TIMER_SOFTIRQ", 1 },
322 { "NET_TX_SOFTIRQ", 2 },
323 { "NET_RX_SOFTIRQ", 3 },
324 { "BLOCK_SOFTIRQ", 4 },
325 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
326 { "TASKLET_SOFTIRQ", 6 },
327 { "SCHED_SOFTIRQ", 7 },
328 { "HRTIMER_SOFTIRQ", 8 },
329 { "RCU_SOFTIRQ", 9 },
331 { "HRTIMER_NORESTART", 0 },
332 { "HRTIMER_RESTART", 1 },
335 unsigned long long eval_flag(const char *flag
)
340 * Some flags in the format files do not get converted.
341 * If the flag is not numeric, see if it is something that
342 * we already know about.
344 if (isdigit(flag
[0]))
345 return strtoull(flag
, NULL
, 0);
347 for (i
= 0; i
< (int)(sizeof(flags
)/sizeof(flags
[0])); i
++)
348 if (strcmp(flags
[i
].name
, flag
) == 0)
349 return flags
[i
].value
;
This page took 0.038439 seconds and 6 git commands to generate.