4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
8 #include <linux/module.h>
9 #include <linux/mutex.h>
10 #include <linux/ftrace.h>
12 #include "trace_output.h"
14 /* must be a power of 2 */
15 #define EVENT_HASHSIZE 128
17 DECLARE_RWSEM(trace_event_mutex);
19 DEFINE_PER_CPU(struct trace_seq, ftrace_event_seq);
20 EXPORT_PER_CPU_SYMBOL(ftrace_event_seq);
22 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
24 static int next_event_type = __TRACE_LAST_TYPE + 1;
26 int trace_print_seq(struct seq_file *m, struct trace_seq *s)
28 int len = s->len >= PAGE_SIZE ? PAGE_SIZE - 1 : s->len;
31 ret = seq_write(m, s->buffer, len);
34 * Only reset this buffer if we successfully wrote to the
43 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
45 struct trace_seq *s = &iter->seq;
46 struct trace_entry *entry = iter->ent;
47 struct bprint_entry *field;
50 trace_assign_type(field, entry);
52 ret = trace_seq_bprintf(s, field->fmt, field->buf);
54 return TRACE_TYPE_PARTIAL_LINE;
56 return TRACE_TYPE_HANDLED;
59 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
61 struct trace_seq *s = &iter->seq;
62 struct trace_entry *entry = iter->ent;
63 struct print_entry *field;
66 trace_assign_type(field, entry);
68 ret = trace_seq_printf(s, "%s", field->buf);
70 return TRACE_TYPE_PARTIAL_LINE;
72 return TRACE_TYPE_HANDLED;
76 * trace_seq_printf - sequence printing of trace information
77 * @s: trace sequence descriptor
78 * @fmt: printf format string
80 * It returns 0 if the trace oversizes the buffer's free
83 * The tracer may use either sequence operations or its own
84 * copy to user routines. To simplify formating of a trace
85 * trace_seq_printf is used to store strings into a special
86 * buffer (@s). Then the output may be either used by
87 * the sequencer or pulled into another buffer.
90 trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
92 int len = (PAGE_SIZE - 1) - s->len;
100 ret = vsnprintf(s->buffer + s->len, len, fmt, ap);
103 /* If we can't write it all, don't bother writing anything */
113 EXPORT_SYMBOL_GPL(trace_seq_printf);
116 * trace_seq_vprintf - sequence printing of trace information
117 * @s: trace sequence descriptor
118 * @fmt: printf format string
120 * The tracer may use either sequence operations or its own
121 * copy to user routines. To simplify formating of a trace
122 * trace_seq_printf is used to store strings into a special
123 * buffer (@s). Then the output may be either used by
124 * the sequencer or pulled into another buffer.
127 trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args)
129 int len = (PAGE_SIZE - 1) - s->len;
135 ret = vsnprintf(s->buffer + s->len, len, fmt, args);
137 /* If we can't write it all, don't bother writing anything */
147 EXPORT_SYMBOL_GPL(trace_seq_vprintf);
149 int trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
151 int len = (PAGE_SIZE - 1) - s->len;
157 ret = bstr_printf(s->buffer + s->len, len, fmt, binary);
159 /* If we can't write it all, don't bother writing anything */
171 * trace_seq_puts - trace sequence printing of simple string
172 * @s: trace sequence descriptor
173 * @str: simple string to record
175 * The tracer may use either the sequence operations or its own
176 * copy to user routines. This function records a simple string
177 * into a special buffer (@s) for later retrieval by a sequencer
178 * or other mechanism.
180 int trace_seq_puts(struct trace_seq *s, const char *str)
182 int len = strlen(str);
187 if (len > ((PAGE_SIZE - 1) - s->len)) {
192 memcpy(s->buffer + s->len, str, len);
198 int trace_seq_putc(struct trace_seq *s, unsigned char c)
203 if (s->len >= (PAGE_SIZE - 1)) {
208 s->buffer[s->len++] = c;
213 int trace_seq_putmem(struct trace_seq *s, const void *mem, size_t len)
218 if (len > ((PAGE_SIZE - 1) - s->len)) {
223 memcpy(s->buffer + s->len, mem, len);
229 int trace_seq_putmem_hex(struct trace_seq *s, const void *mem, size_t len)
231 unsigned char hex[HEX_CHARS];
232 const unsigned char *data = mem;
239 for (i = 0, j = 0; i < len; i++) {
241 for (i = len-1, j = 0; i >= 0; i--) {
243 hex[j++] = hex_asc_hi(data[i]);
244 hex[j++] = hex_asc_lo(data[i]);
248 return trace_seq_putmem(s, hex, j);
251 void *trace_seq_reserve(struct trace_seq *s, size_t len)
258 if (len > ((PAGE_SIZE - 1) - s->len)) {
263 ret = s->buffer + s->len;
269 int trace_seq_path(struct trace_seq *s, struct path *path)
276 if (s->len >= (PAGE_SIZE - 1)) {
281 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
283 p = mangle_path(s->buffer + s->len, p, "\n");
285 s->len = p - s->buffer;
289 s->buffer[s->len++] = '?';
298 ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
300 const struct trace_print_flags *flag_array)
304 const char *ret = p->buffer + p->len;
307 for (i = 0; flag_array[i].name && flags; i++) {
309 mask = flag_array[i].mask;
310 if ((flags & mask) != mask)
313 str = flag_array[i].name;
316 trace_seq_puts(p, delim);
317 trace_seq_puts(p, str);
320 /* check for left over flags */
323 trace_seq_puts(p, delim);
324 trace_seq_printf(p, "0x%lx", flags);
327 trace_seq_putc(p, 0);
331 EXPORT_SYMBOL(ftrace_print_flags_seq);
334 ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
335 const struct trace_print_flags *symbol_array)
338 const char *ret = p->buffer + p->len;
340 for (i = 0; symbol_array[i].name; i++) {
342 if (val != symbol_array[i].mask)
345 trace_seq_puts(p, symbol_array[i].name);
350 trace_seq_printf(p, "0x%lx", val);
352 trace_seq_putc(p, 0);
356 EXPORT_SYMBOL(ftrace_print_symbols_seq);
358 #ifdef CONFIG_KRETPROBES
359 static inline const char *kretprobed(const char *name)
361 static const char tramp_name[] = "kretprobe_trampoline";
362 int size = sizeof(tramp_name);
364 if (strncmp(tramp_name, name, size) == 0)
365 return "[unknown/kretprobe'd]";
369 static inline const char *kretprobed(const char *name)
373 #endif /* CONFIG_KRETPROBES */
376 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
378 #ifdef CONFIG_KALLSYMS
379 char str[KSYM_SYMBOL_LEN];
382 kallsyms_lookup(address, NULL, NULL, NULL, str);
384 name = kretprobed(str);
386 return trace_seq_printf(s, fmt, name);
392 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
393 unsigned long address)
395 #ifdef CONFIG_KALLSYMS
396 char str[KSYM_SYMBOL_LEN];
399 sprint_symbol(str, address);
400 name = kretprobed(str);
402 return trace_seq_printf(s, fmt, name);
408 # define IP_FMT "%08lx"
410 # define IP_FMT "%016lx"
413 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
414 unsigned long ip, unsigned long sym_flags)
416 struct file *file = NULL;
417 unsigned long vmstart = 0;
424 const struct vm_area_struct *vma;
426 down_read(&mm->mmap_sem);
427 vma = find_vma(mm, ip);
430 vmstart = vma->vm_start;
433 ret = trace_seq_path(s, &file->f_path);
435 ret = trace_seq_printf(s, "[+0x%lx]",
438 up_read(&mm->mmap_sem);
440 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
441 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
446 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
447 unsigned long sym_flags)
449 struct mm_struct *mm = NULL;
453 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
454 struct task_struct *task;
456 * we do the lookup on the thread group leader,
457 * since individual threads might have already quit!
460 task = find_task_by_vpid(entry->tgid);
462 mm = get_task_mm(task);
466 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
467 unsigned long ip = entry->caller[i];
469 if (ip == ULONG_MAX || !ret)
472 ret = trace_seq_puts(s, " => ");
475 ret = trace_seq_puts(s, "??");
477 ret = trace_seq_puts(s, "\n");
483 ret = seq_print_user_ip(s, mm, ip, sym_flags);
484 ret = trace_seq_puts(s, "\n");
493 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
498 return trace_seq_printf(s, "0");
500 if (sym_flags & TRACE_ITER_SYM_OFFSET)
501 ret = seq_print_sym_offset(s, "%s", ip);
503 ret = seq_print_sym_short(s, "%s", ip);
508 if (sym_flags & TRACE_ITER_SYM_ADDR)
509 ret = trace_seq_printf(s, " <" IP_FMT ">", ip);
514 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
515 * @s: trace seq struct to write to
516 * @entry: The trace entry field from the ring buffer
518 * Prints the generic fields of irqs off, in hard or softirq, preempt
519 * count and lock depth.
521 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
523 int hardirq, softirq;
526 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
527 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
529 if (!trace_seq_printf(s, "%c%c%c",
530 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
531 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ?
533 (entry->flags & TRACE_FLAG_NEED_RESCHED) ?
535 (hardirq && softirq) ? 'H' :
536 hardirq ? 'h' : softirq ? 's' : '.'))
539 if (entry->preempt_count)
540 ret = trace_seq_printf(s, "%x", entry->preempt_count);
542 ret = trace_seq_putc(s, '.');
547 if (entry->lock_depth < 0)
548 return trace_seq_putc(s, '.');
550 return trace_seq_printf(s, "%d", entry->lock_depth);
554 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
556 char comm[TASK_COMM_LEN];
558 trace_find_cmdline(entry->pid, comm);
560 if (!trace_seq_printf(s, "%8.8s-%-5d %3d",
561 comm, entry->pid, cpu))
564 return trace_print_lat_fmt(s, entry);
567 static unsigned long preempt_mark_thresh = 100;
570 lat_print_timestamp(struct trace_seq *s, u64 abs_usecs,
571 unsigned long rel_usecs)
573 return trace_seq_printf(s, " %4lldus%c: ", abs_usecs,
574 rel_usecs > preempt_mark_thresh ? '!' :
575 rel_usecs > 1 ? '+' : ' ');
578 int trace_print_context(struct trace_iterator *iter)
580 struct trace_seq *s = &iter->seq;
581 struct trace_entry *entry = iter->ent;
582 unsigned long long t = ns2usecs(iter->ts);
583 unsigned long usec_rem = do_div(t, USEC_PER_SEC);
584 unsigned long secs = (unsigned long)t;
585 char comm[TASK_COMM_LEN];
587 trace_find_cmdline(entry->pid, comm);
589 return trace_seq_printf(s, "%16s-%-5d [%03d] %5lu.%06lu: ",
590 comm, entry->pid, iter->cpu, secs, usec_rem);
593 int trace_print_lat_context(struct trace_iterator *iter)
597 struct trace_seq *s = &iter->seq;
598 struct trace_entry *entry = iter->ent,
599 *next_entry = trace_find_next_entry(iter, NULL,
601 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
602 unsigned long abs_usecs = ns2usecs(iter->ts - iter->tr->time_start);
603 unsigned long rel_usecs;
607 rel_usecs = ns2usecs(next_ts - iter->ts);
610 char comm[TASK_COMM_LEN];
612 trace_find_cmdline(entry->pid, comm);
614 ret = trace_seq_printf(s, "%16s %5d %3d %d %08x %08lx [%08llx]"
615 " %ld.%03ldms (+%ld.%03ldms): ", comm,
616 entry->pid, iter->cpu, entry->flags,
617 entry->preempt_count, iter->idx,
619 abs_usecs / USEC_PER_MSEC,
620 abs_usecs % USEC_PER_MSEC,
621 rel_usecs / USEC_PER_MSEC,
622 rel_usecs % USEC_PER_MSEC);
624 ret = lat_print_generic(s, entry, iter->cpu);
626 ret = lat_print_timestamp(s, abs_usecs, rel_usecs);
632 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
634 static int task_state_char(unsigned long state)
636 int bit = state ? __ffs(state) + 1 : 0;
638 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
642 * ftrace_find_event - find a registered event
643 * @type: the type of event to look for
645 * Returns an event of type @type otherwise NULL
646 * Called with trace_event_read_lock() held.
648 struct trace_event *ftrace_find_event(int type)
650 struct trace_event *event;
651 struct hlist_node *n;
654 key = type & (EVENT_HASHSIZE - 1);
656 hlist_for_each_entry(event, n, &event_hash[key], node) {
657 if (event->type == type)
664 static LIST_HEAD(ftrace_event_list);
666 static int trace_search_list(struct list_head **list)
668 struct trace_event *e;
669 int last = __TRACE_LAST_TYPE;
671 if (list_empty(&ftrace_event_list)) {
672 *list = &ftrace_event_list;
677 * We used up all possible max events,
678 * lets see if somebody freed one.
680 list_for_each_entry(e, &ftrace_event_list, list) {
681 if (e->type != last + 1)
686 /* Did we used up all 65 thousand events??? */
687 if ((last + 1) > FTRACE_MAX_EVENT)
694 void trace_event_read_lock(void)
696 down_read(&trace_event_mutex);
699 void trace_event_read_unlock(void)
701 up_read(&trace_event_mutex);
705 * register_ftrace_event - register output for an event type
706 * @event: the event type to register
708 * Event types are stored in a hash and this hash is used to
709 * find a way to print an event. If the @event->type is set
710 * then it will use that type, otherwise it will assign a
713 * If you assign your own type, please make sure it is added
714 * to the trace_type enum in trace.h, to avoid collisions
715 * with the dynamic types.
717 * Returns the event type number or zero on error.
719 int register_ftrace_event(struct trace_event *event)
724 down_write(&trace_event_mutex);
729 if (WARN_ON(!event->funcs))
732 INIT_LIST_HEAD(&event->list);
735 struct list_head *list = NULL;
737 if (next_event_type > FTRACE_MAX_EVENT) {
739 event->type = trace_search_list(&list);
745 event->type = next_event_type++;
746 list = &ftrace_event_list;
749 if (WARN_ON(ftrace_find_event(event->type)))
752 list_add_tail(&event->list, list);
754 } else if (event->type > __TRACE_LAST_TYPE) {
755 printk(KERN_WARNING "Need to add type to trace.h\n");
759 /* Is this event already used */
760 if (ftrace_find_event(event->type))
764 if (event->funcs->trace == NULL)
765 event->funcs->trace = trace_nop_print;
766 if (event->funcs->raw == NULL)
767 event->funcs->raw = trace_nop_print;
768 if (event->funcs->hex == NULL)
769 event->funcs->hex = trace_nop_print;
770 if (event->funcs->binary == NULL)
771 event->funcs->binary = trace_nop_print;
773 key = event->type & (EVENT_HASHSIZE - 1);
775 hlist_add_head(&event->node, &event_hash[key]);
779 up_write(&trace_event_mutex);
783 EXPORT_SYMBOL_GPL(register_ftrace_event);
786 * Used by module code with the trace_event_mutex held for write.
788 int __unregister_ftrace_event(struct trace_event *event)
790 hlist_del(&event->node);
791 list_del(&event->list);
796 * unregister_ftrace_event - remove a no longer used event
797 * @event: the event to remove
799 int unregister_ftrace_event(struct trace_event *event)
801 down_write(&trace_event_mutex);
802 __unregister_ftrace_event(event);
803 up_write(&trace_event_mutex);
807 EXPORT_SYMBOL_GPL(unregister_ftrace_event);
813 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
814 struct trace_event *event)
816 return TRACE_TYPE_HANDLED;
820 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
821 struct trace_event *event)
823 struct ftrace_entry *field;
824 struct trace_seq *s = &iter->seq;
826 trace_assign_type(field, iter->ent);
828 if (!seq_print_ip_sym(s, field->ip, flags))
831 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
832 if (!trace_seq_printf(s, " <-"))
834 if (!seq_print_ip_sym(s,
839 if (!trace_seq_printf(s, "\n"))
842 return TRACE_TYPE_HANDLED;
845 return TRACE_TYPE_PARTIAL_LINE;
848 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
849 struct trace_event *event)
851 struct ftrace_entry *field;
853 trace_assign_type(field, iter->ent);
855 if (!trace_seq_printf(&iter->seq, "%lx %lx\n",
858 return TRACE_TYPE_PARTIAL_LINE;
860 return TRACE_TYPE_HANDLED;
863 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
864 struct trace_event *event)
866 struct ftrace_entry *field;
867 struct trace_seq *s = &iter->seq;
869 trace_assign_type(field, iter->ent);
871 SEQ_PUT_HEX_FIELD_RET(s, field->ip);
872 SEQ_PUT_HEX_FIELD_RET(s, field->parent_ip);
874 return TRACE_TYPE_HANDLED;
877 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
878 struct trace_event *event)
880 struct ftrace_entry *field;
881 struct trace_seq *s = &iter->seq;
883 trace_assign_type(field, iter->ent);
885 SEQ_PUT_FIELD_RET(s, field->ip);
886 SEQ_PUT_FIELD_RET(s, field->parent_ip);
888 return TRACE_TYPE_HANDLED;
891 static struct trace_event_functions trace_fn_funcs = {
892 .trace = trace_fn_trace,
895 .binary = trace_fn_bin,
898 static struct trace_event trace_fn_event = {
900 .funcs = &trace_fn_funcs,
903 /* TRACE_CTX an TRACE_WAKE */
904 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
907 struct ctx_switch_entry *field;
908 char comm[TASK_COMM_LEN];
912 trace_assign_type(field, iter->ent);
914 T = task_state_char(field->next_state);
915 S = task_state_char(field->prev_state);
916 trace_find_cmdline(field->next_pid, comm);
917 if (!trace_seq_printf(&iter->seq,
918 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
926 return TRACE_TYPE_PARTIAL_LINE;
928 return TRACE_TYPE_HANDLED;
931 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
932 struct trace_event *event)
934 return trace_ctxwake_print(iter, "==>");
937 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
938 int flags, struct trace_event *event)
940 return trace_ctxwake_print(iter, " +");
943 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
945 struct ctx_switch_entry *field;
948 trace_assign_type(field, iter->ent);
951 S = task_state_char(field->prev_state);
952 T = task_state_char(field->next_state);
953 if (!trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
961 return TRACE_TYPE_PARTIAL_LINE;
963 return TRACE_TYPE_HANDLED;
966 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
967 struct trace_event *event)
969 return trace_ctxwake_raw(iter, 0);
972 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
973 struct trace_event *event)
975 return trace_ctxwake_raw(iter, '+');
979 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
981 struct ctx_switch_entry *field;
982 struct trace_seq *s = &iter->seq;
985 trace_assign_type(field, iter->ent);
988 S = task_state_char(field->prev_state);
989 T = task_state_char(field->next_state);
991 SEQ_PUT_HEX_FIELD_RET(s, field->prev_pid);
992 SEQ_PUT_HEX_FIELD_RET(s, field->prev_prio);
993 SEQ_PUT_HEX_FIELD_RET(s, S);
994 SEQ_PUT_HEX_FIELD_RET(s, field->next_cpu);
995 SEQ_PUT_HEX_FIELD_RET(s, field->next_pid);
996 SEQ_PUT_HEX_FIELD_RET(s, field->next_prio);
997 SEQ_PUT_HEX_FIELD_RET(s, T);
999 return TRACE_TYPE_HANDLED;
1002 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
1003 struct trace_event *event)
1005 return trace_ctxwake_hex(iter, 0);
1008 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
1009 struct trace_event *event)
1011 return trace_ctxwake_hex(iter, '+');
1014 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
1015 int flags, struct trace_event *event)
1017 struct ctx_switch_entry *field;
1018 struct trace_seq *s = &iter->seq;
1020 trace_assign_type(field, iter->ent);
1022 SEQ_PUT_FIELD_RET(s, field->prev_pid);
1023 SEQ_PUT_FIELD_RET(s, field->prev_prio);
1024 SEQ_PUT_FIELD_RET(s, field->prev_state);
1025 SEQ_PUT_FIELD_RET(s, field->next_pid);
1026 SEQ_PUT_FIELD_RET(s, field->next_prio);
1027 SEQ_PUT_FIELD_RET(s, field->next_state);
1029 return TRACE_TYPE_HANDLED;
1032 static struct trace_event_functions trace_ctx_funcs = {
1033 .trace = trace_ctx_print,
1034 .raw = trace_ctx_raw,
1035 .hex = trace_ctx_hex,
1036 .binary = trace_ctxwake_bin,
1039 static struct trace_event trace_ctx_event = {
1041 .funcs = &trace_ctx_funcs,
1044 static struct trace_event_functions trace_wake_funcs = {
1045 .trace = trace_wake_print,
1046 .raw = trace_wake_raw,
1047 .hex = trace_wake_hex,
1048 .binary = trace_ctxwake_bin,
1051 static struct trace_event trace_wake_event = {
1053 .funcs = &trace_wake_funcs,
1057 static enum print_line_t trace_special_print(struct trace_iterator *iter,
1058 int flags, struct trace_event *event)
1060 struct special_entry *field;
1062 trace_assign_type(field, iter->ent);
1064 if (!trace_seq_printf(&iter->seq, "# %ld %ld %ld\n",
1068 return TRACE_TYPE_PARTIAL_LINE;
1070 return TRACE_TYPE_HANDLED;
1073 static enum print_line_t trace_special_hex(struct trace_iterator *iter,
1074 int flags, struct trace_event *event)
1076 struct special_entry *field;
1077 struct trace_seq *s = &iter->seq;
1079 trace_assign_type(field, iter->ent);
1081 SEQ_PUT_HEX_FIELD_RET(s, field->arg1);
1082 SEQ_PUT_HEX_FIELD_RET(s, field->arg2);
1083 SEQ_PUT_HEX_FIELD_RET(s, field->arg3);
1085 return TRACE_TYPE_HANDLED;
1088 static enum print_line_t trace_special_bin(struct trace_iterator *iter,
1089 int flags, struct trace_event *event)
1091 struct special_entry *field;
1092 struct trace_seq *s = &iter->seq;
1094 trace_assign_type(field, iter->ent);
1096 SEQ_PUT_FIELD_RET(s, field->arg1);
1097 SEQ_PUT_FIELD_RET(s, field->arg2);
1098 SEQ_PUT_FIELD_RET(s, field->arg3);
1100 return TRACE_TYPE_HANDLED;
1103 static struct trace_event_functions trace_special_funcs = {
1104 .trace = trace_special_print,
1105 .raw = trace_special_print,
1106 .hex = trace_special_hex,
1107 .binary = trace_special_bin,
1110 static struct trace_event trace_special_event = {
1111 .type = TRACE_SPECIAL,
1112 .funcs = &trace_special_funcs,
1117 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1118 int flags, struct trace_event *event)
1120 struct stack_entry *field;
1121 struct trace_seq *s = &iter->seq;
1124 trace_assign_type(field, iter->ent);
1126 if (!trace_seq_puts(s, "<stack trace>\n"))
1128 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
1129 if (!field->caller[i] || (field->caller[i] == ULONG_MAX))
1131 if (!trace_seq_puts(s, " => "))
1134 if (!seq_print_ip_sym(s, field->caller[i], flags))
1136 if (!trace_seq_puts(s, "\n"))
1140 return TRACE_TYPE_HANDLED;
1143 return TRACE_TYPE_PARTIAL_LINE;
1146 static struct trace_event_functions trace_stack_funcs = {
1147 .trace = trace_stack_print,
1148 .raw = trace_special_print,
1149 .hex = trace_special_hex,
1150 .binary = trace_special_bin,
1153 static struct trace_event trace_stack_event = {
1154 .type = TRACE_STACK,
1155 .funcs = &trace_stack_funcs,
1158 /* TRACE_USER_STACK */
1159 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1160 int flags, struct trace_event *event)
1162 struct userstack_entry *field;
1163 struct trace_seq *s = &iter->seq;
1165 trace_assign_type(field, iter->ent);
1167 if (!trace_seq_puts(s, "<user stack trace>\n"))
1170 if (!seq_print_userip_objs(field, s, flags))
1173 return TRACE_TYPE_HANDLED;
1176 return TRACE_TYPE_PARTIAL_LINE;
1179 static struct trace_event_functions trace_user_stack_funcs = {
1180 .trace = trace_user_stack_print,
1181 .raw = trace_special_print,
1182 .hex = trace_special_hex,
1183 .binary = trace_special_bin,
1186 static struct trace_event trace_user_stack_event = {
1187 .type = TRACE_USER_STACK,
1188 .funcs = &trace_user_stack_funcs,
1192 static enum print_line_t
1193 trace_bprint_print(struct trace_iterator *iter, int flags,
1194 struct trace_event *event)
1196 struct trace_entry *entry = iter->ent;
1197 struct trace_seq *s = &iter->seq;
1198 struct bprint_entry *field;
1200 trace_assign_type(field, entry);
1202 if (!seq_print_ip_sym(s, field->ip, flags))
1205 if (!trace_seq_puts(s, ": "))
1208 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1211 return TRACE_TYPE_HANDLED;
1214 return TRACE_TYPE_PARTIAL_LINE;
1218 static enum print_line_t
1219 trace_bprint_raw(struct trace_iterator *iter, int flags,
1220 struct trace_event *event)
1222 struct bprint_entry *field;
1223 struct trace_seq *s = &iter->seq;
1225 trace_assign_type(field, iter->ent);
1227 if (!trace_seq_printf(s, ": %lx : ", field->ip))
1230 if (!trace_seq_bprintf(s, field->fmt, field->buf))
1233 return TRACE_TYPE_HANDLED;
1236 return TRACE_TYPE_PARTIAL_LINE;
1239 static struct trace_event_functions trace_bprint_funcs = {
1240 .trace = trace_bprint_print,
1241 .raw = trace_bprint_raw,
1244 static struct trace_event trace_bprint_event = {
1245 .type = TRACE_BPRINT,
1246 .funcs = &trace_bprint_funcs,
1250 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1251 int flags, struct trace_event *event)
1253 struct print_entry *field;
1254 struct trace_seq *s = &iter->seq;
1256 trace_assign_type(field, iter->ent);
1258 if (!seq_print_ip_sym(s, field->ip, flags))
1261 if (!trace_seq_printf(s, ": %s", field->buf))
1264 return TRACE_TYPE_HANDLED;
1267 return TRACE_TYPE_PARTIAL_LINE;
1270 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1271 struct trace_event *event)
1273 struct print_entry *field;
1275 trace_assign_type(field, iter->ent);
1277 if (!trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf))
1280 return TRACE_TYPE_HANDLED;
1283 return TRACE_TYPE_PARTIAL_LINE;
1286 static struct trace_event_functions trace_print_funcs = {
1287 .trace = trace_print_print,
1288 .raw = trace_print_raw,
1291 static struct trace_event trace_print_event = {
1292 .type = TRACE_PRINT,
1293 .funcs = &trace_print_funcs,
1297 static struct trace_event *events[] __initdata = {
1301 &trace_special_event,
1303 &trace_user_stack_event,
1304 &trace_bprint_event,
1309 __init static int init_events(void)
1311 struct trace_event *event;
1314 for (i = 0; events[i]; i++) {
1317 ret = register_ftrace_event(event);
1319 printk(KERN_WARNING "event %d failed to register\n",
1327 device_initcall(init_events);