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 static int get_common_field(struct scripting_context *context,
32 int *offset, int *size, const char *type)
34 struct pevent *pevent = context->pevent;
35 struct event_format *event;
36 struct format_field *field;
42 event = pevent->events[0];
43 field = pevent_find_common_field(event, type);
46 *offset = field->offset;
50 return pevent_read_number(pevent, context->event_data + *offset, *size);
53 int common_lock_depth(struct scripting_context *context)
59 ret = get_common_field(context, &size, &offset,
67 int common_flags(struct scripting_context *context)
73 ret = get_common_field(context, &size, &offset,
81 int common_pc(struct scripting_context *context)
87 ret = get_common_field(context, &size, &offset,
88 "common_preempt_count");
96 raw_field_value(struct event_format *event, const char *name, void *data)
98 struct format_field *field;
99 unsigned long long val;
101 field = pevent_find_any_field(event, name);
105 pevent_read_number_field(field, data, &val);
110 unsigned long long read_size(struct event_format *event, void *ptr, int size)
112 return pevent_read_number(event->pevent, ptr, size);
115 void event_format__print(struct event_format *event,
116 int cpu, void *data, int size)
118 struct pevent_record record;
121 memset(&record, 0, sizeof(record));
127 pevent_event_info(&s, event, &record);
128 trace_seq_do_printf(&s);
129 trace_seq_destroy(&s);
132 void parse_proc_kallsyms(struct pevent *pevent,
133 char *file, unsigned int size __maybe_unused)
135 unsigned long long addr;
143 line = strtok_r(file, "\n", &next);
146 addr_str = strtok_r(line, " ", &fmt);
147 addr = strtoull(addr_str, NULL, 16);
149 strtok_r(NULL, " ", &fmt);
150 func = strtok_r(NULL, "\t", &fmt);
151 mod = strtok_r(NULL, "]", &fmt);
152 /* truncate the extra '[' */
156 pevent_register_function(pevent, func, addr, mod);
158 line = strtok_r(NULL, "\n", &next);
162 void parse_ftrace_printk(struct pevent *pevent,
163 char *file, unsigned int size __maybe_unused)
165 unsigned long long addr;
172 line = strtok_r(file, "\n", &next);
174 addr_str = strtok_r(line, ":", &fmt);
176 warning("printk format with empty entry");
179 addr = strtoull(addr_str, NULL, 16);
180 /* fmt still has a space, skip it */
181 printk = strdup(fmt+1);
182 line = strtok_r(NULL, "\n", &next);
183 pevent_register_print_string(pevent, printk, addr);
187 int parse_ftrace_file(struct pevent *pevent, char *buf, unsigned long size)
189 return pevent_parse_event(pevent, buf, size, "ftrace");
192 int parse_event_file(struct pevent *pevent,
193 char *buf, unsigned long size, char *sys)
195 return pevent_parse_event(pevent, buf, size, sys);
198 struct event_format *trace_find_next_event(struct pevent *pevent,
199 struct event_format *event)
203 if (!pevent || !pevent->events)
208 return pevent->events[0];
211 if (idx < pevent->nr_events && event == pevent->events[idx]) {
213 if (idx == pevent->nr_events)
215 return pevent->events[idx];
218 for (idx = 1; idx < pevent->nr_events; idx++) {
219 if (event == pevent->events[idx - 1])
220 return pevent->events[idx];
227 unsigned long long value;
230 static const struct flag flags[] = {
232 { "TIMER_SOFTIRQ", 1 },
233 { "NET_TX_SOFTIRQ", 2 },
234 { "NET_RX_SOFTIRQ", 3 },
235 { "BLOCK_SOFTIRQ", 4 },
236 { "BLOCK_IOPOLL_SOFTIRQ", 5 },
237 { "TASKLET_SOFTIRQ", 6 },
238 { "SCHED_SOFTIRQ", 7 },
239 { "HRTIMER_SOFTIRQ", 8 },
240 { "RCU_SOFTIRQ", 9 },
242 { "HRTIMER_NORESTART", 0 },
243 { "HRTIMER_RESTART", 1 },
246 unsigned long long eval_flag(const char *flag)
251 * Some flags in the format files do not get converted.
252 * If the flag is not numeric, see if it is something that
253 * we already know about.
255 if (isdigit(flag[0]))
256 return strtoull(flag, NULL, 0);
258 for (i = 0; i < (int)(sizeof(flags)/sizeof(flags[0])); i++)
259 if (strcmp(flags[i].name, flag) == 0)
260 return flags[i].value;