blob: 4ab71201862e763e2b4f3d7a89b6215b52b93fe6 [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
22/**
23 * trace_seq_printf - sequence printing of trace information
24 * @s: trace sequence descriptor
25 * @fmt: printf format string
26 *
27 * The tracer may use either sequence operations or its own
28 * copy to user routines. To simplify formating of a trace
29 * trace_seq_printf is used to store strings into a special
30 * buffer (@s). Then the output may be either used by
31 * the sequencer or pulled into another buffer.
32 */
33int
34trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
35{
36 int len = (PAGE_SIZE - 1) - s->len;
37 va_list ap;
38 int ret;
39
40 if (!len)
41 return 0;
42
43 va_start(ap, fmt);
44 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
45 va_end(ap);
46
47 /* If we can't write it all, don't bother writing anything */
48 if (ret >= len)
49 return 0;
50
51 s->len += ret;
52
53 return len;
54}
55
Lai Jiangshan1427cdf2009-03-06 17:21:47 +010056static int
57trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
58{
59 int len = (PAGE_SIZE - 1) - s->len;
60 int ret;
61
62 if (!len)
63 return 0;
64
65 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
66
67 /* If we can't write it all, don't bother writing anything */
68 if (ret >= len)
69 return 0;
70
71 s->len += ret;
72
73 return len;
74}
75
Steven Rostedtf0868d12008-12-23 23:24:12 -050076/**
77 * trace_seq_puts - trace sequence printing of simple string
78 * @s: trace sequence descriptor
79 * @str: simple string to record
80 *
81 * The tracer may use either the sequence operations or its own
82 * copy to user routines. This function records a simple string
83 * into a special buffer (@s) for later retrieval by a sequencer
84 * or other mechanism.
85 */
86int trace_seq_puts(struct trace_seq *s, const char *str)
87{
88 int len = strlen(str);
89
90 if (len > ((PAGE_SIZE - 1) - s->len))
91 return 0;
92
93 memcpy(s->buffer + s->len, str, len);
94 s->len += len;
95
96 return len;
97}
98
99int trace_seq_putc(struct trace_seq *s, unsigned char c)
100{
101 if (s->len >= (PAGE_SIZE - 1))
102 return 0;
103
104 s->buffer[s->len++] = c;
105
106 return 1;
107}
108
109int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
110{
111 if (len > ((PAGE_SIZE - 1) - s->len))
112 return 0;
113
114 memcpy(s->buffer + s->len, mem, len);
115 s->len += len;
116
117 return len;
118}
119
120int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
121{
122 unsigned char hex[HEX_CHARS];
123 unsigned char *data = mem;
124 int i, j;
125
126#ifdef __BIG_ENDIAN
127 for (i = 0, j = 0; i < len; i++) {
128#else
129 for (i = len-1, j = 0; i >= 0; i--) {
130#endif
131 hex[j++] = hex_asc_hi(data[i]);
132 hex[j++] = hex_asc_lo(data[i]);
133 }
134 hex[j++] = ' ';
135
136 return trace_seq_putmem(s, hex, j);
137}
138
139int trace_seq_path(struct trace_seq *s, struct path *path)
140{
141 unsigned char *p;
142
143 if (s->len >= (PAGE_SIZE - 1))
144 return 0;
145 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
146 if (!IS_ERR(p)) {
147 p = mangle_path(s->buffer + s->len, p, "\n");
148 if (p) {
149 s->len = p - s->buffer;
150 return 1;
151 }
152 } else {
153 s->buffer[s->len++] = '?';
154 return 1;
155 }
156
157 return 0;
158}
159
160#ifdef CONFIG_KRETPROBES
161static inline const char *kretprobed(const char *name)
162{
163 static const char tramp_name[] = "kretprobe_trampoline";
164 int size = sizeof(tramp_name);
165
166 if (strncmp(tramp_name, name, size) == 0)
167 return "[unknown/kretprobe'd]";
168 return name;
169}
170#else
171static inline const char *kretprobed(const char *name)
172{
173 return name;
174}
175#endif /* CONFIG_KRETPROBES */
176
177static int
178seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
179{
180#ifdef CONFIG_KALLSYMS
181 char str[KSYM_SYMBOL_LEN];
182 const char *name;
183
184 kallsyms_lookup(address, NULL, NULL, NULL, str);
185
186 name = kretprobed(str);
187
188 return trace_seq_printf(s, fmt, name);
189#endif
190 return 1;
191}
192
193static int
194seq_print_sym_offset(struct trace_seq *s, const char *fmt,
195 unsigned long address)
196{
197#ifdef CONFIG_KALLSYMS
198 char str[KSYM_SYMBOL_LEN];
199 const char *name;
200
201 sprint_symbol(str, address);
202 name = kretprobed(str);
203
204 return trace_seq_printf(s, fmt, name);
205#endif
206 return 1;
207}
208
209#ifndef CONFIG_64BIT
210# define IP_FMT "%08lx"
211#else
212# define IP_FMT "%016lx"
213#endif
214
215int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
216 unsigned long ip, unsigned long sym_flags)
217{
218 struct file *file = NULL;
219 unsigned long vmstart = 0;
220 int ret = 1;
221
222 if (mm) {
223 const struct vm_area_struct *vma;
224
225 down_read(&mm->mmap_sem);
226 vma = find_vma(mm, ip);
227 if (vma) {
228 file = vma->vm_file;
229 vmstart = vma->vm_start;
230 }
231 if (file) {
232 ret = trace_seq_path(s, &file->f_path);
233 if (ret)
234 ret = trace_seq_printf(s, "[+0x%lx]",
235 ip - vmstart);
236 }
237 up_read(&mm->mmap_sem);
238 }
239 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
240 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
241 return ret;
242}
243
244int
245seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
246 unsigned long sym_flags)
247{
248 struct mm_struct *mm = NULL;
249 int ret = 1;
250 unsigned int i;
251
252 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
253 struct task_struct *task;
254 /*
255 * we do the lookup on the thread group leader,
256 * since individual threads might have already quit!
257 */
258 rcu_read_lock();
259 task = find_task_by_vpid(entry->ent.tgid);
260 if (task)
261 mm = get_task_mm(task);
262 rcu_read_unlock();
263 }
264
265 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
266 unsigned long ip = entry->caller[i];
267
268 if (ip == ULONG_MAX || !ret)
269 break;
270 if (i && ret)
271 ret = trace_seq_puts(s, " <- ");
272 if (!ip) {
273 if (ret)
274 ret = trace_seq_puts(s, "??");
275 continue;
276 }
277 if (!ret)
278 break;
279 if (ret)
280 ret = seq_print_user_ip(s, mm, ip, sym_flags);
281 }
282
283 if (mm)
284 mmput(mm);
285 return ret;
286}
287
288int
289seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
290{
291 int ret;
292
293 if (!ip)
294 return trace_seq_printf(s, "0");
295
296 if (sym_flags & TRACE_ITER_SYM_OFFSET)
297 ret = seq_print_sym_offset(s, "%s", ip);
298 else
299 ret = seq_print_sym_short(s, "%s", ip);
300
301 if (!ret)
302 return 0;
303
304 if (sym_flags & TRACE_ITER_SYM_ADDR)
305 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
306 return ret;
307}
308
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200309static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200310lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
311{
312 int hardirq, softirq;
313 char *comm;
314
315 comm = trace_find_cmdline(entry->pid);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200316 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
317 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200318
319 if (!trace_seq_printf(s, "%8.8s-%-5d %3d%c%c%c",
320 comm, entry->pid, cpu,
321 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
322 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
323 'X' : '.',
324 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
325 'N' : '.',
326 (hardirq && softirq) ? 'H' :
327 hardirq ? 'h' : softirq ? 's' : '.'))
328 return 0;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200329
330 if (entry->preempt_count)
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200331 return trace_seq_printf(s, "%x", entry->preempt_count);
332 return trace_seq_puts(s, ".");
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200333}
334
335static unsigned long preempt_mark_thresh = 100;
336
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200337static int
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200338lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
339 unsigned long rel_usecs)
340{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200341 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
342 rel_usecs > preempt_mark_thresh ? '!' :
343 rel_usecs > 1 ? '+' : ' ');
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200344}
345
346int trace_print_context(struct trace_iterator *iter)
347{
348 struct trace_seq *s = &iter->seq;
349 struct trace_entry *entry = iter->ent;
350 char *comm = trace_find_cmdline(entry->pid);
351 unsigned long long t = ns2usecs(iter->ts);
352 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
353 unsigned long secs = (unsigned long)t;
354
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200355 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
Steven Rostedt1830b522009-02-07 19:38:43 -0500356 comm, entry->pid, iter->cpu, secs, usec_rem);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200357}
358
359int trace_print_lat_context(struct trace_iterator *iter)
360{
361 u64 next_ts;
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200362 int ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200363 struct trace_seq *s = &iter->seq;
364 struct trace_entry *entry = iter->ent,
365 *next_entry = trace_find_next_entry(iter, NULL,
366 &next_ts);
367 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
368 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
369 unsigned long rel_usecs;
370
371 if (!next_entry)
372 next_ts = iter->ts;
373 rel_usecs = ns2usecs(next_ts - iter->ts);
374
375 if (verbose) {
376 char *comm = trace_find_cmdline(entry->pid);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200377 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
378 " %ld.%03ldms (+%ld.%03ldms): ", comm,
Steven Rostedt1830b522009-02-07 19:38:43 -0500379 entry->pid, iter->cpu, entry->flags,
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200380 entry->preempt_count, iter->idx,
381 ns2usecs(iter->ts),
382 abs_usecs / USEC_PER_MSEC,
383 abs_usecs % USEC_PER_MSEC,
384 rel_usecs / USEC_PER_MSEC,
385 rel_usecs % USEC_PER_MSEC);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200386 } else {
Steven Rostedt1830b522009-02-07 19:38:43 -0500387 ret = lat_print_generic(s, entry, iter->cpu);
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200388 if (ret)
389 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200390 }
391
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200392 return ret;
Frederic Weisbeckerc4a8e8b2009-02-02 20:29:21 -0200393}
394
Steven Rostedtf633cef2008-12-23 23:24:13 -0500395static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
396
397static int task_state_char(unsigned long state)
398{
399 int bit = state ? __ffs(state) + 1 : 0;
400
401 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
402}
403
Steven Rostedtf0868d12008-12-23 23:24:12 -0500404/**
405 * ftrace_find_event - find a registered event
406 * @type: the type of event to look for
407 *
408 * Returns an event of type @type otherwise NULL
409 */
410struct trace_event *ftrace_find_event(int type)
411{
412 struct trace_event *event;
413 struct hlist_node *n;
414 unsigned key;
415
416 key = type & (EVENT_HASHSIZE - 1);
417
418 hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
419 if (event->type == type)
420 return event;
421 }
422
423 return NULL;
424}
425
426/**
427 * register_ftrace_event - register output for an event type
428 * @event: the event type to register
429 *
430 * Event types are stored in a hash and this hash is used to
431 * find a way to print an event. If the @event->type is set
432 * then it will use that type, otherwise it will assign a
433 * type to use.
434 *
435 * If you assign your own type, please make sure it is added
436 * to the trace_type enum in trace.h, to avoid collisions
437 * with the dynamic types.
438 *
439 * Returns the event type number or zero on error.
440 */
441int register_ftrace_event(struct trace_event *event)
442{
443 unsigned key;
444 int ret = 0;
445
446 mutex_lock(&trace_event_mutex);
447
448 if (!event->type)
449 event->type = next_event_type++;
450 else if (event->type > __TRACE_LAST_TYPE) {
451 printk(KERN_WARNING "Need to add type to trace.h\n");
452 WARN_ON(1);
453 }
454
455 if (ftrace_find_event(event->type))
456 goto out;
457
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200458 if (event->trace == NULL)
459 event->trace = trace_nop_print;
Arnaldo Carvalho de Melo268ccda2009-02-04 20:16:39 -0200460 if (event->raw == NULL)
461 event->raw = trace_nop_print;
462 if (event->hex == NULL)
463 event->hex = trace_nop_print;
464 if (event->binary == NULL)
465 event->binary = trace_nop_print;
466
Steven Rostedtf0868d12008-12-23 23:24:12 -0500467 key = event->type & (EVENT_HASHSIZE - 1);
468
469 hlist_add_head_rcu(&event->node, &event_hash[key]);
470
471 ret = event->type;
472 out:
473 mutex_unlock(&trace_event_mutex);
474
475 return ret;
476}
477
478/**
479 * unregister_ftrace_event - remove a no longer used event
480 * @event: the event to remove
481 */
482int unregister_ftrace_event(struct trace_event *event)
483{
484 mutex_lock(&trace_event_mutex);
485 hlist_del(&event->node);
486 mutex_unlock(&trace_event_mutex);
487
488 return 0;
489}
Steven Rostedtf633cef2008-12-23 23:24:13 -0500490
491/*
492 * Standard events
493 */
494
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200495enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500496{
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200497 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500498}
499
500/* TRACE_FN */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200501static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500502{
503 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200504 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500505
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200506 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500507
508 if (!seq_print_ip_sym(s, field->ip, flags))
509 goto partial;
510
511 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
512 if (!trace_seq_printf(s, " <-"))
513 goto partial;
514 if (!seq_print_ip_sym(s,
515 field->parent_ip,
516 flags))
517 goto partial;
518 }
519 if (!trace_seq_printf(s, "\n"))
520 goto partial;
521
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200522 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500523
524 partial:
525 return TRACE_TYPE_PARTIAL_LINE;
526}
527
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200528static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500529{
530 struct ftrace_entry *field;
531
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200532 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500533
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200534 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800535 field->ip,
536 field->parent_ip))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500537 return TRACE_TYPE_PARTIAL_LINE;
538
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200539 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500540}
541
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200542static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500543{
544 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200545 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500546
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200547 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500548
549 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
550 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
551
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200552 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500553}
554
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200555static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500556{
557 struct ftrace_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200558 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500559
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200560 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500561
562 SEQ_PUT_FIELD_RET(s, field->ip);
563 SEQ_PUT_FIELD_RET(s, field->parent_ip);
564
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200565 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500566}
567
568static struct trace_event trace_fn_event = {
569 .type = TRACE_FN,
570 .trace = trace_fn_trace,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500571 .raw = trace_fn_raw,
572 .hex = trace_fn_hex,
573 .binary = trace_fn_bin,
574};
575
576/* TRACE_CTX an TRACE_WAKE */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200577static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
578 char *delim)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500579{
580 struct ctx_switch_entry *field;
581 char *comm;
582 int S, T;
583
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200584 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500585
586 T = task_state_char(field->next_state);
587 S = task_state_char(field->prev_state);
588 comm = trace_find_cmdline(field->next_pid);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200589 if (!trace_seq_printf(&iter->seq,
590 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800591 field->prev_pid,
592 field->prev_prio,
593 S, delim,
594 field->next_cpu,
595 field->next_pid,
596 field->next_prio,
597 T, comm))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500598 return TRACE_TYPE_PARTIAL_LINE;
599
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200600 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500601}
602
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200603static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500604{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200605 return trace_ctxwake_print(iter, "==>");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500606}
607
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200608static enum print_line_t trace_wake_print(struct trace_iterator *iter,
609 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500610{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200611 return trace_ctxwake_print(iter, " +");
Steven Rostedtf633cef2008-12-23 23:24:13 -0500612}
613
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200614static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500615{
616 struct ctx_switch_entry *field;
617 int T;
618
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200619 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500620
621 if (!S)
622 task_state_char(field->prev_state);
623 T = task_state_char(field->next_state);
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200624 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800625 field->prev_pid,
626 field->prev_prio,
627 S,
628 field->next_cpu,
629 field->next_pid,
630 field->next_prio,
631 T))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500632 return TRACE_TYPE_PARTIAL_LINE;
633
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200634 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500635}
636
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200637static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500638{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200639 return trace_ctxwake_raw(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500640}
641
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200642static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500643{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200644 return trace_ctxwake_raw(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500645}
646
647
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200648static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500649{
650 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200651 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500652 int T;
653
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200654 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500655
656 if (!S)
657 task_state_char(field->prev_state);
658 T = task_state_char(field->next_state);
659
660 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
661 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
662 SEQ_PUT_HEX_FIELD_RET(s, S);
663 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
664 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
665 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
666 SEQ_PUT_HEX_FIELD_RET(s, T);
667
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200668 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500669}
670
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200671static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500672{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200673 return trace_ctxwake_hex(iter, 0);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500674}
675
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200676static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500677{
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200678 return trace_ctxwake_hex(iter, '+');
Steven Rostedtf633cef2008-12-23 23:24:13 -0500679}
680
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200681static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
682 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500683{
684 struct ctx_switch_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200685 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500686
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200687 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500688
689 SEQ_PUT_FIELD_RET(s, field->prev_pid);
690 SEQ_PUT_FIELD_RET(s, field->prev_prio);
691 SEQ_PUT_FIELD_RET(s, field->prev_state);
692 SEQ_PUT_FIELD_RET(s, field->next_pid);
693 SEQ_PUT_FIELD_RET(s, field->next_prio);
694 SEQ_PUT_FIELD_RET(s, field->next_state);
695
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200696 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500697}
698
699static struct trace_event trace_ctx_event = {
700 .type = TRACE_CTX,
701 .trace = trace_ctx_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500702 .raw = trace_ctx_raw,
703 .hex = trace_ctx_hex,
704 .binary = trace_ctxwake_bin,
705};
706
707static struct trace_event trace_wake_event = {
708 .type = TRACE_WAKE,
709 .trace = trace_wake_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500710 .raw = trace_wake_raw,
711 .hex = trace_wake_hex,
712 .binary = trace_ctxwake_bin,
713};
714
715/* TRACE_SPECIAL */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200716static enum print_line_t trace_special_print(struct trace_iterator *iter,
717 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500718{
719 struct special_entry *field;
720
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200721 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500722
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200723 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800724 field->arg1,
725 field->arg2,
726 field->arg3))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500727 return TRACE_TYPE_PARTIAL_LINE;
728
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200729 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500730}
731
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200732static enum print_line_t trace_special_hex(struct trace_iterator *iter,
733 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500734{
735 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200736 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500737
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200738 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500739
740 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
741 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
742 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
743
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200744 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500745}
746
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200747static enum print_line_t trace_special_bin(struct trace_iterator *iter,
748 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500749{
750 struct special_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200751 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500752
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200753 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500754
755 SEQ_PUT_FIELD_RET(s, field->arg1);
756 SEQ_PUT_FIELD_RET(s, field->arg2);
757 SEQ_PUT_FIELD_RET(s, field->arg3);
758
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200759 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500760}
761
762static struct trace_event trace_special_event = {
763 .type = TRACE_SPECIAL,
764 .trace = trace_special_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500765 .raw = trace_special_print,
766 .hex = trace_special_hex,
767 .binary = trace_special_bin,
768};
769
770/* TRACE_STACK */
771
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200772static enum print_line_t trace_stack_print(struct trace_iterator *iter,
773 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500774{
775 struct stack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200776 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500777 int i;
778
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200779 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500780
781 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
782 if (i) {
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800783 if (!trace_seq_puts(s, " <= "))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500784 goto partial;
785
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800786 if (!seq_print_ip_sym(s, field->caller[i], flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500787 goto partial;
788 }
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800789 if (!trace_seq_puts(s, "\n"))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500790 goto partial;
791 }
792
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200793 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500794
795 partial:
796 return TRACE_TYPE_PARTIAL_LINE;
797}
798
799static struct trace_event trace_stack_event = {
800 .type = TRACE_STACK,
801 .trace = trace_stack_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_USER_STACK */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200808static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
809 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500810{
811 struct userstack_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200812 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500813
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200814 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500815
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800816 if (!seq_print_userip_objs(field, s, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500817 goto partial;
818
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800819 if (!trace_seq_putc(s, '\n'))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500820 goto partial;
821
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200822 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500823
824 partial:
825 return TRACE_TYPE_PARTIAL_LINE;
826}
827
828static struct trace_event trace_user_stack_event = {
829 .type = TRACE_USER_STACK,
830 .trace = trace_user_stack_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500831 .raw = trace_special_print,
832 .hex = trace_special_hex,
833 .binary = trace_special_bin,
834};
835
836/* TRACE_PRINT */
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200837static enum print_line_t trace_print_print(struct trace_iterator *iter,
838 int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500839{
840 struct print_entry *field;
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200841 struct trace_seq *s = &iter->seq;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500842
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200843 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500844
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800845 if (!seq_print_ip_sym(s, field->ip, flags))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500846 goto partial;
847
Lai Jiangshan6c1a99a2009-01-15 18:05:40 +0800848 if (!trace_seq_printf(s, ": %s", field->buf))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500849 goto partial;
850
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200851 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500852
853 partial:
854 return TRACE_TYPE_PARTIAL_LINE;
855}
856
Arnaldo Carvalho de Meloae7462b2009-02-03 22:05:50 -0200857static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags)
Steven Rostedtf633cef2008-12-23 23:24:13 -0500858{
859 struct print_entry *field;
860
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200861 trace_assign_type(field, iter->ent);
Steven Rostedtf633cef2008-12-23 23:24:13 -0500862
Arnaldo Carvalho de Melo2c9b2382009-02-02 20:30:12 -0200863 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
Steven Rostedtf633cef2008-12-23 23:24:13 -0500864 goto partial;
865
Arnaldo Carvalho de Melod9793bd2009-02-03 20:20:41 -0200866 return TRACE_TYPE_HANDLED;
Steven Rostedtf633cef2008-12-23 23:24:13 -0500867
868 partial:
869 return TRACE_TYPE_PARTIAL_LINE;
870}
871
872static struct trace_event trace_print_event = {
873 .type = TRACE_PRINT,
874 .trace = trace_print_print,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500875 .raw = trace_print_raw,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500876};
877
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100878/* TRACE_BPRINTK */
879static enum print_line_t
880trace_bprintk_print(struct trace_iterator *iter, int flags)
881{
882 struct trace_entry *entry = iter->ent;
883 struct trace_seq *s = &iter->seq;
884 struct bprintk_entry *field;
885
886 trace_assign_type(field, entry);
887
888 if (!seq_print_ip_sym(s, field->ip, flags))
889 goto partial;
890
891 if (!trace_seq_puts(s, ": "))
892 goto partial;
893
894 if (!trace_seq_bprintf(s, field->fmt, field->buf))
895 goto partial;
896
897 return TRACE_TYPE_HANDLED;
898
899 partial:
900 return TRACE_TYPE_PARTIAL_LINE;
901}
902
903static enum print_line_t
904trace_bprintk_raw(struct trace_iterator *iter, int flags)
905{
906 struct trace_entry *entry = iter->ent;
907 struct trace_seq *s = &iter->seq;
908 struct bprintk_entry *field;
909
910 trace_assign_type(field, entry);
911
912 if (!trace_seq_printf(s, ": %lx : ", field->ip))
913 goto partial;
914
915 if (!trace_seq_bprintf(s, field->fmt, field->buf))
916 goto partial;
917
918 return TRACE_TYPE_HANDLED;
919
920 partial:
921 return TRACE_TYPE_PARTIAL_LINE;
922}
923
924static struct trace_event trace_bprintk_event = {
925 .type = TRACE_BPRINTK,
926 .trace = trace_bprintk_print,
927 .raw = trace_bprintk_raw,
928 .hex = trace_nop_print,
929 .binary = trace_nop_print,
930};
931
Steven Rostedtf633cef2008-12-23 23:24:13 -0500932static struct trace_event *events[] __initdata = {
933 &trace_fn_event,
934 &trace_ctx_event,
935 &trace_wake_event,
936 &trace_special_event,
937 &trace_stack_event,
938 &trace_user_stack_event,
939 &trace_print_event,
Lai Jiangshan1427cdf2009-03-06 17:21:47 +0100940 &trace_bprintk_event,
Steven Rostedtf633cef2008-12-23 23:24:13 -0500941 NULL
942};
943
944__init static int init_events(void)
945{
946 struct trace_event *event;
947 int i, ret;
948
949 for (i = 0; events[i]; i++) {
950 event = events[i];
951
952 ret = register_ftrace_event(event);
953 if (!ret) {
954 printk(KERN_WARNING "event %d failed to register\n",
955 event->type);
956 WARN_ON_ONCE(1);
957 }
958 }
959
960 return 0;
961}
962device_initcall(init_events);