blob: b45141748af51b255755e42a2a0d3ec74afbd2bd [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
17static DEFINE_MUTEX(trace_event_mutex);
18static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
19
20static int next_event_type = __TRACE_LAST_TYPE + 1;
21
Steven Rostedt5ef841f2009-03-19 12:20:38 -040022enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
23{
24 struct trace_seq *s = &iter->seq;
25 struct trace_entry *entry = iter->ent;
26 struct bprint_entry *field;
27 int ret;
28
29 trace_assign_type(field, entry);
30
31 ret = trace_seq_bprintf(s, field->fmt, field->buf);
32 if (!ret)
33 return TRACE_TYPE_PARTIAL_LINE;
34
35 return TRACE_TYPE_HANDLED;
36}
37
38enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
39{
40 struct trace_seq *s = &iter->seq;
41 struct trace_entry *entry = iter->ent;
42 struct print_entry *field;
43 int ret;
44
45 trace_assign_type(field, entry);
46
47 ret = trace_seq_printf(s, "%s", field->buf);
48 if (!ret)
49 return TRACE_TYPE_PARTIAL_LINE;
50
51 return TRACE_TYPE_HANDLED;
52}
53
Steven Rostedtf0868d12008-12-23 23:24:12 -050054/**
55 * trace_seq_printf - sequence printing of trace information
56 * @s: trace sequence descriptor
57 * @fmt: printf format string
58 *
59 * The tracer may use either sequence operations or its own
60 * copy to user routines. To simplify formating of a trace
61 * trace_seq_printf is used to store strings into a special
62 * buffer (@s). Then the output may be either used by
63 * the sequencer or pulled into another buffer.
64 */
65int
66trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
67{
68 int len = (PAGE_SIZE - 1) - s->len;
69 va_list ap;
70 int ret;
71
72 if (!len)
73 return 0;
74
75 va_start(ap, fmt);
76 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
77 va_end(ap);
78
79 /* If we can't write it all, don't bother writing anything */
80 if (ret >= len)
81 return 0;
82
83 s->len += ret;
84
85 return len;
86}
87
Frederic Weisbecker769b0442009-03-06 17:21:49 +010088int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +010089{
90 int len = (PAGE_SIZE - 1) - s->len;
91 int ret;
92
93 if (!len)
94 return 0;
95
96 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
97
98 /* If we can't write it all, don't bother writing anything */
99 if (ret >= len)
100 return 0;
101
102 s->len += ret;
103
104 return len;
105}
106
Steven Rostedtf0868d12008-12-23 23:24:12 -0500107/**
108 * trace_seq_puts - trace sequence printing of simple string
109 * @s: trace sequence descriptor
110 * @str: simple string to record
111 *
112 * The tracer may use either the sequence operations or its own
113 * copy to user routines. This function records a simple string
114 * into a special buffer (@s) for later retrieval by a sequencer
115 * or other mechanism.
116 */
117int trace_seq_puts(struct trace_seq *s, const char *str)
118{
119 int len = strlen(str);
120
121 if (len > ((PAGE_SIZE - 1) - s->len))
122 return 0;
123
124 memcpy(s->buffer + s->len, str, len);
125 s->len += len;
126
127 return len;
128}
129
130int trace_seq_putc(struct trace_seq *s, unsigned char c)
131{
132 if (s->len >= (PAGE_SIZE - 1))
133 return 0;
134
135 s->buffer[s->len++] = c;
136
137 return 1;
138}
139
140int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
141{
142 if (len > ((PAGE_SIZE - 1) - s->len))
143 return 0;
144
145 memcpy(s->buffer + s->len, mem, len);
146 s->len += len;
147
148 return len;
149}
150
151int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
152{
153 unsigned char hex[HEX_CHARS];
154 unsigned char *data = mem;
155 int i, j;
156
157#ifdef __BIG_ENDIAN
158 for (i = 0, j = 0; i < len; i++) {
159#else
160 for (i = len-1, j = 0; i >= 0; i--) {
161#endif
162 hex[j++] = hex_asc_hi(data[i]);
163 hex[j++] = hex_asc_lo(data[i]);
164 }
165 hex[j++] = ' ';
166
167 return trace_seq_putmem(s, hex, j);
168}
169
170int trace_seq_path(struct trace_seq *s, struct path *path)
171{
172 unsigned char *p;
173
174 if (s->len >= (PAGE_SIZE - 1))
175 return 0;
176 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
177 if (!IS_ERR(p)) {
178 p = mangle_path(s->buffer + s->len, p, "\n");
179 if (p) {
180 s->len = p - s->buffer;
181 return 1;
182 }
183 } else {
184 s->buffer[s->len++] = '?';
185 return 1;
186 }
187
188 return 0;
189}
190
191#ifdef CONFIG_KRETPROBES
192static inline const char *kretprobed(const char *name)
193{
194 static const char tramp_name[] = "kretprobe_trampoline";
195 int size = sizeof(tramp_name);
196
197 if (strncmp(tramp_name, name, size) == 0)
198 return "[unknown/kretprobe'd]";
199 return name;
200}
201#else
202static inline const char *kretprobed(const char *name)
203{
204 return name;
205}
206#endif /* CONFIG_KRETPROBES */
207
208static int
209seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
210{
211#ifdef CONFIG_KALLSYMS
212 char str[KSYM_SYMBOL_LEN];
213 const char *name;
214
215 kallsyms_lookup(address, NULL, NULL, NULL, str);
216
217 name = kretprobed(str);
218
219 return trace_seq_printf(s, fmt, name);
220#endif
221 return 1;
222}
223
224static int
225seq_print_sym_offset(struct trace_seq *s, const char *fmt,
226 unsigned long address)
227{
228#ifdef CONFIG_KALLSYMS
229 char str[KSYM_SYMBOL_LEN];
230 const char *name;
231
232 sprint_symbol(str, address);
233 name = kretprobed(str);
234
235 return trace_seq_printf(s, fmt, name);
236#endif
237 return 1;
238}
239
240#ifndef CONFIG_64BIT
241# define IP_FMT "%08lx"
242#else
243# define IP_FMT "%016lx"
244#endif
245
246int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
247 unsigned long ip, unsigned long sym_flags)
248{
249 struct file *file = NULL;
250 unsigned long vmstart = 0;
251 int ret = 1;
252
253 if (mm) {
254 const struct vm_area_struct *vma;
255
256 down_read(&mm->mmap_sem);
257 vma = find_vma(mm, ip);
258 if (vma) {
259 file = vma->vm_file;
260 vmstart = vma->vm_start;
261 }
262 if (file) {
263 ret = trace_seq_path(s, &file->f_path);
264 if (ret)
265 ret = trace_seq_printf(s, "[+0x%lx]",
266 ip - vmstart);
267 }
268 up_read(&mm->mmap_sem);
269 }
270 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
271 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
272 return ret;
273}
274
275int
276seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
277 unsigned long sym_flags)
278{
279 struct mm_struct *mm = NULL;
280 int ret = 1;
281 unsigned int i;
282
283 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
284 struct task_struct *task;
285 /*
286 * we do the lookup on the thread group leader,
287 * since individual threads might have already quit!
288 */
289 rcu_read_lock();
290 task = find_task_by_vpid(entry->ent.tgid);
291 if (task)
292 mm = get_task_mm(task);
293 rcu_read_unlock();
294 }
295
296 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
297 unsigned long ip = entry->caller[i];
298
299 if (ip == ULONG_MAX || !ret)
300 break;
301 if (i && ret)
302 ret = trace_seq_puts(s, " <- ");
303 if (!ip) {
304 if (ret)
305 ret = trace_seq_puts(s, "??");
306 continue;
307 }
308 if (!ret)
309 break;
310 if (ret)
311 ret = seq_print_user_ip(s, mm, ip, sym_flags);
312 }
313
314 if (mm)
315 mmput(mm);
316 return ret;
317}
318
319int
320seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
321{
322 int ret;
323
324 if (!ip)
325 return trace_seq_printf(s, "0");
326
327 if (sym_flags & TRACE_ITER_SYM_OFFSET)
328 ret = seq_print_sym_offset(s, "%s", ip);
329 else
330 ret = seq_print_sym_short(s, "%s", ip);
331
332 if (!ret)
333 return 0;
334
335 if (sym_flags & TRACE_ITER_SYM_ADDR)
336 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
337 return ret;
338}
339
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200340static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200341lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
342{
343 int hardirq, softirq;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400344 char comm[TASK_COMM_LEN];
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200345
Steven Rostedt4ca53082009-03-16 19:20:15 -0400346 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200347 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
348 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200349
350 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
351 comm, entry->pid, cpu,
352 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
353 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
354 'X' : '.',
355 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
356 'N' : '.',
357 (hardirq && softirq) ? 'H' :
358 hardirq ? 'h' : softirq ? 's' : '.'))
359 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200360
361 if (entry->preempt_count)
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200362 return trace_seq_printf(s, "%x", entry->preempt_count);
363 return trace_seq_puts(s, ".");
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200364}
365
366static unsigned long preempt_mark_thresh = 100;
367
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200368static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200369lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
370 unsigned long rel_usecs)
371{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200372 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
373 rel_usecs > preempt_mark_thresh ? '!' :
374 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200375}
376
377int trace_print_context(struct trace_iterator *iter)
378{
379 struct trace_seq *s = &iter->seq;
380 struct trace_entry *entry = iter->ent;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200381 unsigned long long t = ns2usecs(iter->ts);
382 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
383 unsigned long secs = (unsigned long)t;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400384 char comm[TASK_COMM_LEN];
385
386 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200387
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200388 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500389 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200390}
391
392int trace_print_lat_context(struct trace_iterator *iter)
393{
394 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200395 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200396 struct trace_seq *s = &iter->seq;
397 struct trace_entry *entry = iter->ent,
398 *next_entry = trace_find_next_entry(iter, NULL,
399 &next_ts);
400 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
401 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
402 unsigned long rel_usecs;
403
404 if (!next_entry)
405 next_ts = iter->ts;
406 rel_usecs = ns2usecs(next_ts - iter->ts);
407
408 if (verbose) {
Steven Rostedt4ca53082009-03-16 19:20:15 -0400409 char comm[TASK_COMM_LEN];
410
411 trace_find_cmdline(entry->pid, comm);
412
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200413 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
414 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500415 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200416 entry->preempt_count, iter->idx,
417 ns2usecs(iter->ts),
418 abs_usecs / USEC_PER_MSEC,
419 abs_usecs % USEC_PER_MSEC,
420 rel_usecs / USEC_PER_MSEC,
421 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200422 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500423 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200424 if (ret)
425 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200426 }
427
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200428 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200429}
430
Steven Rostedtf633cef2008-12-23 23:24:13 -0500431static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
432
433static int task_state_char(unsigned long state)
434{
435 int bit = state ? __ffs(state) + 1 : 0;
436
437 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
438}
439
Steven Rostedtf0868d12008-12-23 23:24:12 -0500440/**
441 * ftrace_find_event - find a registered event
442 * @type: the type of event to look for
443 *
444 * Returns an event of type @type otherwise NULL
445 */
446struct trace_event *ftrace_find_event(int type)
447{
448 struct trace_event *event;
449 struct hlist_node *n;
450 unsigned key;
451
452 key = type & (EVENT_HASHSIZE - 1);
453
454 hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
455 if (event->type == type)
456 return event;
457 }
458
459 return NULL;
460}
461
462/**
463 * register_ftrace_event - register output for an event type
464 * @event: the event type to register
465 *
466 * Event types are stored in a hash and this hash is used to
467 * find a way to print an event. If the @event->type is set
468 * then it will use that type, otherwise it will assign a
469 * type to use.
470 *
471 * If you assign your own type, please make sure it is added
472 * to the trace_type enum in trace.h, to avoid collisions
473 * with the dynamic types.
474 *
475 * Returns the event type number or zero on error.
476 */
477int register_ftrace_event(struct trace_event *event)
478{
479 unsigned key;
480 int ret = 0;
481
482 mutex_lock(&trace_event_mutex);
483
484 if (!event->type)
485 event->type = next_event_type++;
486 else if (event->type > __TRACE_LAST_TYPE) {
487 printk(KERN_WARNING "Need to add type to trace.h\n");
488 WARN_ON(1);
489 }
490
491 if (ftrace_find_event(event->type))
492 goto out;
493
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200494 if (event->trace == NULL)
495 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200496 if (event->raw == NULL)
497 event->raw = trace_nop_print;
498 if (event->hex == NULL)
499 event->hex = trace_nop_print;
500 if (event->binary == NULL)
501 event->binary = trace_nop_print;
502
Steven Rostedtf0868d12008-12-23 23:24:12 -0500503 key = event->type & (EVENT_HASHSIZE - 1);
504
505 hlist_add_head_rcu(&event->node, &event_hash[key]);
506
507 ret = event->type;
508 out:
509 mutex_unlock(&trace_event_mutex);
510
511 return ret;
512}
513
514/**
515 * unregister_ftrace_event - remove a no longer used event
516 * @event: the event to remove
517 */
518int unregister_ftrace_event(struct trace_event *event)
519{
520 mutex_lock(&trace_event_mutex);
521 hlist_del(&event->node);
522 mutex_unlock(&trace_event_mutex);
523
524 return 0;
525}
Steven Rostedtf633cef2008-12-23 23:24:13 -0500526
527/*
528 * Standard events
529 */
530
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200531enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500532{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200533 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500534}
535
536/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200537static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500538{
539 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200540 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500541
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200542 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500543
544 if (!seq_print_ip_sym(s, field->ip, flags))
545 goto partial;
546
547 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
548 if (!trace_seq_printf(s, " <-"))
549 goto partial;
550 if (!seq_print_ip_sym(s,
551 field->parent_ip,
552 flags))
553 goto partial;
554 }
555 if (!trace_seq_printf(s, "\n"))
556 goto partial;
557
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200558 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500559
560 partial:
561 return TRACE_TYPE_PARTIAL_LINE;
562}
563
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200564static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500565{
566 struct ftrace_entry *field;
567
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200568 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500569
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200570 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800571 field->ip,
572 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500573 return TRACE_TYPE_PARTIAL_LINE;
574
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200575 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500576}
577
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200578static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500579{
580 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200581 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500582
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200583 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500584
585 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
586 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
587
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200588 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500589}
590
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200591static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500592{
593 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200594 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500595
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200596 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500597
598 SEQ_PUT_FIELD_RET(s, field->ip);
599 SEQ_PUT_FIELD_RET(s, field->parent_ip);
600
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200601 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500602}
603
604static struct trace_event trace_fn_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400605 .type = TRACE_FN,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500606 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500607 .raw = trace_fn_raw,
608 .hex = trace_fn_hex,
609 .binary = trace_fn_bin,
610};
611
612/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200613static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
614 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500615{
616 struct ctx_switch_entry *field;
Steven Rostedt4ca53082009-03-16 19:20:15 -0400617 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500618 int S, T;
619
Steven Rostedt4ca53082009-03-16 19:20:15 -0400620
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200621 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500622
623 T = task_state_char(field->next_state);
624 S = task_state_char(field->prev_state);
Steven Rostedt4ca53082009-03-16 19:20:15 -0400625 trace_find_cmdline(field->next_pid, comm);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200626 if (!trace_seq_printf(&iter->seq,
627 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800628 field->prev_pid,
629 field->prev_prio,
630 S, delim,
631 field->next_cpu,
632 field->next_pid,
633 field->next_prio,
634 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500635 return TRACE_TYPE_PARTIAL_LINE;
636
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200637 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500638}
639
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200640static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500641{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200642 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500643}
644
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200645static enum print_line_t trace_wake_print(struct trace_iterator *iter,
646 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500647{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200648 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500649}
650
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200651static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500652{
653 struct ctx_switch_entry *field;
654 int T;
655
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200656 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500657
658 if (!S)
659 task_state_char(field->prev_state);
660 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200661 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800662 field->prev_pid,
663 field->prev_prio,
664 S,
665 field->next_cpu,
666 field->next_pid,
667 field->next_prio,
668 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500669 return TRACE_TYPE_PARTIAL_LINE;
670
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200671 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500672}
673
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200674static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500675{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200676 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500677}
678
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200679static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500680{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200681 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500682}
683
684
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200685static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500686{
687 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200688 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500689 int T;
690
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200691 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500692
693 if (!S)
694 task_state_char(field->prev_state);
695 T = task_state_char(field->next_state);
696
697 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
698 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
699 SEQ_PUT_HEX_FIELD_RET(s, S);
700 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
701 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
702 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
703 SEQ_PUT_HEX_FIELD_RET(s, T);
704
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200705 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500706}
707
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200708static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500709{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200710 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500711}
712
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200713static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500714{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200715 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500716}
717
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200718static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
719 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500720{
721 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200722 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500723
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200724 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500725
726 SEQ_PUT_FIELD_RET(s, field->prev_pid);
727 SEQ_PUT_FIELD_RET(s, field->prev_prio);
728 SEQ_PUT_FIELD_RET(s, field->prev_state);
729 SEQ_PUT_FIELD_RET(s, field->next_pid);
730 SEQ_PUT_FIELD_RET(s, field->next_prio);
731 SEQ_PUT_FIELD_RET(s, field->next_state);
732
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200733 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500734}
735
736static struct trace_event trace_ctx_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400737 .type = TRACE_CTX,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500738 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500739 .raw = trace_ctx_raw,
740 .hex = trace_ctx_hex,
741 .binary = trace_ctxwake_bin,
742};
743
744static struct trace_event trace_wake_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400745 .type = TRACE_WAKE,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500746 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500747 .raw = trace_wake_raw,
748 .hex = trace_wake_hex,
749 .binary = trace_ctxwake_bin,
750};
751
752/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200753static enum print_line_t trace_special_print(struct trace_iterator *iter,
754 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500755{
756 struct special_entry *field;
757
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200758 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500759
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200760 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800761 field->arg1,
762 field->arg2,
763 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500764 return TRACE_TYPE_PARTIAL_LINE;
765
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200766 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500767}
768
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200769static enum print_line_t trace_special_hex(struct trace_iterator *iter,
770 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500771{
772 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200773 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500774
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200775 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500776
777 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
778 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
779 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
780
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200781 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500782}
783
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200784static enum print_line_t trace_special_bin(struct trace_iterator *iter,
785 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500786{
787 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200788 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500789
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200790 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500791
792 SEQ_PUT_FIELD_RET(s, field->arg1);
793 SEQ_PUT_FIELD_RET(s, field->arg2);
794 SEQ_PUT_FIELD_RET(s, field->arg3);
795
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200796 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500797}
798
799static struct trace_event trace_special_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400800 .type = TRACE_SPECIAL,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500801 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500802 .raw = trace_special_print,
803 .hex = trace_special_hex,
804 .binary = trace_special_bin,
805};
806
807/* TRACE_STACK */
808
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200809static enum print_line_t trace_stack_print(struct trace_iterator *iter,
810 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500811{
812 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200813 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500814 int i;
815
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200816 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500817
818 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
819 if (i) {
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800820 if (!trace_seq_puts(s, " <= "))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500821 goto partial;
822
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800823 if (!seq_print_ip_sym(s, field->caller[i], flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500824 goto partial;
825 }
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800826 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500827 goto partial;
828 }
829
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200830 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500831
832 partial:
833 return TRACE_TYPE_PARTIAL_LINE;
834}
835
836static struct trace_event trace_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400837 .type = TRACE_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500838 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500839 .raw = trace_special_print,
840 .hex = trace_special_hex,
841 .binary = trace_special_bin,
842};
843
844/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200845static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
846 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500847{
848 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200849 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500850
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200851 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800853 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500854 goto partial;
855
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800856 if (!trace_seq_putc(s, '\n'))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500857 goto partial;
858
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200859 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500860
861 partial:
862 return TRACE_TYPE_PARTIAL_LINE;
863}
864
865static struct trace_event trace_user_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400866 .type = TRACE_USER_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500867 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500868 .raw = trace_special_print,
869 .hex = trace_special_hex,
870 .binary = trace_special_bin,
871};
872
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100873/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100874static enum print_line_t
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100875trace_bprint_print(struct trace_iterator *iter, int flags)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100876{
877 struct trace_entry *entry = iter->ent;
878 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100879 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100880
881 trace_assign_type(field, entry);
882
883 if (!seq_print_ip_sym(s, field->ip, flags))
884 goto partial;
885
886 if (!trace_seq_puts(s, ": "))
887 goto partial;
888
889 if (!trace_seq_bprintf(s, field->fmt, field->buf))
890 goto partial;
891
892 return TRACE_TYPE_HANDLED;
893
894 partial:
895 return TRACE_TYPE_PARTIAL_LINE;
896}
897
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100898
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100899static enum print_line_t
900trace_bprint_raw(struct trace_iterator *iter, int flags)
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100901{
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100902 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100903 struct trace_seq *s = &iter->seq;
904
905 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100906
907 if (!trace_seq_printf(s, ": %lx : ", field->ip))
908 goto partial;
909
910 if (!trace_seq_bprintf(s, field->fmt, field->buf))
911 goto partial;
912
913 return TRACE_TYPE_HANDLED;
914
915 partial:
916 return TRACE_TYPE_PARTIAL_LINE;
917}
918
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100919
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100920static struct trace_event trace_bprint_event = {
921 .type = TRACE_BPRINT,
922 .trace = trace_bprint_print,
923 .raw = trace_bprint_raw,
924};
925
926/* TRACE_PRINT */
927static enum print_line_t trace_print_print(struct trace_iterator *iter,
928 int flags)
929{
930 struct print_entry *field;
931 struct trace_seq *s = &iter->seq;
932
933 trace_assign_type(field, iter->ent);
934
935 if (!seq_print_ip_sym(s, field->ip, flags))
936 goto partial;
937
938 if (!trace_seq_printf(s, ": %s", field->buf))
939 goto partial;
940
941 return TRACE_TYPE_HANDLED;
942
943 partial:
944 return TRACE_TYPE_PARTIAL_LINE;
945}
946
947static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
948{
949 struct print_entry *field;
950
951 trace_assign_type(field, iter->ent);
952
953 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
954 goto partial;
955
956 return TRACE_TYPE_HANDLED;
957
958 partial:
959 return TRACE_TYPE_PARTIAL_LINE;
960}
961
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100962static struct trace_event trace_print_event = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100963 .type = TRACE_PRINT,
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100964 .trace = trace_print_print,
965 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100966};
967
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100968
Steven Rostedtf633cef2008-12-23 23:24:13 -0500969static struct trace_event *events[] __initdata = {
970 &trace_fn_event,
971 &trace_ctx_event,
972 &trace_wake_event,
973 &trace_special_event,
974 &trace_stack_event,
975 &trace_user_stack_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100976 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500977 &trace_print_event,
978 NULL
979};
980
981__init static int init_events(void)
982{
983 struct trace_event *event;
984 int i, ret;
985
986 for (i = 0; events[i]; i++) {
987 event = events[i];
988
989 ret = register_ftrace_event(event);
990 if (!ret) {
991 printk(KERN_WARNING "event %d failed to register\n",
992 event->type);
993 WARN_ON_ONCE(1);
994 }
995 }
996
997 return 0;
998}
999device_initcall(init_events);