blob: a3b6e3fd7044623cb6a8719bf7f2e62f73ea61d7 [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 Rostedt0706f1c2009-03-23 23:12:58 -040022void trace_print_seq(struct seq_file *m, struct trace_seq *s)
23{
24 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
25
26 s->buffer[len] = 0;
27 seq_puts(m, s->buffer);
28
29 trace_seq_init(s);
30}
31
Steven Rostedt5ef841f2009-03-19 12:20:38 -040032enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
33{
34 struct trace_seq *s = &iter->seq;
35 struct trace_entry *entry = iter->ent;
36 struct bprint_entry *field;
37 int ret;
38
39 trace_assign_type(field, entry);
40
41 ret = trace_seq_bprintf(s, field->fmt, field->buf);
42 if (!ret)
43 return TRACE_TYPE_PARTIAL_LINE;
44
45 return TRACE_TYPE_HANDLED;
46}
47
48enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
49{
50 struct trace_seq *s = &iter->seq;
51 struct trace_entry *entry = iter->ent;
52 struct print_entry *field;
53 int ret;
54
55 trace_assign_type(field, entry);
56
57 ret = trace_seq_printf(s, "%s", field->buf);
58 if (!ret)
59 return TRACE_TYPE_PARTIAL_LINE;
60
61 return TRACE_TYPE_HANDLED;
62}
63
Steven Rostedtf0868d12008-12-23 23:24:12 -050064/**
65 * trace_seq_printf - sequence printing of trace information
66 * @s: trace sequence descriptor
67 * @fmt: printf format string
68 *
69 * The tracer may use either sequence operations or its own
70 * copy to user routines. To simplify formating of a trace
71 * trace_seq_printf is used to store strings into a special
72 * buffer (@s). Then the output may be either used by
73 * the sequencer or pulled into another buffer.
74 */
75int
76trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
77{
78 int len = (PAGE_SIZE - 1) - s->len;
79 va_list ap;
80 int ret;
81
82 if (!len)
83 return 0;
84
85 va_start(ap, fmt);
86 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
87 va_end(ap);
88
89 /* If we can't write it all, don't bother writing anything */
90 if (ret >= len)
91 return 0;
92
93 s->len += ret;
94
95 return len;
96}
97
Frederic Weisbecker769b0442009-03-06 17:21:49 +010098int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +010099{
100 int len = (PAGE_SIZE - 1) - s->len;
101 int ret;
102
103 if (!len)
104 return 0;
105
106 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
107
108 /* If we can't write it all, don't bother writing anything */
109 if (ret >= len)
110 return 0;
111
112 s->len += ret;
113
114 return len;
115}
116
Steven Rostedtf0868d12008-12-23 23:24:12 -0500117/**
118 * trace_seq_puts - trace sequence printing of simple string
119 * @s: trace sequence descriptor
120 * @str: simple string to record
121 *
122 * The tracer may use either the sequence operations or its own
123 * copy to user routines. This function records a simple string
124 * into a special buffer (@s) for later retrieval by a sequencer
125 * or other mechanism.
126 */
127int trace_seq_puts(struct trace_seq *s, const char *str)
128{
129 int len = strlen(str);
130
131 if (len > ((PAGE_SIZE - 1) - s->len))
132 return 0;
133
134 memcpy(s->buffer + s->len, str, len);
135 s->len += len;
136
137 return len;
138}
139
140int trace_seq_putc(struct trace_seq *s, unsigned char c)
141{
142 if (s->len >= (PAGE_SIZE - 1))
143 return 0;
144
145 s->buffer[s->len++] = c;
146
147 return 1;
148}
149
150int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
151{
152 if (len > ((PAGE_SIZE - 1) - s->len))
153 return 0;
154
155 memcpy(s->buffer + s->len, mem, len);
156 s->len += len;
157
158 return len;
159}
160
161int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
162{
163 unsigned char hex[HEX_CHARS];
164 unsigned char *data = mem;
165 int i, j;
166
167#ifdef __BIG_ENDIAN
168 for (i = 0, j = 0; i < len; i++) {
169#else
170 for (i = len-1, j = 0; i >= 0; i--) {
171#endif
172 hex[j++] = hex_asc_hi(data[i]);
173 hex[j++] = hex_asc_lo(data[i]);
174 }
175 hex[j++] = ' ';
176
177 return trace_seq_putmem(s, hex, j);
178}
179
180int trace_seq_path(struct trace_seq *s, struct path *path)
181{
182 unsigned char *p;
183
184 if (s->len >= (PAGE_SIZE - 1))
185 return 0;
186 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
187 if (!IS_ERR(p)) {
188 p = mangle_path(s->buffer + s->len, p, "\n");
189 if (p) {
190 s->len = p - s->buffer;
191 return 1;
192 }
193 } else {
194 s->buffer[s->len++] = '?';
195 return 1;
196 }
197
198 return 0;
199}
200
201#ifdef CONFIG_KRETPROBES
202static inline const char *kretprobed(const char *name)
203{
204 static const char tramp_name[] = "kretprobe_trampoline";
205 int size = sizeof(tramp_name);
206
207 if (strncmp(tramp_name, name, size) == 0)
208 return "[unknown/kretprobe'd]";
209 return name;
210}
211#else
212static inline const char *kretprobed(const char *name)
213{
214 return name;
215}
216#endif /* CONFIG_KRETPROBES */
217
218static int
219seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
220{
221#ifdef CONFIG_KALLSYMS
222 char str[KSYM_SYMBOL_LEN];
223 const char *name;
224
225 kallsyms_lookup(address, NULL, NULL, NULL, str);
226
227 name = kretprobed(str);
228
229 return trace_seq_printf(s, fmt, name);
230#endif
231 return 1;
232}
233
234static int
235seq_print_sym_offset(struct trace_seq *s, const char *fmt,
236 unsigned long address)
237{
238#ifdef CONFIG_KALLSYMS
239 char str[KSYM_SYMBOL_LEN];
240 const char *name;
241
242 sprint_symbol(str, address);
243 name = kretprobed(str);
244
245 return trace_seq_printf(s, fmt, name);
246#endif
247 return 1;
248}
249
250#ifndef CONFIG_64BIT
251# define IP_FMT "%08lx"
252#else
253# define IP_FMT "%016lx"
254#endif
255
256int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
257 unsigned long ip, unsigned long sym_flags)
258{
259 struct file *file = NULL;
260 unsigned long vmstart = 0;
261 int ret = 1;
262
263 if (mm) {
264 const struct vm_area_struct *vma;
265
266 down_read(&mm->mmap_sem);
267 vma = find_vma(mm, ip);
268 if (vma) {
269 file = vma->vm_file;
270 vmstart = vma->vm_start;
271 }
272 if (file) {
273 ret = trace_seq_path(s, &file->f_path);
274 if (ret)
275 ret = trace_seq_printf(s, "[+0x%lx]",
276 ip - vmstart);
277 }
278 up_read(&mm->mmap_sem);
279 }
280 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
281 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
282 return ret;
283}
284
285int
286seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
287 unsigned long sym_flags)
288{
289 struct mm_struct *mm = NULL;
290 int ret = 1;
291 unsigned int i;
292
293 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
294 struct task_struct *task;
295 /*
296 * we do the lookup on the thread group leader,
297 * since individual threads might have already quit!
298 */
299 rcu_read_lock();
300 task = find_task_by_vpid(entry->ent.tgid);
301 if (task)
302 mm = get_task_mm(task);
303 rcu_read_unlock();
304 }
305
306 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
307 unsigned long ip = entry->caller[i];
308
309 if (ip == ULONG_MAX || !ret)
310 break;
311 if (i && ret)
312 ret = trace_seq_puts(s, " <- ");
313 if (!ip) {
314 if (ret)
315 ret = trace_seq_puts(s, "??");
316 continue;
317 }
318 if (!ret)
319 break;
320 if (ret)
321 ret = seq_print_user_ip(s, mm, ip, sym_flags);
322 }
323
324 if (mm)
325 mmput(mm);
326 return ret;
327}
328
329int
330seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
331{
332 int ret;
333
334 if (!ip)
335 return trace_seq_printf(s, "0");
336
337 if (sym_flags & TRACE_ITER_SYM_OFFSET)
338 ret = seq_print_sym_offset(s, "%s", ip);
339 else
340 ret = seq_print_sym_short(s, "%s", ip);
341
342 if (!ret)
343 return 0;
344
345 if (sym_flags & TRACE_ITER_SYM_ADDR)
346 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
347 return ret;
348}
349
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200350static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200351lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
352{
353 int hardirq, softirq;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400354 char comm[TASK_COMM_LEN];
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200355
Steven Rostedt4ca530852009-03-16 19:20:15 -0400356 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200357 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
358 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200359
360 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
361 comm, entry->pid, cpu,
362 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
363 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
364 'X' : '.',
365 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
366 'N' : '.',
367 (hardirq && softirq) ? 'H' :
368 hardirq ? 'h' : softirq ? 's' : '.'))
369 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200370
371 if (entry->preempt_count)
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200372 return trace_seq_printf(s, "%x", entry->preempt_count);
373 return trace_seq_puts(s, ".");
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200374}
375
376static unsigned long preempt_mark_thresh = 100;
377
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200378static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200379lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
380 unsigned long rel_usecs)
381{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200382 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
383 rel_usecs > preempt_mark_thresh ? '!' :
384 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200385}
386
387int trace_print_context(struct trace_iterator *iter)
388{
389 struct trace_seq *s = &iter->seq;
390 struct trace_entry *entry = iter->ent;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200391 unsigned long long t = ns2usecs(iter->ts);
392 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
393 unsigned long secs = (unsigned long)t;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400394 char comm[TASK_COMM_LEN];
395
396 trace_find_cmdline(entry->pid, comm);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200397
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200398 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500399 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200400}
401
402int trace_print_lat_context(struct trace_iterator *iter)
403{
404 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200405 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200406 struct trace_seq *s = &iter->seq;
407 struct trace_entry *entry = iter->ent,
408 *next_entry = trace_find_next_entry(iter, NULL,
409 &next_ts);
410 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
411 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
412 unsigned long rel_usecs;
413
414 if (!next_entry)
415 next_ts = iter->ts;
416 rel_usecs = ns2usecs(next_ts - iter->ts);
417
418 if (verbose) {
Steven Rostedt4ca530852009-03-16 19:20:15 -0400419 char comm[TASK_COMM_LEN];
420
421 trace_find_cmdline(entry->pid, comm);
422
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200423 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
424 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500425 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200426 entry->preempt_count, iter->idx,
427 ns2usecs(iter->ts),
428 abs_usecs / USEC_PER_MSEC,
429 abs_usecs % USEC_PER_MSEC,
430 rel_usecs / USEC_PER_MSEC,
431 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200432 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500433 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200434 if (ret)
435 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200436 }
437
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200438 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200439}
440
Steven Rostedtf633cef2008-12-23 23:24:13 -0500441static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
442
443static int task_state_char(unsigned long state)
444{
445 int bit = state ? __ffs(state) + 1 : 0;
446
447 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
448}
449
Steven Rostedtf0868d12008-12-23 23:24:12 -0500450/**
451 * ftrace_find_event - find a registered event
452 * @type: the type of event to look for
453 *
454 * Returns an event of type @type otherwise NULL
455 */
456struct trace_event *ftrace_find_event(int type)
457{
458 struct trace_event *event;
459 struct hlist_node *n;
460 unsigned key;
461
462 key = type & (EVENT_HASHSIZE - 1);
463
464 hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
465 if (event->type == type)
466 return event;
467 }
468
469 return NULL;
470}
471
472/**
473 * register_ftrace_event - register output for an event type
474 * @event: the event type to register
475 *
476 * Event types are stored in a hash and this hash is used to
477 * find a way to print an event. If the @event->type is set
478 * then it will use that type, otherwise it will assign a
479 * type to use.
480 *
481 * If you assign your own type, please make sure it is added
482 * to the trace_type enum in trace.h, to avoid collisions
483 * with the dynamic types.
484 *
485 * Returns the event type number or zero on error.
486 */
487int register_ftrace_event(struct trace_event *event)
488{
489 unsigned key;
490 int ret = 0;
491
492 mutex_lock(&trace_event_mutex);
493
Peter Zijlstra28bea272009-03-19 20:26:14 +0100494 if (!event) {
495 ret = next_event_type++;
496 goto out;
497 }
498
Steven Rostedtf0868d12008-12-23 23:24:12 -0500499 if (!event->type)
500 event->type = next_event_type++;
501 else if (event->type > __TRACE_LAST_TYPE) {
502 printk(KERN_WARNING "Need to add type to trace.h\n");
503 WARN_ON(1);
504 }
505
506 if (ftrace_find_event(event->type))
507 goto out;
508
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200509 if (event->trace == NULL)
510 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200511 if (event->raw == NULL)
512 event->raw = trace_nop_print;
513 if (event->hex == NULL)
514 event->hex = trace_nop_print;
515 if (event->binary == NULL)
516 event->binary = trace_nop_print;
517
Steven Rostedtf0868d12008-12-23 23:24:12 -0500518 key = event->type & (EVENT_HASHSIZE - 1);
519
520 hlist_add_head_rcu(&event->node, &event_hash[key]);
521
522 ret = event->type;
523 out:
524 mutex_unlock(&trace_event_mutex);
525
526 return ret;
527}
528
529/**
530 * unregister_ftrace_event - remove a no longer used event
531 * @event: the event to remove
532 */
533int unregister_ftrace_event(struct trace_event *event)
534{
535 mutex_lock(&trace_event_mutex);
536 hlist_del(&event->node);
537 mutex_unlock(&trace_event_mutex);
538
539 return 0;
540}
Steven Rostedtf633cef2008-12-23 23:24:13 -0500541
542/*
543 * Standard events
544 */
545
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200546enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500547{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200548 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500549}
550
551/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200552static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500553{
554 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200555 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500556
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200557 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500558
559 if (!seq_print_ip_sym(s, field->ip, flags))
560 goto partial;
561
562 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
563 if (!trace_seq_printf(s, " <-"))
564 goto partial;
565 if (!seq_print_ip_sym(s,
566 field->parent_ip,
567 flags))
568 goto partial;
569 }
570 if (!trace_seq_printf(s, "\n"))
571 goto partial;
572
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200573 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500574
575 partial:
576 return TRACE_TYPE_PARTIAL_LINE;
577}
578
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200579static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500580{
581 struct ftrace_entry *field;
582
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200583 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500584
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200585 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800586 field->ip,
587 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500588 return TRACE_TYPE_PARTIAL_LINE;
589
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200590 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500591}
592
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200593static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500594{
595 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200596 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500597
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200598 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500599
600 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
601 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
602
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200603 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500604}
605
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200606static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500607{
608 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200609 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500610
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200611 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500612
613 SEQ_PUT_FIELD_RET(s, field->ip);
614 SEQ_PUT_FIELD_RET(s, field->parent_ip);
615
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200616 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500617}
618
619static struct trace_event trace_fn_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400620 .type = TRACE_FN,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500621 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500622 .raw = trace_fn_raw,
623 .hex = trace_fn_hex,
624 .binary = trace_fn_bin,
625};
626
627/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200628static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
629 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500630{
631 struct ctx_switch_entry *field;
Steven Rostedt4ca530852009-03-16 19:20:15 -0400632 char comm[TASK_COMM_LEN];
Steven Rostedtf633cef2008-12-23 23:24:13 -0500633 int S, T;
634
Steven Rostedt4ca530852009-03-16 19:20:15 -0400635
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200636 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500637
638 T = task_state_char(field->next_state);
639 S = task_state_char(field->prev_state);
Steven Rostedt4ca530852009-03-16 19:20:15 -0400640 trace_find_cmdline(field->next_pid, comm);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200641 if (!trace_seq_printf(&iter->seq,
642 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800643 field->prev_pid,
644 field->prev_prio,
645 S, delim,
646 field->next_cpu,
647 field->next_pid,
648 field->next_prio,
649 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500650 return TRACE_TYPE_PARTIAL_LINE;
651
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200652 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500653}
654
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200655static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500656{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200657 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500658}
659
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200660static enum print_line_t trace_wake_print(struct trace_iterator *iter,
661 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500662{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200663 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500664}
665
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200666static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500667{
668 struct ctx_switch_entry *field;
669 int T;
670
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200671 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500672
673 if (!S)
674 task_state_char(field->prev_state);
675 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200676 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800677 field->prev_pid,
678 field->prev_prio,
679 S,
680 field->next_cpu,
681 field->next_pid,
682 field->next_prio,
683 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500684 return TRACE_TYPE_PARTIAL_LINE;
685
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200686 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500687}
688
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200689static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500690{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200691 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500692}
693
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200694static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500695{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200696 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500697}
698
699
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200700static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500701{
702 struct ctx_switch_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 int T;
705
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200706 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500707
708 if (!S)
709 task_state_char(field->prev_state);
710 T = task_state_char(field->next_state);
711
712 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
713 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
714 SEQ_PUT_HEX_FIELD_RET(s, S);
715 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
716 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
717 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
718 SEQ_PUT_HEX_FIELD_RET(s, T);
719
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200720 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500721}
722
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200723static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500724{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200725 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500726}
727
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200728static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500729{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200730 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500731}
732
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200733static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
734 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500735{
736 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200737 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500738
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200739 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500740
741 SEQ_PUT_FIELD_RET(s, field->prev_pid);
742 SEQ_PUT_FIELD_RET(s, field->prev_prio);
743 SEQ_PUT_FIELD_RET(s, field->prev_state);
744 SEQ_PUT_FIELD_RET(s, field->next_pid);
745 SEQ_PUT_FIELD_RET(s, field->next_prio);
746 SEQ_PUT_FIELD_RET(s, field->next_state);
747
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200748 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500749}
750
751static struct trace_event trace_ctx_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400752 .type = TRACE_CTX,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500753 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500754 .raw = trace_ctx_raw,
755 .hex = trace_ctx_hex,
756 .binary = trace_ctxwake_bin,
757};
758
759static struct trace_event trace_wake_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400760 .type = TRACE_WAKE,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500761 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500762 .raw = trace_wake_raw,
763 .hex = trace_wake_hex,
764 .binary = trace_ctxwake_bin,
765};
766
767/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200768static enum print_line_t trace_special_print(struct trace_iterator *iter,
769 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500770{
771 struct special_entry *field;
772
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200773 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500774
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200775 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800776 field->arg1,
777 field->arg2,
778 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500779 return TRACE_TYPE_PARTIAL_LINE;
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_hex(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_HEX_FIELD_RET(s, field->arg1);
793 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
794 SEQ_PUT_HEX_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
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200799static enum print_line_t trace_special_bin(struct trace_iterator *iter,
800 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500801{
802 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200803 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500804
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200805 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500806
807 SEQ_PUT_FIELD_RET(s, field->arg1);
808 SEQ_PUT_FIELD_RET(s, field->arg2);
809 SEQ_PUT_FIELD_RET(s, field->arg3);
810
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200811 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500812}
813
814static struct trace_event trace_special_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400815 .type = TRACE_SPECIAL,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500816 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500817 .raw = trace_special_print,
818 .hex = trace_special_hex,
819 .binary = trace_special_bin,
820};
821
822/* TRACE_STACK */
823
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200824static enum print_line_t trace_stack_print(struct trace_iterator *iter,
825 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500826{
827 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200828 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500829 int i;
830
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200831 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500832
833 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
834 if (i) {
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800835 if (!trace_seq_puts(s, " <= "))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500836 goto partial;
837
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800838 if (!seq_print_ip_sym(s, field->caller[i], flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500839 goto partial;
840 }
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800841 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500842 goto partial;
843 }
844
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200845 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500846
847 partial:
848 return TRACE_TYPE_PARTIAL_LINE;
849}
850
851static struct trace_event trace_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400852 .type = TRACE_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500853 .trace = trace_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500854 .raw = trace_special_print,
855 .hex = trace_special_hex,
856 .binary = trace_special_bin,
857};
858
859/* TRACE_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200860static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
861 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500862{
863 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200864 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500865
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200866 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500867
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800868 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500869 goto partial;
870
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800871 if (!trace_seq_putc(s, '\n'))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500872 goto partial;
873
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200874 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500875
876 partial:
877 return TRACE_TYPE_PARTIAL_LINE;
878}
879
880static struct trace_event trace_user_stack_event = {
Steven Rostedtef180122009-03-10 14:10:56 -0400881 .type = TRACE_USER_STACK,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500882 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500883 .raw = trace_special_print,
884 .hex = trace_special_hex,
885 .binary = trace_special_bin,
886};
887
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100888/* TRACE_BPRINT */
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100889static enum print_line_t
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100890trace_bprint_print(struct trace_iterator *iter, int flags)
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100891{
892 struct trace_entry *entry = iter->ent;
893 struct trace_seq *s = &iter->seq;
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100894 struct bprint_entry *field;
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100895
896 trace_assign_type(field, entry);
897
898 if (!seq_print_ip_sym(s, field->ip, flags))
899 goto partial;
900
901 if (!trace_seq_puts(s, ": "))
902 goto partial;
903
904 if (!trace_seq_bprintf(s, field->fmt, field->buf))
905 goto partial;
906
907 return TRACE_TYPE_HANDLED;
908
909 partial:
910 return TRACE_TYPE_PARTIAL_LINE;
911}
912
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100913
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100914static enum print_line_t
915trace_bprint_raw(struct trace_iterator *iter, int flags)
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100916{
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100917 struct bprint_entry *field;
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100918 struct trace_seq *s = &iter->seq;
919
920 trace_assign_type(field, iter->ent);
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100921
922 if (!trace_seq_printf(s, ": %lx : ", field->ip))
923 goto partial;
924
925 if (!trace_seq_bprintf(s, field->fmt, field->buf))
926 goto partial;
927
928 return TRACE_TYPE_HANDLED;
929
930 partial:
931 return TRACE_TYPE_PARTIAL_LINE;
932}
933
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100934
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100935static struct trace_event trace_bprint_event = {
936 .type = TRACE_BPRINT,
937 .trace = trace_bprint_print,
938 .raw = trace_bprint_raw,
939};
940
941/* TRACE_PRINT */
942static enum print_line_t trace_print_print(struct trace_iterator *iter,
943 int flags)
944{
945 struct print_entry *field;
946 struct trace_seq *s = &iter->seq;
947
948 trace_assign_type(field, iter->ent);
949
950 if (!seq_print_ip_sym(s, field->ip, flags))
951 goto partial;
952
953 if (!trace_seq_printf(s, ": %s", field->buf))
954 goto partial;
955
956 return TRACE_TYPE_HANDLED;
957
958 partial:
959 return TRACE_TYPE_PARTIAL_LINE;
960}
961
962static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
963{
964 struct print_entry *field;
965
966 trace_assign_type(field, iter->ent);
967
968 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
969 goto partial;
970
971 return TRACE_TYPE_HANDLED;
972
973 partial:
974 return TRACE_TYPE_PARTIAL_LINE;
975}
976
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100977static struct trace_event trace_print_event = {
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100978 .type = TRACE_PRINT,
Frederic Weisbecker769b0442009-03-06 17:21:49 +0100979 .trace = trace_print_print,
980 .raw = trace_print_raw,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100981};
982
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100983
Steven Rostedtf633cef2008-12-23 23:24:13 -0500984static struct trace_event *events[] __initdata = {
985 &trace_fn_event,
986 &trace_ctx_event,
987 &trace_wake_event,
988 &trace_special_event,
989 &trace_stack_event,
990 &trace_user_stack_event,
Frederic Weisbecker48ead022009-03-12 18:24:49 +0100991 &trace_bprint_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500992 &trace_print_event,
993 NULL
994};
995
996__init static int init_events(void)
997{
998 struct trace_event *event;
999 int i, ret;
1000
1001 for (i = 0; events[i]; i++) {
1002 event = events[i];
1003
1004 ret = register_ftrace_event(event);
1005 if (!ret) {
1006 printk(KERN_WARNING "event %d failed to register\n",
1007 event->type);
1008 WARN_ON_ONCE(1);
1009 }
1010 }
1011
1012 return 0;
1013}
1014device_initcall(init_events);