Merge branches 'tracing/blktrace', 'tracing/ftrace', 'tracing/urgent' and 'linus...
[linux-2.6] / kernel / trace / trace_output.c
1 /*
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
17 static DEFINE_MUTEX(trace_event_mutex);
18 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
19
20 static 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  */
33 int
34 trace_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
56 /**
57  * trace_seq_puts - trace sequence printing of simple string
58  * @s: trace sequence descriptor
59  * @str: simple string to record
60  *
61  * The tracer may use either the sequence operations or its own
62  * copy to user routines. This function records a simple string
63  * into a special buffer (@s) for later retrieval by a sequencer
64  * or other mechanism.
65  */
66 int trace_seq_puts(struct trace_seq *s, const char *str)
67 {
68         int len = strlen(str);
69
70         if (len > ((PAGE_SIZE - 1) - s->len))
71                 return 0;
72
73         memcpy(s->buffer + s->len, str, len);
74         s->len += len;
75
76         return len;
77 }
78
79 int trace_seq_putc(struct trace_seq *s, unsigned char c)
80 {
81         if (s->len >= (PAGE_SIZE - 1))
82                 return 0;
83
84         s->buffer[s->len++] = c;
85
86         return 1;
87 }
88
89 int trace_seq_putmem(struct trace_seq *s, void *mem, size_t len)
90 {
91         if (len > ((PAGE_SIZE - 1) - s->len))
92                 return 0;
93
94         memcpy(s->buffer + s->len, mem, len);
95         s->len += len;
96
97         return len;
98 }
99
100 int trace_seq_putmem_hex(struct trace_seq *s, void *mem, size_t len)
101 {
102         unsigned char hex[HEX_CHARS];
103         unsigned char *data = mem;
104         int i, j;
105
106 #ifdef __BIG_ENDIAN
107         for (i = 0, j = 0; i < len; i++) {
108 #else
109         for (i = len-1, j = 0; i >= 0; i--) {
110 #endif
111                 hex[j++] = hex_asc_hi(data[i]);
112                 hex[j++] = hex_asc_lo(data[i]);
113         }
114         hex[j++] = ' ';
115
116         return trace_seq_putmem(s, hex, j);
117 }
118
119 int trace_seq_path(struct trace_seq *s, struct path *path)
120 {
121         unsigned char *p;
122
123         if (s->len >= (PAGE_SIZE - 1))
124                 return 0;
125         p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
126         if (!IS_ERR(p)) {
127                 p = mangle_path(s->buffer + s->len, p, "\n");
128                 if (p) {
129                         s->len = p - s->buffer;
130                         return 1;
131                 }
132         } else {
133                 s->buffer[s->len++] = '?';
134                 return 1;
135         }
136
137         return 0;
138 }
139
140 #ifdef CONFIG_KRETPROBES
141 static inline const char *kretprobed(const char *name)
142 {
143         static const char tramp_name[] = "kretprobe_trampoline";
144         int size = sizeof(tramp_name);
145
146         if (strncmp(tramp_name, name, size) == 0)
147                 return "[unknown/kretprobe'd]";
148         return name;
149 }
150 #else
151 static inline const char *kretprobed(const char *name)
152 {
153         return name;
154 }
155 #endif /* CONFIG_KRETPROBES */
156
157 static int
158 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
159 {
160 #ifdef CONFIG_KALLSYMS
161         char str[KSYM_SYMBOL_LEN];
162         const char *name;
163
164         kallsyms_lookup(address, NULL, NULL, NULL, str);
165
166         name = kretprobed(str);
167
168         return trace_seq_printf(s, fmt, name);
169 #endif
170         return 1;
171 }
172
173 static int
174 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
175                      unsigned long address)
176 {
177 #ifdef CONFIG_KALLSYMS
178         char str[KSYM_SYMBOL_LEN];
179         const char *name;
180
181         sprint_symbol(str, address);
182         name = kretprobed(str);
183
184         return trace_seq_printf(s, fmt, name);
185 #endif
186         return 1;
187 }
188
189 #ifndef CONFIG_64BIT
190 # define IP_FMT "%08lx"
191 #else
192 # define IP_FMT "%016lx"
193 #endif
194
195 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
196                       unsigned long ip, unsigned long sym_flags)
197 {
198         struct file *file = NULL;
199         unsigned long vmstart = 0;
200         int ret = 1;
201
202         if (mm) {
203                 const struct vm_area_struct *vma;
204
205                 down_read(&mm->mmap_sem);
206                 vma = find_vma(mm, ip);
207                 if (vma) {
208                         file = vma->vm_file;
209                         vmstart = vma->vm_start;
210                 }
211                 if (file) {
212                         ret = trace_seq_path(s, &file->f_path);
213                         if (ret)
214                                 ret = trace_seq_printf(s, "[+0x%lx]",
215                                                        ip - vmstart);
216                 }
217                 up_read(&mm->mmap_sem);
218         }
219         if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
220                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
221         return ret;
222 }
223
224 int
225 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
226                       unsigned long sym_flags)
227 {
228         struct mm_struct *mm = NULL;
229         int ret = 1;
230         unsigned int i;
231
232         if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
233                 struct task_struct *task;
234                 /*
235                  * we do the lookup on the thread group leader,
236                  * since individual threads might have already quit!
237                  */
238                 rcu_read_lock();
239                 task = find_task_by_vpid(entry->ent.tgid);
240                 if (task)
241                         mm = get_task_mm(task);
242                 rcu_read_unlock();
243         }
244
245         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
246                 unsigned long ip = entry->caller[i];
247
248                 if (ip == ULONG_MAX || !ret)
249                         break;
250                 if (i && ret)
251                         ret = trace_seq_puts(s, " <- ");
252                 if (!ip) {
253                         if (ret)
254                                 ret = trace_seq_puts(s, "??");
255                         continue;
256                 }
257                 if (!ret)
258                         break;
259                 if (ret)
260                         ret = seq_print_user_ip(s, mm, ip, sym_flags);
261         }
262
263         if (mm)
264                 mmput(mm);
265         return ret;
266 }
267
268 int
269 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
270 {
271         int ret;
272
273         if (!ip)
274                 return trace_seq_printf(s, "0");
275
276         if (sym_flags & TRACE_ITER_SYM_OFFSET)
277                 ret = seq_print_sym_offset(s, "%s", ip);
278         else
279                 ret = seq_print_sym_short(s, "%s", ip);
280
281         if (!ret)
282                 return 0;
283
284         if (sym_flags & TRACE_ITER_SYM_ADDR)
285                 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
286         return ret;
287 }
288
289 static void
290 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
291 {
292         int hardirq, softirq;
293         char *comm;
294
295         comm = trace_find_cmdline(entry->pid);
296
297         trace_seq_printf(s, "%8.8s-%-5d ", comm, entry->pid);
298         trace_seq_printf(s, "%3d", cpu);
299         trace_seq_printf(s, "%c%c",
300                         (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
301                          (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' : '.',
302                         ((entry->flags & TRACE_FLAG_NEED_RESCHED) ? 'N' : '.'));
303
304         hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
305         softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
306         if (hardirq && softirq) {
307                 trace_seq_putc(s, 'H');
308         } else {
309                 if (hardirq) {
310                         trace_seq_putc(s, 'h');
311                 } else {
312                         if (softirq)
313                                 trace_seq_putc(s, 's');
314                         else
315                                 trace_seq_putc(s, '.');
316                 }
317         }
318
319         if (entry->preempt_count)
320                 trace_seq_printf(s, "%x", entry->preempt_count);
321         else
322                 trace_seq_puts(s, ".");
323 }
324
325 static unsigned long preempt_mark_thresh = 100;
326
327 static void
328 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
329                     unsigned long rel_usecs)
330 {
331         trace_seq_printf(s, " %4lldus", abs_usecs);
332         if (rel_usecs > preempt_mark_thresh)
333                 trace_seq_puts(s, "!: ");
334         else if (rel_usecs > 1)
335                 trace_seq_puts(s, "+: ");
336         else
337                 trace_seq_puts(s, " : ");
338 }
339
340 int trace_print_context(struct trace_iterator *iter)
341 {
342         struct trace_seq *s = &iter->seq;
343         struct trace_entry *entry = iter->ent;
344         char *comm = trace_find_cmdline(entry->pid);
345         unsigned long long t = ns2usecs(iter->ts);
346         unsigned long usec_rem = do_div(t, USEC_PER_SEC);
347         unsigned long secs = (unsigned long)t;
348
349         if (!trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid))
350                 goto partial;
351         if (!trace_seq_printf(s, "[%03d] ", entry->cpu))
352                 goto partial;
353         if (!trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem))
354                 goto partial;
355
356         return 0;
357
358 partial:
359         return TRACE_TYPE_PARTIAL_LINE;
360 }
361
362 int trace_print_lat_context(struct trace_iterator *iter)
363 {
364         u64 next_ts;
365         struct trace_seq *s = &iter->seq;
366         struct trace_entry *entry = iter->ent,
367                            *next_entry = trace_find_next_entry(iter, NULL,
368                                                                &next_ts);
369         unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
370         unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
371         unsigned long rel_usecs;
372
373         if (!next_entry)
374                 next_ts = iter->ts;
375         rel_usecs = ns2usecs(next_ts - iter->ts);
376
377         if (verbose) {
378                 char *comm = trace_find_cmdline(entry->pid);
379                 trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08lx]"
380                                  " %ld.%03ldms (+%ld.%03ldms): ",
381                                  comm,
382                                  entry->pid, entry->cpu, entry->flags,
383                                  entry->preempt_count, iter->idx,
384                                  ns2usecs(iter->ts),
385                                  abs_usecs/1000,
386                                  abs_usecs % 1000, rel_usecs/1000,
387                                  rel_usecs % 1000);
388         } else {
389                 lat_print_generic(s, entry, entry->cpu);
390                 lat_print_timestamp(s, abs_usecs, rel_usecs);
391         }
392
393         return 0;
394 }
395
396 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
397
398 static int task_state_char(unsigned long state)
399 {
400         int bit = state ? __ffs(state) + 1 : 0;
401
402         return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
403 }
404
405 /**
406  * ftrace_find_event - find a registered event
407  * @type: the type of event to look for
408  *
409  * Returns an event of type @type otherwise NULL
410  */
411 struct trace_event *ftrace_find_event(int type)
412 {
413         struct trace_event *event;
414         struct hlist_node *n;
415         unsigned key;
416
417         key = type & (EVENT_HASHSIZE - 1);
418
419         hlist_for_each_entry_rcu(event, n, &event_hash[key], node) {
420                 if (event->type == type)
421                         return event;
422         }
423
424         return NULL;
425 }
426
427 /**
428  * register_ftrace_event - register output for an event type
429  * @event: the event type to register
430  *
431  * Event types are stored in a hash and this hash is used to
432  * find a way to print an event. If the @event->type is set
433  * then it will use that type, otherwise it will assign a
434  * type to use.
435  *
436  * If you assign your own type, please make sure it is added
437  * to the trace_type enum in trace.h, to avoid collisions
438  * with the dynamic types.
439  *
440  * Returns the event type number or zero on error.
441  */
442 int register_ftrace_event(struct trace_event *event)
443 {
444         unsigned key;
445         int ret = 0;
446
447         mutex_lock(&trace_event_mutex);
448
449         if (!event->type)
450                 event->type = next_event_type++;
451         else if (event->type > __TRACE_LAST_TYPE) {
452                 printk(KERN_WARNING "Need to add type to trace.h\n");
453                 WARN_ON(1);
454         }
455
456         if (ftrace_find_event(event->type))
457                 goto out;
458
459         key = event->type & (EVENT_HASHSIZE - 1);
460
461         hlist_add_head_rcu(&event->node, &event_hash[key]);
462
463         ret = event->type;
464  out:
465         mutex_unlock(&trace_event_mutex);
466
467         return ret;
468 }
469
470 /**
471  * unregister_ftrace_event - remove a no longer used event
472  * @event: the event to remove
473  */
474 int unregister_ftrace_event(struct trace_event *event)
475 {
476         mutex_lock(&trace_event_mutex);
477         hlist_del(&event->node);
478         mutex_unlock(&trace_event_mutex);
479
480         return 0;
481 }
482
483 /*
484  * Standard events
485  */
486
487 int trace_nop_print(struct trace_iterator *iter, int flags)
488 {
489         return 0;
490 }
491
492 /* TRACE_FN */
493 static int trace_fn_latency(struct trace_iterator *iter, int flags)
494 {
495         struct ftrace_entry *field;
496         struct trace_seq *s = &iter->seq;
497
498         trace_assign_type(field, iter->ent);
499
500         if (!seq_print_ip_sym(s, field->ip, flags))
501                 goto partial;
502         if (!trace_seq_puts(s, " ("))
503                 goto partial;
504         if (!seq_print_ip_sym(s, field->parent_ip, flags))
505                 goto partial;
506         if (!trace_seq_puts(s, ")\n"))
507                 goto partial;
508
509         return 0;
510
511  partial:
512         return TRACE_TYPE_PARTIAL_LINE;
513 }
514
515 static int trace_fn_trace(struct trace_iterator *iter, int flags)
516 {
517         struct ftrace_entry *field;
518         struct trace_seq *s = &iter->seq;
519
520         trace_assign_type(field, iter->ent);
521
522         if (!seq_print_ip_sym(s, field->ip, flags))
523                 goto partial;
524
525         if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
526                 if (!trace_seq_printf(s, " <-"))
527                         goto partial;
528                 if (!seq_print_ip_sym(s,
529                                       field->parent_ip,
530                                       flags))
531                         goto partial;
532         }
533         if (!trace_seq_printf(s, "\n"))
534                 goto partial;
535
536         return 0;
537
538  partial:
539         return TRACE_TYPE_PARTIAL_LINE;
540 }
541
542 static int trace_fn_raw(struct trace_iterator *iter, int flags)
543 {
544         struct ftrace_entry *field;
545
546         trace_assign_type(field, iter->ent);
547
548         if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
549                               field->ip,
550                               field->parent_ip))
551                 return TRACE_TYPE_PARTIAL_LINE;
552
553         return 0;
554 }
555
556 static int trace_fn_hex(struct trace_iterator *iter, int flags)
557 {
558         struct ftrace_entry *field;
559         struct trace_seq *s = &iter->seq;
560
561         trace_assign_type(field, iter->ent);
562
563         SEQ_PUT_HEX_FIELD_RET(s, field->ip);
564         SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
565
566         return 0;
567 }
568
569 static int trace_fn_bin(struct trace_iterator *iter, int flags)
570 {
571         struct ftrace_entry *field;
572         struct trace_seq *s = &iter->seq;
573
574         trace_assign_type(field, iter->ent);
575
576         SEQ_PUT_FIELD_RET(s, field->ip);
577         SEQ_PUT_FIELD_RET(s, field->parent_ip);
578
579         return 0;
580 }
581
582 static struct trace_event trace_fn_event = {
583         .type           = TRACE_FN,
584         .trace          = trace_fn_trace,
585         .latency_trace  = trace_fn_latency,
586         .raw            = trace_fn_raw,
587         .hex            = trace_fn_hex,
588         .binary         = trace_fn_bin,
589 };
590
591 /* TRACE_CTX an TRACE_WAKE */
592 static int trace_ctxwake_print(struct trace_iterator *iter, char *delim)
593 {
594         struct ctx_switch_entry *field;
595         char *comm;
596         int S, T;
597
598         trace_assign_type(field, iter->ent);
599
600         T = task_state_char(field->next_state);
601         S = task_state_char(field->prev_state);
602         comm = trace_find_cmdline(field->next_pid);
603         if (!trace_seq_printf(&iter->seq,
604                               " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
605                               field->prev_pid,
606                               field->prev_prio,
607                               S, delim,
608                               field->next_cpu,
609                               field->next_pid,
610                               field->next_prio,
611                               T, comm))
612                 return TRACE_TYPE_PARTIAL_LINE;
613
614         return 0;
615 }
616
617 static int trace_ctx_print(struct trace_iterator *iter, int flags)
618 {
619         return trace_ctxwake_print(iter, "==>");
620 }
621
622 static int trace_wake_print(struct trace_iterator *iter, int flags)
623 {
624         return trace_ctxwake_print(iter, "  +");
625 }
626
627 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
628 {
629         struct ctx_switch_entry *field;
630         int T;
631
632         trace_assign_type(field, iter->ent);
633
634         if (!S)
635                 task_state_char(field->prev_state);
636         T = task_state_char(field->next_state);
637         if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
638                               field->prev_pid,
639                               field->prev_prio,
640                               S,
641                               field->next_cpu,
642                               field->next_pid,
643                               field->next_prio,
644                               T))
645                 return TRACE_TYPE_PARTIAL_LINE;
646
647         return 0;
648 }
649
650 static int trace_ctx_raw(struct trace_iterator *iter, int flags)
651 {
652         return trace_ctxwake_raw(iter, 0);
653 }
654
655 static int trace_wake_raw(struct trace_iterator *iter, int flags)
656 {
657         return trace_ctxwake_raw(iter, '+');
658 }
659
660
661 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
662 {
663         struct ctx_switch_entry *field;
664         struct trace_seq *s = &iter->seq;
665         int T;
666
667         trace_assign_type(field, iter->ent);
668
669         if (!S)
670                 task_state_char(field->prev_state);
671         T = task_state_char(field->next_state);
672
673         SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
674         SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
675         SEQ_PUT_HEX_FIELD_RET(s, S);
676         SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
677         SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
678         SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
679         SEQ_PUT_HEX_FIELD_RET(s, T);
680
681         return 0;
682 }
683
684 static int trace_ctx_hex(struct trace_iterator *iter, int flags)
685 {
686         return trace_ctxwake_hex(iter, 0);
687 }
688
689 static int trace_wake_hex(struct trace_iterator *iter, int flags)
690 {
691         return trace_ctxwake_hex(iter, '+');
692 }
693
694 static int trace_ctxwake_bin(struct trace_iterator *iter, int flags)
695 {
696         struct ctx_switch_entry *field;
697         struct trace_seq *s = &iter->seq;
698
699         trace_assign_type(field, iter->ent);
700
701         SEQ_PUT_FIELD_RET(s, field->prev_pid);
702         SEQ_PUT_FIELD_RET(s, field->prev_prio);
703         SEQ_PUT_FIELD_RET(s, field->prev_state);
704         SEQ_PUT_FIELD_RET(s, field->next_pid);
705         SEQ_PUT_FIELD_RET(s, field->next_prio);
706         SEQ_PUT_FIELD_RET(s, field->next_state);
707
708         return 0;
709 }
710
711 static struct trace_event trace_ctx_event = {
712         .type           = TRACE_CTX,
713         .trace          = trace_ctx_print,
714         .latency_trace  = trace_ctx_print,
715         .raw            = trace_ctx_raw,
716         .hex            = trace_ctx_hex,
717         .binary         = trace_ctxwake_bin,
718 };
719
720 static struct trace_event trace_wake_event = {
721         .type           = TRACE_WAKE,
722         .trace          = trace_wake_print,
723         .latency_trace  = trace_wake_print,
724         .raw            = trace_wake_raw,
725         .hex            = trace_wake_hex,
726         .binary         = trace_ctxwake_bin,
727 };
728
729 /* TRACE_SPECIAL */
730 static int trace_special_print(struct trace_iterator *iter, int flags)
731 {
732         struct special_entry *field;
733
734         trace_assign_type(field, iter->ent);
735
736         if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
737                               field->arg1,
738                               field->arg2,
739                               field->arg3))
740                 return TRACE_TYPE_PARTIAL_LINE;
741
742         return 0;
743 }
744
745 static int trace_special_hex(struct trace_iterator *iter, int flags)
746 {
747         struct special_entry *field;
748         struct trace_seq *s = &iter->seq;
749
750         trace_assign_type(field, iter->ent);
751
752         SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
753         SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
754         SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
755
756         return 0;
757 }
758
759 static int trace_special_bin(struct trace_iterator *iter, int flags)
760 {
761         struct special_entry *field;
762         struct trace_seq *s = &iter->seq;
763
764         trace_assign_type(field, iter->ent);
765
766         SEQ_PUT_FIELD_RET(s, field->arg1);
767         SEQ_PUT_FIELD_RET(s, field->arg2);
768         SEQ_PUT_FIELD_RET(s, field->arg3);
769
770         return 0;
771 }
772
773 static struct trace_event trace_special_event = {
774         .type           = TRACE_SPECIAL,
775         .trace          = trace_special_print,
776         .latency_trace  = trace_special_print,
777         .raw            = trace_special_print,
778         .hex            = trace_special_hex,
779         .binary         = trace_special_bin,
780 };
781
782 /* TRACE_STACK */
783
784 static int trace_stack_print(struct trace_iterator *iter, int flags)
785 {
786         struct stack_entry *field;
787         struct trace_seq *s = &iter->seq;
788         int i;
789
790         trace_assign_type(field, iter->ent);
791
792         for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
793                 if (i) {
794                         if (!trace_seq_puts(s, " <= "))
795                                 goto partial;
796
797                         if (!seq_print_ip_sym(s, field->caller[i], flags))
798                                 goto partial;
799                 }
800                 if (!trace_seq_puts(s, "\n"))
801                         goto partial;
802         }
803
804         return 0;
805
806  partial:
807         return TRACE_TYPE_PARTIAL_LINE;
808 }
809
810 static struct trace_event trace_stack_event = {
811         .type           = TRACE_STACK,
812         .trace          = trace_stack_print,
813         .latency_trace  = trace_stack_print,
814         .raw            = trace_special_print,
815         .hex            = trace_special_hex,
816         .binary         = trace_special_bin,
817 };
818
819 /* TRACE_USER_STACK */
820 static int trace_user_stack_print(struct trace_iterator *iter, int flags)
821 {
822         struct userstack_entry *field;
823         struct trace_seq *s = &iter->seq;
824
825         trace_assign_type(field, iter->ent);
826
827         if (!seq_print_userip_objs(field, s, flags))
828                 goto partial;
829
830         if (!trace_seq_putc(s, '\n'))
831                 goto partial;
832
833         return 0;
834
835  partial:
836         return TRACE_TYPE_PARTIAL_LINE;
837 }
838
839 static struct trace_event trace_user_stack_event = {
840         .type           = TRACE_USER_STACK,
841         .trace          = trace_user_stack_print,
842         .latency_trace  = trace_user_stack_print,
843         .raw            = trace_special_print,
844         .hex            = trace_special_hex,
845         .binary         = trace_special_bin,
846 };
847
848 /* TRACE_PRINT */
849 static int trace_print_print(struct trace_iterator *iter, int flags)
850 {
851         struct print_entry *field;
852         struct trace_seq *s = &iter->seq;
853
854         trace_assign_type(field, iter->ent);
855
856         if (!seq_print_ip_sym(s, field->ip, flags))
857                 goto partial;
858
859         if (!trace_seq_printf(s, ": %s", field->buf))
860                 goto partial;
861
862         return 0;
863
864  partial:
865         return TRACE_TYPE_PARTIAL_LINE;
866 }
867
868 static int trace_print_raw(struct trace_iterator *iter, int flags)
869 {
870         struct print_entry *field;
871
872         trace_assign_type(field, iter->ent);
873
874         if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
875                 goto partial;
876
877         return 0;
878
879  partial:
880         return TRACE_TYPE_PARTIAL_LINE;
881 }
882
883 static struct trace_event trace_print_event = {
884         .type           = TRACE_PRINT,
885         .trace          = trace_print_print,
886         .latency_trace  = trace_print_print,
887         .raw            = trace_print_raw,
888         .hex            = trace_nop_print,
889         .binary         = trace_nop_print,
890 };
891
892 static struct trace_event *events[] __initdata = {
893         &trace_fn_event,
894         &trace_ctx_event,
895         &trace_wake_event,
896         &trace_special_event,
897         &trace_stack_event,
898         &trace_user_stack_event,
899         &trace_print_event,
900         NULL
901 };
902
903 __init static int init_events(void)
904 {
905         struct trace_event *event;
906         int i, ret;
907
908         for (i = 0; events[i]; i++) {
909                 event = events[i];
910
911                 ret = register_ftrace_event(event);
912                 if (!ret) {
913                         printk(KERN_WARNING "event %d failed to register\n",
914                                event->type);
915                         WARN_ON_ONCE(1);
916                 }
917         }
918
919         return 0;
920 }
921 device_initcall(init_events);