blob: 8dadbbbd2d5c36be0399e69a417b069b5f05d965 [file] [log] [blame]
Steven Rostedtf0868d12008-12-23 23:24:12 -05001/*
2 * trace_output.c
3 *
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
5 *
6 */
7
8#include <linux/module.h>
9#include <linux/mutex.h>
10#include <linux/ftrace.h>
11
12#include "trace_output.h"
13
14/* must be a power of 2 */
15#define EVENT_HASHSIZE 128
16
Lai Jiangshan4f535962009-05-18 19:35:34 +080017static DECLARE_RWSEM(trace_event_mutex);
Steven Rostedtbe74b732009-05-26 20:25:22 +020018
19DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq);
Steven Whitehouseec081dd2009-06-01 15:53:35 +010020EXPORT_PER_CPU_SYMBOL(ftrace_event_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +020021
Steven Rostedtf0868d12008-12-23 23:24:12 -050022static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
23
24static int next_event_type = __TRACE_LAST_TYPE + 1;
25
Steven Rostedt0706f1c2009-03-23 23:12:58 -040026void trace_print_seq(struct seq_file *m, struct trace_seq *s)
27{
28 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
29
30 s->buffer[len] = 0;
31 seq_puts(m, s->buffer);
32
33 trace_seq_init(s);
34}
35
Steven Rostedt5ef841f2009-03-19 12:20:38 -040036enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
37{
38 struct trace_seq *s = &iter->seq;
39 struct trace_entry *entry = iter->ent;
40 struct bprint_entry *field;
41 int ret;
42
43 trace_assign_type(field, entry);
44
45 ret = trace_seq_bprintf(s, field->fmt, field->buf);
46 if (!ret)
47 return TRACE_TYPE_PARTIAL_LINE;
48
49 return TRACE_TYPE_HANDLED;
50}
51
52enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
53{
54 struct trace_seq *s = &iter->seq;
55 struct trace_entry *entry = iter->ent;
56 struct print_entry *field;
57 int ret;
58
59 trace_assign_type(field, entry);
60
61 ret = trace_seq_printf(s, "%s", field->buf);
62 if (!ret)
63 return TRACE_TYPE_PARTIAL_LINE;
64
65 return TRACE_TYPE_HANDLED;
66}
67
Steven Rostedtf0868d12008-12-23 23:24:12 -050068/**
69 * trace_seq_printf - sequence printing of trace information
70 * @s: trace sequence descriptor
71 * @fmt: printf format string
72 *
73 * The tracer may use either sequence operations or its own
74 * copy to user routines. To simplify formating of a trace
75 * trace_seq_printf is used to store strings into a special
76 * buffer (@s). Then the output may be either used by
77 * the sequencer or pulled into another buffer.
78 */
79int
80trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
81{
82 int len = (PAGE_SIZE - 1) - s->len;
83 va_list ap;
84 int ret;
85
86 if (!len)
87 return 0;
88
89 va_start(ap, fmt);
90 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
91 va_end(ap);
92
93 /* If we can't write it all, don't bother writing anything */
94 if (ret >= len)
95 return 0;
96
97 s->len += ret;
98
99 return len;
100}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400101EXPORT_SYMBOL_GPL(trace_seq_printf);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500102
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100103int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100104{
105 int len = (PAGE_SIZE - 1) - s->len;
106 int ret;
107
108 if (!len)
109 return 0;
110
111 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
112
113 /* If we can't write it all, don't bother writing anything */
114 if (ret >= len)
115 return 0;
116
117 s->len += ret;
118
119 return len;
120}
121
Steven Rostedtf0868d12008-12-23 23:24:12 -0500122/**
123 * trace_seq_puts - trace sequence printing of simple string
124 * @s: trace sequence descriptor
125 * @str: simple string to record
126 *
127 * The tracer may use either the sequence operations or its own
128 * copy to user routines. This function records a simple string
129 * into a special buffer (@s) for later retrieval by a sequencer
130 * or other mechanism.
131 */
132int trace_seq_puts(struct trace_seq *s, const char *str)
133{
134 int len = strlen(str);
135
136 if (len > ((PAGE_SIZE - 1) - s->len))
137 return 0;
138
139 memcpy(s->buffer + s->len, str, len);
140 s->len += len;
141
142 return len;
143}
144
145int trace_seq_putc(struct trace_seq *s, unsigned char c)
146{
147 if (s->len >= (PAGE_SIZE - 1))
148 return 0;
149
150 s->buffer[s->len++] = c;
151
152 return 1;
153}
154
Li Zefanb14b70a2009-03-27 10:21:00 +0800155int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500156{
157 if (len > ((PAGE_SIZE - 1) - s->len))
158 return 0;
159
160 memcpy(s->buffer + s->len, mem, len);
161 s->len += len;
162
163 return len;
164}
165
Li Zefanb14b70a2009-03-27 10:21:00 +0800166int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
Steven Rostedtf0868d12008-12-23 23:24:12 -0500167{
168 unsigned char hex[HEX_CHARS];
Li Zefanb14b70a2009-03-27 10:21:00 +0800169 const unsigned char *data = mem;
Steven Rostedtf0868d12008-12-23 23:24:12 -0500170 int i, j;
171
172#ifdef __BIG_ENDIAN
173 for (i = 0, j = 0; i < len; i++) {
174#else
175 for (i = len-1, j = 0; i >= 0; i--) {
176#endif
177 hex[j++] = hex_asc_hi(data[i]);
178 hex[j++] = hex_asc_lo(data[i]);
179 }
180 hex[j++] = ' ';
181
182 return trace_seq_putmem(s, hex, j);
183}
184
Eduard - Gabriel Munteanubdd6df62009-03-23 15:12:22 +0200185void *trace_seq_reserve(struct trace_seq *s, size_t len)
186{
187 void *ret;
188
189 if (len > ((PAGE_SIZE - 1) - s->len))
190 return NULL;
191
192 ret = s->buffer + s->len;
193 s->len += len;
194
195 return ret;
196}
197
Steven Rostedtf0868d12008-12-23 23:24:12 -0500198int trace_seq_path(struct trace_seq *s, struct path *path)
199{
200 unsigned char *p;
201
202 if (s->len >= (PAGE_SIZE - 1))
203 return 0;
204 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
205 if (!IS_ERR(p)) {
206 p = mangle_path(s->buffer + s->len, p, "\n");
207 if (p) {
208 s->len = p - s->buffer;
209 return 1;
210 }
211 } else {
212 s->buffer[s->len++] = '?';
213 return 1;
214 }
215
216 return 0;
217}
218
Steven Rostedtbe74b732009-05-26 20:25:22 +0200219const char *
220ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
221 unsigned long flags,
222 const struct trace_print_flags *flag_array)
223{
224 unsigned long mask;
225 const char *str;
226 int i;
227
228 trace_seq_init(p);
229
230 for (i = 0; flag_array[i].name && flags; i++) {
231
232 mask = flag_array[i].mask;
233 if ((flags & mask) != mask)
234 continue;
235
236 str = flag_array[i].name;
237 flags &= ~mask;
238 if (p->len && delim)
239 trace_seq_puts(p, delim);
240 trace_seq_puts(p, str);
241 }
242
243 /* check for left over flags */
244 if (flags) {
245 if (p->len && delim)
246 trace_seq_puts(p, delim);
247 trace_seq_printf(p, "0x%lx", flags);
248 }
249
250 trace_seq_putc(p, 0);
251
252 return p->buffer;
253}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100254EXPORT_SYMBOL(ftrace_print_flags_seq);
Steven Rostedtbe74b732009-05-26 20:25:22 +0200255
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400256const char *
257ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
258 const struct trace_print_flags *symbol_array)
259{
260 int i;
261
262 trace_seq_init(p);
263
264 for (i = 0; symbol_array[i].name; i++) {
265
266 if (val != symbol_array[i].mask)
267 continue;
268
269 trace_seq_puts(p, symbol_array[i].name);
270 break;
271 }
272
273 if (!p->len)
274 trace_seq_printf(p, "0x%lx", val);
275
276 trace_seq_putc(p, 0);
277
278 return p->buffer;
279}
Steven Whitehouseec081dd2009-06-01 15:53:35 +0100280EXPORT_SYMBOL(ftrace_print_symbols_seq);
Steven Rostedt0f4fc292009-05-20 19:21:47 -0400281
Steven Rostedtf0868d12008-12-23 23:24:12 -0500282#ifdef CONFIG_KRETPROBES
283static inline const char *kretprobed(const char *name)
284{
285 static const char tramp_name[] = "kretprobe_trampoline";
286 int size = sizeof(tramp_name);
287
288 if (strncmp(tramp_name, name, size) == 0)
289 return "[unknown/kretprobe'd]";
290 return name;
291}
292#else
293static inline const char *kretprobed(const char *name)
294{
295 return name;
296}
297#endif /* CONFIG_KRETPROBES */
298
299static int
300seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
301{
302#ifdef CONFIG_KALLSYMS
303 char str[KSYM_SYMBOL_LEN];
304 const char *name;
305
306 kallsyms_lookup(address, NULL, NULL, NULL, str);
307
308 name = kretprobed(str);
309
310 return trace_seq_printf(s, fmt, name);
311#endif
312 return 1;
313}
314
315static int
316seq_print_sym_offset(struct trace_seq *s, const char *fmt,
317 unsigned long address)
318{
319#ifdef CONFIG_KALLSYMS
320 char str[KSYM_SYMBOL_LEN];
321 const char *name;
322
323 sprint_symbol(str, address);
324 name = kretprobed(str);
325
326 return trace_seq_printf(s, fmt, name);
327#endif
328 return 1;
329}
330
331#ifndef CONFIG_64BIT
332# define IP_FMT "%08lx"
333#else
334# define IP_FMT "%016lx"
335#endif
336
337int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
338 unsigned long ip, unsigned long sym_flags)
339{
340 struct file *file = NULL;
341 unsigned long vmstart = 0;
342 int ret = 1;
343
344 if (mm) {
345 const struct vm_area_struct *vma;
346
347 down_read(&mm->mmap_sem);
348 vma = find_vma(mm, ip);
349 if (vma) {
350 file = vma->vm_file;
351 vmstart = vma->vm_start;
352 }
353 if (file) {
354 ret = trace_seq_path(s, &file->f_path);
355 if (ret)
356 ret = trace_seq_printf(s, "[+0x%lx]",
357 ip - vmstart);
358 }
359 up_read(&mm->mmap_sem);
360 }
361 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
362 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
363 return ret;
364}
365
366int
367seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
368 unsigned long sym_flags)
369{
370 struct mm_struct *mm = NULL;
371 int ret = 1;
372 unsigned int i;
373
374 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
375 struct task_struct *task;
376 /*
377 * we do the lookup on the thread group leader,
378 * since individual threads might have already quit!
379 */
380 rcu_read_lock();
381 task = find_task_by_vpid(entry->ent.tgid);
382 if (task)
383 mm = get_task_mm(task);
384 rcu_read_unlock();
385 }
386
387 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
388 unsigned long ip = entry->caller[i];
389
390 if (ip == ULONG_MAX || !ret)
391 break;
walimis048dc502009-06-03 16:01:30 +0800392 if (ret)
393 ret = trace_seq_puts(s, " => ");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500394 if (!ip) {
395 if (ret)
396 ret = trace_seq_puts(s, "??");
walimis048dc502009-06-03 16:01:30 +0800397 if (ret)
398 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500399 continue;
400 }
401 if (!ret)
402 break;
403 if (ret)
404 ret = seq_print_user_ip(s, mm, ip, sym_flags);
walimis048dc502009-06-03 16:01:30 +0800405 ret = trace_seq_puts(s, "\n");
Steven Rostedtf0868d12008-12-23 23:24:12 -0500406 }
407
408 if (mm)
409 mmput(mm);
410 return ret;
411}
412
413int
414seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
415{
416 int ret;
417
418 if (!ip)
419 return trace_seq_printf(s, "0");
420
421 if (sym_flags & TRACE_ITER_SYM_OFFSET)
422 ret = seq_print_sym_offset(s, "%s", ip);
423 else
424 ret = seq_print_sym_short(s, "%s", ip);
425
426 if (!ret)
427 return 0;
428
429 if (sym_flags & TRACE_ITER_SYM_ADDR)
430 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
431 return ret;
432}
433
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200434static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200435lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
436{
437 int hardirq, softirq;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400438 char comm[TASK_COMM_LEN];
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200439
Steven Rostedt4ca53082009-03-16 19:20:15 -0400440 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200441 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
442 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200443
444 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
445 comm, entry->pid, cpu,
446 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
447 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
448 'X' : '.',
449 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
450 'N' : '.',
451 (hardirq && softirq) ? 'H' :
452 hardirq ? 'h' : softirq ? 's' : '.'))
453 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200454
455 if (entry->preempt_count)
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200456 return trace_seq_printf(s, "%x", entry->preempt_count);
457 return trace_seq_puts(s, ".");
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200458}
459
460static unsigned long preempt_mark_thresh = 100;
461
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200462static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200463lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
464 unsigned long rel_usecs)
465{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200466 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
467 rel_usecs > preempt_mark_thresh ? '!' :
468 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200469}
470
471int trace_print_context(struct trace_iterator *iter)
472{
473 struct trace_seq *s = &iter->seq;
474 struct trace_entry *entry = iter->ent;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200475 unsigned long long t = ns2usecs(iter->ts);
476 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
477 unsigned long secs = (unsigned long)t;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400478 char comm[TASK_COMM_LEN];
479
480 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200481
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200482 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500483 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200484}
485
486int trace_print_lat_context(struct trace_iterator *iter)
487{
488 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200489 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200490 struct trace_seq *s = &iter->seq;
491 struct trace_entry *entry = iter->ent,
492 *next_entry = trace_find_next_entry(iter, NULL,
493 &next_ts);
494 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
495 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
496 unsigned long rel_usecs;
497
498 if (!next_entry)
499 next_ts = iter->ts;
500 rel_usecs = ns2usecs(next_ts - iter->ts);
501
502 if (verbose) {
Steven Rostedt4ca53082009-03-16 19:20:15 -0400503 char comm[TASK_COMM_LEN];
504
505 trace_find_cmdline(entry->pid, comm);
506
Lai Jiangshancf8e3472009-03-30 13:48:00 +0800507 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200508 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500509 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200510 entry->preempt_count, iter->idx,
511 ns2usecs(iter->ts),
512 abs_usecs / USEC_PER_MSEC,
513 abs_usecs % USEC_PER_MSEC,
514 rel_usecs / USEC_PER_MSEC,
515 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200516 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500517 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200518 if (ret)
519 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200520 }
521
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200522 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200523}
524
Steven Rostedtf633cef2008-12-23 23:24:13 -0500525static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
526
527static int task_state_char(unsigned long state)
528{
529 int bit = state ? __ffs(state) + 1 : 0;
530
531 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
532}
533
Steven Rostedtf0868d12008-12-23 23:24:12 -0500534/**
535 * ftrace_find_event - find a registered event
536 * @type: the type of event to look for
537 *
538 * Returns an event of type @type otherwise NULL
Lai Jiangshan4f535962009-05-18 19:35:34 +0800539 * Called with trace_event_read_lock() held.
Steven Rostedtf0868d12008-12-23 23:24:12 -0500540 */
541struct trace_event *ftrace_find_event(int type)
542{
543 struct trace_event *event;
544 struct hlist_node *n;
545 unsigned key;
546
547 key = type & (EVENT_HASHSIZE - 1);
548
Lai Jiangshan4f535962009-05-18 19:35:34 +0800549 hlist_for_each_entry(event, n, &event_hash[key], node) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500550 if (event->type == type)
551 return event;
552 }
553
554 return NULL;
555}
556
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400557static LIST_HEAD(ftrace_event_list);
558
559static int trace_search_list(struct list_head **list)
560{
561 struct trace_event *e;
562 int last = __TRACE_LAST_TYPE;
563
564 if (list_empty(&ftrace_event_list)) {
565 *list = &ftrace_event_list;
566 return last + 1;
567 }
568
569 /*
570 * We used up all possible max events,
571 * lets see if somebody freed one.
572 */
573 list_for_each_entry(e, &ftrace_event_list, list) {
574 if (e->type != last + 1)
575 break;
576 last++;
577 }
578
579 /* Did we used up all 65 thousand events??? */
580 if ((last + 1) > FTRACE_MAX_EVENT)
581 return 0;
582
583 *list = &e->list;
584 return last + 1;
585}
586
Lai Jiangshan4f535962009-05-18 19:35:34 +0800587void trace_event_read_lock(void)
588{
589 down_read(&trace_event_mutex);
590}
591
592void trace_event_read_unlock(void)
593{
594 up_read(&trace_event_mutex);
595}
596
Steven Rostedtf0868d12008-12-23 23:24:12 -0500597/**
598 * register_ftrace_event - register output for an event type
599 * @event: the event type to register
600 *
601 * Event types are stored in a hash and this hash is used to
602 * find a way to print an event. If the @event->type is set
603 * then it will use that type, otherwise it will assign a
604 * type to use.
605 *
606 * If you assign your own type, please make sure it is added
607 * to the trace_type enum in trace.h, to avoid collisions
608 * with the dynamic types.
609 *
610 * Returns the event type number or zero on error.
611 */
612int register_ftrace_event(struct trace_event *event)
613{
614 unsigned key;
615 int ret = 0;
616
Lai Jiangshan4f535962009-05-18 19:35:34 +0800617 down_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500618
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400619 if (WARN_ON(!event))
Peter Zijlstra28bea272009-03-19 20:26:14 +0100620 goto out;
Peter Zijlstra28bea272009-03-19 20:26:14 +0100621
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400622 INIT_LIST_HEAD(&event->list);
623
624 if (!event->type) {
Jaswinder Singh Rajput48dd0fe2009-05-06 15:45:45 +0530625 struct list_head *list = NULL;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400626
627 if (next_event_type > FTRACE_MAX_EVENT) {
628
629 event->type = trace_search_list(&list);
630 if (!event->type)
631 goto out;
632
633 } else {
634
635 event->type = next_event_type++;
636 list = &ftrace_event_list;
637 }
638
639 if (WARN_ON(ftrace_find_event(event->type)))
640 goto out;
641
642 list_add_tail(&event->list, list);
643
644 } else if (event->type > __TRACE_LAST_TYPE) {
Steven Rostedtf0868d12008-12-23 23:24:12 -0500645 printk(KERN_WARNING "Need to add type to trace.h\n");
646 WARN_ON(1);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500647 goto out;
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400648 } else {
649 /* Is this event already used */
650 if (ftrace_find_event(event->type))
651 goto out;
652 }
Steven Rostedtf0868d12008-12-23 23:24:12 -0500653
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200654 if (event->trace == NULL)
655 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200656 if (event->raw == NULL)
657 event->raw = trace_nop_print;
658 if (event->hex == NULL)
659 event->hex = trace_nop_print;
660 if (event->binary == NULL)
661 event->binary = trace_nop_print;
662
Steven Rostedtf0868d12008-12-23 23:24:12 -0500663 key = event->type & (EVENT_HASHSIZE - 1);
664
Lai Jiangshan4f535962009-05-18 19:35:34 +0800665 hlist_add_head(&event->node, &event_hash[key]);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500666
667 ret = event->type;
668 out:
Lai Jiangshan4f535962009-05-18 19:35:34 +0800669 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500670
671 return ret;
672}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400673EXPORT_SYMBOL_GPL(register_ftrace_event);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500674
675/**
676 * unregister_ftrace_event - remove a no longer used event
677 * @event: the event to remove
678 */
679int unregister_ftrace_event(struct trace_event *event)
680{
Lai Jiangshan4f535962009-05-18 19:35:34 +0800681 down_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500682 hlist_del(&event->node);
Steven Rostedt060fa5c82009-04-24 12:20:52 -0400683 list_del(&event->list);
Lai Jiangshan4f535962009-05-18 19:35:34 +0800684 up_write(&trace_event_mutex);
Steven Rostedtf0868d12008-12-23 23:24:12 -0500685
686 return 0;
687}
Steven Rostedt17c873e2009-04-10 18:12:50 -0400688EXPORT_SYMBOL_GPL(unregister_ftrace_event);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500689
690/*
691 * Standard events
692 */
693
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200694enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500695{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200696 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500697}
698
699/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200700static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500701{
702 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200703 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500704
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200705 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500706
707 if (!seq_print_ip_sym(s, field->ip, flags))
708 goto partial;
709
710 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
711 if (!trace_seq_printf(s, " <-"))
712 goto partial;
713 if (!seq_print_ip_sym(s,
714 field->parent_ip,
715 flags))
716 goto partial;
717 }
718 if (!trace_seq_printf(s, "\n"))
719 goto partial;
720
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200721 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500722
723 partial:
724 return TRACE_TYPE_PARTIAL_LINE;
725}
726
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200727static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500728{
729 struct ftrace_entry *field;
730
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200731 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500732
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200733 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800734 field->ip,
735 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500736 return TRACE_TYPE_PARTIAL_LINE;
737
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200738 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500739}
740
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200741static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500742{
743 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200744 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500745
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200746 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500747
748 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
749 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
750
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200751 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500752}
753
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200754static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500755{
756 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200757 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500758
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200759 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500760
761 SEQ_PUT_FIELD_RET(s, field->ip);
762 SEQ_PUT_FIELD_RET(s, field->parent_ip);
763
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200764 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500765}
766
767static struct trace_event trace_fn_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400768 .type = TRACE_FN,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500769 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500770 .raw = trace_fn_raw,
771 .hex = trace_fn_hex,
772 .binary = trace_fn_bin,
773};
774
775/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200776static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
777 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500778{
779 struct ctx_switch_entry *field;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400780 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500781 int S, T;
782
Steven Rostedt4ca53082009-03-16 19:20:15 -0400783
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200784 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500785
786 T = task_state_char(field->next_state);
787 S = task_state_char(field->prev_state);
Steven Rostedt4ca53082009-03-16 19:20:15 -0400788 trace_find_cmdline(field->next_pid, comm);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200789 if (!trace_seq_printf(&iter->seq,
790 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800791 field->prev_pid,
792 field->prev_prio,
793 S, delim,
794 field->next_cpu,
795 field->next_pid,
796 field->next_prio,
797 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500798 return TRACE_TYPE_PARTIAL_LINE;
799
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200800 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500801}
802
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200803static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500804{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200805 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500806}
807
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200808static enum print_line_t trace_wake_print(struct trace_iterator *iter,
809 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500810{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200811 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500812}
813
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200814static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500815{
816 struct ctx_switch_entry *field;
817 int T;
818
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200819 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500820
821 if (!S)
822 task_state_char(field->prev_state);
823 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200824 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800825 field->prev_pid,
826 field->prev_prio,
827 S,
828 field->next_cpu,
829 field->next_pid,
830 field->next_prio,
831 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500832 return TRACE_TYPE_PARTIAL_LINE;
833
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200834 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500835}
836
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200837static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500838{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200839 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500840}
841
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200842static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500843{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200844 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500845}
846
847
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200848static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500849{
850 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200851 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852 int T;
853
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200854 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500855
856 if (!S)
857 task_state_char(field->prev_state);
858 T = task_state_char(field->next_state);
859
860 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
861 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
862 SEQ_PUT_HEX_FIELD_RET(s, S);
863 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
864 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
865 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
866 SEQ_PUT_HEX_FIELD_RET(s, T);
867
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200868 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500869}
870
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200871static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500872{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200873 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500874}
875
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200876static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500877{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200878 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500879}
880
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200881static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
882 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500883{
884 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200885 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500886
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200887 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500888
889 SEQ_PUT_FIELD_RET(s, field->prev_pid);
890 SEQ_PUT_FIELD_RET(s, field->prev_prio);
891 SEQ_PUT_FIELD_RET(s, field->prev_state);
892 SEQ_PUT_FIELD_RET(s, field->next_pid);
893 SEQ_PUT_FIELD_RET(s, field->next_prio);
894 SEQ_PUT_FIELD_RET(s, field->next_state);
895
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200896 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500897}
898
899static struct trace_event trace_ctx_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400900 .type = TRACE_CTX,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500901 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500902 .raw = trace_ctx_raw,
903 .hex = trace_ctx_hex,
904 .binary = trace_ctxwake_bin,
905};
906
907static struct trace_event trace_wake_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400908 .type = TRACE_WAKE,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500909 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500910 .raw = trace_wake_raw,
911 .hex = trace_wake_hex,
912 .binary = trace_ctxwake_bin,
913};
914
915/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200916static enum print_line_t trace_special_print(struct trace_iterator *iter,
917 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500918{
919 struct special_entry *field;
920
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200921 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500922
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200923 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800924 field->arg1,
925 field->arg2,
926 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500927 return TRACE_TYPE_PARTIAL_LINE;
928
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200929 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500930}
931
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200932static enum print_line_t trace_special_hex(struct trace_iterator *iter,
933 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500934{
935 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200936 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500937
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200938 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500939
940 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
941 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
942 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
943
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200944 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500945}
946
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200947static enum print_line_t trace_special_bin(struct trace_iterator *iter,
948 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500949{
950 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200951 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500952
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200953 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500954
955 SEQ_PUT_FIELD_RET(s, field->arg1);
956 SEQ_PUT_FIELD_RET(s, field->arg2);
957 SEQ_PUT_FIELD_RET(s, field->arg3);
958
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200959 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500960}
961
962static struct trace_event trace_special_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400963 .type = TRACE_SPECIAL,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500964 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500965 .raw = trace_special_print,
966 .hex = trace_special_hex,
967 .binary = trace_special_bin,
968};
969
970/* TRACE_STACK */
971
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200972static enum print_line_t trace_stack_print(struct trace_iterator *iter,
973 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500974{
975 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200976 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500977 int i;
978
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200979 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500980
walimisf11b3f42009-06-03 16:01:29 +0800981 if (!trace_seq_puts(s, "\n"))
982 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500983 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
walimisf11b3f42009-06-03 16:01:29 +0800984 if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
Steven Rostedt1ec7c482009-05-14 23:40:06 -0400985 break;
walimisf11b3f42009-06-03 16:01:29 +0800986 if (!trace_seq_puts(s, " => "))
987 goto partial;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500988
walimisf11b3f42009-06-03 16:01:29 +0800989 if (!seq_print_ip_sym(s, field->caller[i], flags))
990 goto partial;
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800991 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500992 goto partial;
993 }
994
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200995 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500996
997 partial:
998 return TRACE_TYPE_PARTIAL_LINE;
999}
1000
1001static struct trace_event trace_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001002 .type = TRACE_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001003 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001004 .raw = trace_special_print,
1005 .hex = trace_special_hex,
1006 .binary = trace_special_bin,
1007};
1008
1009/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -02001010static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1011 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -05001012{
1013 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001014 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001015
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -02001016 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -05001017
walimis048dc502009-06-03 16:01:30 +08001018 if (!trace_seq_putc(s, '\n'))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001019 goto partial;
1020
walimis048dc502009-06-03 16:01:30 +08001021 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -05001022 goto partial;
1023
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -02001024 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -05001025
1026 partial:
1027 return TRACE_TYPE_PARTIAL_LINE;
1028}
1029
1030static struct trace_event trace_user_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -04001031 .type = TRACE_USER_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001032 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001033 .raw = trace_special_print,
1034 .hex = trace_special_hex,
1035 .binary = trace_special_bin,
1036};
1037
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001038/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001039static enum print_line_t
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001040trace_bprint_print(struct trace_iterator *iter, int flags)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001041{
1042 struct trace_entry *entry = iter->ent;
1043 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001044 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001045
1046 trace_assign_type(field, entry);
1047
1048 if (!seq_print_ip_sym(s, field->ip, flags))
1049 goto partial;
1050
1051 if (!trace_seq_puts(s, ": "))
1052 goto partial;
1053
1054 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1055 goto partial;
1056
1057 return TRACE_TYPE_HANDLED;
1058
1059 partial:
1060 return TRACE_TYPE_PARTIAL_LINE;
1061}
1062
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001063
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001064static enum print_line_t
1065trace_bprint_raw(struct trace_iterator *iter, int flags)
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001066{
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001067 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001068 struct trace_seq *s = &iter->seq;
1069
1070 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001071
1072 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1073 goto partial;
1074
1075 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1076 goto partial;
1077
1078 return TRACE_TYPE_HANDLED;
1079
1080 partial:
1081 return TRACE_TYPE_PARTIAL_LINE;
1082}
1083
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001084
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001085static struct trace_event trace_bprint_event = {
1086 .type = TRACE_BPRINT,
1087 .trace = trace_bprint_print,
1088 .raw = trace_bprint_raw,
1089};
1090
1091/* TRACE_PRINT */
1092static enum print_line_t trace_print_print(struct trace_iterator *iter,
1093 int flags)
1094{
1095 struct print_entry *field;
1096 struct trace_seq *s = &iter->seq;
1097
1098 trace_assign_type(field, iter->ent);
1099
1100 if (!seq_print_ip_sym(s, field->ip, flags))
1101 goto partial;
1102
1103 if (!trace_seq_printf(s, ": %s", field->buf))
1104 goto partial;
1105
1106 return TRACE_TYPE_HANDLED;
1107
1108 partial:
1109 return TRACE_TYPE_PARTIAL_LINE;
1110}
1111
1112static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
1113{
1114 struct print_entry *field;
1115
1116 trace_assign_type(field, iter->ent);
1117
1118 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1119 goto partial;
1120
1121 return TRACE_TYPE_HANDLED;
1122
1123 partial:
1124 return TRACE_TYPE_PARTIAL_LINE;
1125}
1126
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001127static struct trace_event trace_print_event = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001128 .type = TRACE_PRINT,
Frederic Weisbecker769b0442009-03-06 17:21:49 +01001129 .trace = trace_print_print,
1130 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +01001131};
1132
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001133
Steven Rostedtf633cef2008-12-23 23:24:13 -05001134static struct trace_event *events[] __initdata = {
1135 &trace_fn_event,
1136 &trace_ctx_event,
1137 &trace_wake_event,
1138 &trace_special_event,
1139 &trace_stack_event,
1140 &trace_user_stack_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +01001141 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -05001142 &trace_print_event,
1143 NULL
1144};
1145
1146__init static int init_events(void)
1147{
1148 struct trace_event *event;
1149 int i, ret;
1150
1151 for (i = 0; events[i]; i++) {
1152 event = events[i];
1153
1154 ret = register_ftrace_event(event);
1155 if (!ret) {
1156 printk(KERN_WARNING "event %d failed to register\n",
1157 event->type);
1158 WARN_ON_ONCE(1);
1159 }
1160 }
1161
1162 return 0;
1163}
1164device_initcall(init_events);