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
);
359 ftrace_print_hex_seq(struct trace_seq
*p
, const unsigned char *buf
, int buf_len
)
362 const char *ret
= p
->buffer
+ p
->len
;
364 for (i
= 0; i
< buf_len
; i
++)
365 trace_seq_printf(p
, "%s%2.2x", i
== 0 ? "" : " ", buf
[i
]);
367 trace_seq_putc(p
, 0);
371 EXPORT_SYMBOL(ftrace_print_hex_seq
);
373 #ifdef CONFIG_KRETPROBES
374 static inline const char *kretprobed(const char *name
)
376 static const char tramp_name
[] = "kretprobe_trampoline";
377 int size
= sizeof(tramp_name
);
379 if (strncmp(tramp_name
, name
, size
) == 0)
380 return "[unknown/kretprobe'd]";
384 static inline const char *kretprobed(const char *name
)
388 #endif /* CONFIG_KRETPROBES */
391 seq_print_sym_short(struct trace_seq
*s
, const char *fmt
, unsigned long address
)
393 #ifdef CONFIG_KALLSYMS
394 char str
[KSYM_SYMBOL_LEN
];
397 kallsyms_lookup(address
, NULL
, NULL
, NULL
, str
);
399 name
= kretprobed(str
);
401 return trace_seq_printf(s
, fmt
, name
);
407 seq_print_sym_offset(struct trace_seq
*s
, const char *fmt
,
408 unsigned long address
)
410 #ifdef CONFIG_KALLSYMS
411 char str
[KSYM_SYMBOL_LEN
];
414 sprint_symbol(str
, address
);
415 name
= kretprobed(str
);
417 return trace_seq_printf(s
, fmt
, name
);
423 # define IP_FMT "%08lx"
425 # define IP_FMT "%016lx"
428 int seq_print_user_ip(struct trace_seq
*s
, struct mm_struct
*mm
,
429 unsigned long ip
, unsigned long sym_flags
)
431 struct file
*file
= NULL
;
432 unsigned long vmstart
= 0;
439 const struct vm_area_struct
*vma
;
441 down_read(&mm
->mmap_sem
);
442 vma
= find_vma(mm
, ip
);
445 vmstart
= vma
->vm_start
;
448 ret
= trace_seq_path(s
, &file
->f_path
);
450 ret
= trace_seq_printf(s
, "[+0x%lx]",
453 up_read(&mm
->mmap_sem
);
455 if (ret
&& ((sym_flags
& TRACE_ITER_SYM_ADDR
) || !file
))
456 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
461 seq_print_userip_objs(const struct userstack_entry
*entry
, struct trace_seq
*s
,
462 unsigned long sym_flags
)
464 struct mm_struct
*mm
= NULL
;
468 if (trace_flags
& TRACE_ITER_SYM_USEROBJ
) {
469 struct task_struct
*task
;
471 * we do the lookup on the thread group leader,
472 * since individual threads might have already quit!
475 task
= find_task_by_vpid(entry
->tgid
);
477 mm
= get_task_mm(task
);
481 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
482 unsigned long ip
= entry
->caller
[i
];
484 if (ip
== ULONG_MAX
|| !ret
)
487 ret
= trace_seq_puts(s
, " => ");
490 ret
= trace_seq_puts(s
, "??");
492 ret
= trace_seq_puts(s
, "\n");
498 ret
= seq_print_user_ip(s
, mm
, ip
, sym_flags
);
499 ret
= trace_seq_puts(s
, "\n");
508 seq_print_ip_sym(struct trace_seq
*s
, unsigned long ip
, unsigned long sym_flags
)
513 return trace_seq_printf(s
, "0");
515 if (sym_flags
& TRACE_ITER_SYM_OFFSET
)
516 ret
= seq_print_sym_offset(s
, "%s", ip
);
518 ret
= seq_print_sym_short(s
, "%s", ip
);
523 if (sym_flags
& TRACE_ITER_SYM_ADDR
)
524 ret
= trace_seq_printf(s
, " <" IP_FMT
">", ip
);
529 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
530 * @s: trace seq struct to write to
531 * @entry: The trace entry field from the ring buffer
533 * Prints the generic fields of irqs off, in hard or softirq, preempt
534 * count and lock depth.
536 int trace_print_lat_fmt(struct trace_seq
*s
, struct trace_entry
*entry
)
538 int hardirq
, softirq
;
541 hardirq
= entry
->flags
& TRACE_FLAG_HARDIRQ
;
542 softirq
= entry
->flags
& TRACE_FLAG_SOFTIRQ
;
544 if (!trace_seq_printf(s
, "%c%c%c",
545 (entry
->flags
& TRACE_FLAG_IRQS_OFF
) ? 'd' :
546 (entry
->flags
& TRACE_FLAG_IRQS_NOSUPPORT
) ?
548 (entry
->flags
& TRACE_FLAG_NEED_RESCHED
) ?
550 (hardirq
&& softirq
) ? 'H' :
551 hardirq
? 'h' : softirq
? 's' : '.'))
554 if (entry
->preempt_count
)
555 ret
= trace_seq_printf(s
, "%x", entry
->preempt_count
);
557 ret
= trace_seq_putc(s
, '.');
562 if (entry
->lock_depth
< 0)
563 return trace_seq_putc(s
, '.');
565 return trace_seq_printf(s
, "%d", entry
->lock_depth
);
569 lat_print_generic(struct trace_seq
*s
, struct trace_entry
*entry
, int cpu
)
571 char comm
[TASK_COMM_LEN
];
573 trace_find_cmdline(entry
->pid
, comm
);
575 if (!trace_seq_printf(s
, "%8.8s-%-5d %3d",
576 comm
, entry
->pid
, cpu
))
579 return trace_print_lat_fmt(s
, entry
);
582 static unsigned long preempt_mark_thresh
= 100;
585 lat_print_timestamp(struct trace_seq
*s
, u64 abs_usecs
,
586 unsigned long rel_usecs
)
588 return trace_seq_printf(s
, " %4lldus%c: ", abs_usecs
,
589 rel_usecs
> preempt_mark_thresh
? '!' :
590 rel_usecs
> 1 ? '+' : ' ');
593 int trace_print_context(struct trace_iterator
*iter
)
595 struct trace_seq
*s
= &iter
->seq
;
596 struct trace_entry
*entry
= iter
->ent
;
597 unsigned long long t
= ns2usecs(iter
->ts
);
598 unsigned long usec_rem
= do_div(t
, USEC_PER_SEC
);
599 unsigned long secs
= (unsigned long)t
;
600 char comm
[TASK_COMM_LEN
];
602 trace_find_cmdline(entry
->pid
, comm
);
604 return trace_seq_printf(s
, "%16s-%-5d [%03d] %5lu.%06lu: ",
605 comm
, entry
->pid
, iter
->cpu
, secs
, usec_rem
);
608 int trace_print_lat_context(struct trace_iterator
*iter
)
612 struct trace_seq
*s
= &iter
->seq
;
613 struct trace_entry
*entry
= iter
->ent
,
614 *next_entry
= trace_find_next_entry(iter
, NULL
,
616 unsigned long verbose
= (trace_flags
& TRACE_ITER_VERBOSE
);
617 unsigned long abs_usecs
= ns2usecs(iter
->ts
- iter
->tr
->time_start
);
618 unsigned long rel_usecs
;
622 rel_usecs
= ns2usecs(next_ts
- iter
->ts
);
625 char comm
[TASK_COMM_LEN
];
627 trace_find_cmdline(entry
->pid
, comm
);
629 ret
= trace_seq_printf(s
, "%16s %5d %3d %d %08x %08lx [%08llx]"
630 " %ld.%03ldms (+%ld.%03ldms): ", comm
,
631 entry
->pid
, iter
->cpu
, entry
->flags
,
632 entry
->preempt_count
, iter
->idx
,
634 abs_usecs
/ USEC_PER_MSEC
,
635 abs_usecs
% USEC_PER_MSEC
,
636 rel_usecs
/ USEC_PER_MSEC
,
637 rel_usecs
% USEC_PER_MSEC
);
639 ret
= lat_print_generic(s
, entry
, iter
->cpu
);
641 ret
= lat_print_timestamp(s
, abs_usecs
, rel_usecs
);
647 static const char state_to_char
[] = TASK_STATE_TO_CHAR_STR
;
649 static int task_state_char(unsigned long state
)
651 int bit
= state
? __ffs(state
) + 1 : 0;
653 return bit
< sizeof(state_to_char
) - 1 ? state_to_char
[bit
] : '?';
657 * ftrace_find_event - find a registered event
658 * @type: the type of event to look for
660 * Returns an event of type @type otherwise NULL
661 * Called with trace_event_read_lock() held.
663 struct trace_event
*ftrace_find_event(int type
)
665 struct trace_event
*event
;
666 struct hlist_node
*n
;
669 key
= type
& (EVENT_HASHSIZE
- 1);
671 hlist_for_each_entry(event
, n
, &event_hash
[key
], node
) {
672 if (event
->type
== type
)
679 static LIST_HEAD(ftrace_event_list
);
681 static int trace_search_list(struct list_head
**list
)
683 struct trace_event
*e
;
684 int last
= __TRACE_LAST_TYPE
;
686 if (list_empty(&ftrace_event_list
)) {
687 *list
= &ftrace_event_list
;
692 * We used up all possible max events,
693 * lets see if somebody freed one.
695 list_for_each_entry(e
, &ftrace_event_list
, list
) {
696 if (e
->type
!= last
+ 1)
701 /* Did we used up all 65 thousand events??? */
702 if ((last
+ 1) > FTRACE_MAX_EVENT
)
709 void trace_event_read_lock(void)
711 down_read(&trace_event_mutex
);
714 void trace_event_read_unlock(void)
716 up_read(&trace_event_mutex
);
720 * register_ftrace_event - register output for an event type
721 * @event: the event type to register
723 * Event types are stored in a hash and this hash is used to
724 * find a way to print an event. If the @event->type is set
725 * then it will use that type, otherwise it will assign a
728 * If you assign your own type, please make sure it is added
729 * to the trace_type enum in trace.h, to avoid collisions
730 * with the dynamic types.
732 * Returns the event type number or zero on error.
734 int register_ftrace_event(struct trace_event
*event
)
739 down_write(&trace_event_mutex
);
744 INIT_LIST_HEAD(&event
->list
);
747 struct list_head
*list
= NULL
;
749 if (next_event_type
> FTRACE_MAX_EVENT
) {
751 event
->type
= trace_search_list(&list
);
757 event
->type
= next_event_type
++;
758 list
= &ftrace_event_list
;
761 if (WARN_ON(ftrace_find_event(event
->type
)))
764 list_add_tail(&event
->list
, list
);
766 } else if (event
->type
> __TRACE_LAST_TYPE
) {
767 printk(KERN_WARNING
"Need to add type to trace.h\n");
771 /* Is this event already used */
772 if (ftrace_find_event(event
->type
))
776 if (event
->trace
== NULL
)
777 event
->trace
= trace_nop_print
;
778 if (event
->raw
== NULL
)
779 event
->raw
= trace_nop_print
;
780 if (event
->hex
== NULL
)
781 event
->hex
= trace_nop_print
;
782 if (event
->binary
== NULL
)
783 event
->binary
= trace_nop_print
;
785 key
= event
->type
& (EVENT_HASHSIZE
- 1);
787 hlist_add_head(&event
->node
, &event_hash
[key
]);
791 up_write(&trace_event_mutex
);
795 EXPORT_SYMBOL_GPL(register_ftrace_event
);
798 * Used by module code with the trace_event_mutex held for write.
800 int __unregister_ftrace_event(struct trace_event
*event
)
802 hlist_del(&event
->node
);
803 list_del(&event
->list
);
808 * unregister_ftrace_event - remove a no longer used event
809 * @event: the event to remove
811 int unregister_ftrace_event(struct trace_event
*event
)
813 down_write(&trace_event_mutex
);
814 __unregister_ftrace_event(event
);
815 up_write(&trace_event_mutex
);
819 EXPORT_SYMBOL_GPL(unregister_ftrace_event
);
825 enum print_line_t
trace_nop_print(struct trace_iterator
*iter
, int flags
)
827 return TRACE_TYPE_HANDLED
;
831 static enum print_line_t
trace_fn_trace(struct trace_iterator
*iter
, int flags
)
833 struct ftrace_entry
*field
;
834 struct trace_seq
*s
= &iter
->seq
;
836 trace_assign_type(field
, iter
->ent
);
838 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
841 if ((flags
& TRACE_ITER_PRINT_PARENT
) && field
->parent_ip
) {
842 if (!trace_seq_printf(s
, " <-"))
844 if (!seq_print_ip_sym(s
,
849 if (!trace_seq_printf(s
, "\n"))
852 return TRACE_TYPE_HANDLED
;
855 return TRACE_TYPE_PARTIAL_LINE
;
858 static enum print_line_t
trace_fn_raw(struct trace_iterator
*iter
, int flags
)
860 struct ftrace_entry
*field
;
862 trace_assign_type(field
, iter
->ent
);
864 if (!trace_seq_printf(&iter
->seq
, "%lx %lx\n",
867 return TRACE_TYPE_PARTIAL_LINE
;
869 return TRACE_TYPE_HANDLED
;
872 static enum print_line_t
trace_fn_hex(struct trace_iterator
*iter
, int flags
)
874 struct ftrace_entry
*field
;
875 struct trace_seq
*s
= &iter
->seq
;
877 trace_assign_type(field
, iter
->ent
);
879 SEQ_PUT_HEX_FIELD_RET(s
, field
->ip
);
880 SEQ_PUT_HEX_FIELD_RET(s
, field
->parent_ip
);
882 return TRACE_TYPE_HANDLED
;
885 static enum print_line_t
trace_fn_bin(struct trace_iterator
*iter
, int flags
)
887 struct ftrace_entry
*field
;
888 struct trace_seq
*s
= &iter
->seq
;
890 trace_assign_type(field
, iter
->ent
);
892 SEQ_PUT_FIELD_RET(s
, field
->ip
);
893 SEQ_PUT_FIELD_RET(s
, field
->parent_ip
);
895 return TRACE_TYPE_HANDLED
;
898 static struct trace_event trace_fn_event
= {
900 .trace
= trace_fn_trace
,
903 .binary
= trace_fn_bin
,
906 /* TRACE_CTX an TRACE_WAKE */
907 static enum print_line_t
trace_ctxwake_print(struct trace_iterator
*iter
,
910 struct ctx_switch_entry
*field
;
911 char comm
[TASK_COMM_LEN
];
915 trace_assign_type(field
, iter
->ent
);
917 T
= task_state_char(field
->next_state
);
918 S
= task_state_char(field
->prev_state
);
919 trace_find_cmdline(field
->next_pid
, comm
);
920 if (!trace_seq_printf(&iter
->seq
,
921 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
929 return TRACE_TYPE_PARTIAL_LINE
;
931 return TRACE_TYPE_HANDLED
;
934 static enum print_line_t
trace_ctx_print(struct trace_iterator
*iter
, int flags
)
936 return trace_ctxwake_print(iter
, "==>");
939 static enum print_line_t
trace_wake_print(struct trace_iterator
*iter
,
942 return trace_ctxwake_print(iter
, " +");
945 static int trace_ctxwake_raw(struct trace_iterator
*iter
, char S
)
947 struct ctx_switch_entry
*field
;
950 trace_assign_type(field
, iter
->ent
);
953 S
= task_state_char(field
->prev_state
);
954 T
= task_state_char(field
->next_state
);
955 if (!trace_seq_printf(&iter
->seq
, "%d %d %c %d %d %d %c\n",
963 return TRACE_TYPE_PARTIAL_LINE
;
965 return TRACE_TYPE_HANDLED
;
968 static enum print_line_t
trace_ctx_raw(struct trace_iterator
*iter
, int flags
)
970 return trace_ctxwake_raw(iter
, 0);
973 static enum print_line_t
trace_wake_raw(struct trace_iterator
*iter
, int flags
)
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
)
1004 return trace_ctxwake_hex(iter
, 0);
1007 static enum print_line_t
trace_wake_hex(struct trace_iterator
*iter
, int flags
)
1009 return trace_ctxwake_hex(iter
, '+');
1012 static enum print_line_t
trace_ctxwake_bin(struct trace_iterator
*iter
,
1015 struct ctx_switch_entry
*field
;
1016 struct trace_seq
*s
= &iter
->seq
;
1018 trace_assign_type(field
, iter
->ent
);
1020 SEQ_PUT_FIELD_RET(s
, field
->prev_pid
);
1021 SEQ_PUT_FIELD_RET(s
, field
->prev_prio
);
1022 SEQ_PUT_FIELD_RET(s
, field
->prev_state
);
1023 SEQ_PUT_FIELD_RET(s
, field
->next_pid
);
1024 SEQ_PUT_FIELD_RET(s
, field
->next_prio
);
1025 SEQ_PUT_FIELD_RET(s
, field
->next_state
);
1027 return TRACE_TYPE_HANDLED
;
1030 static struct trace_event trace_ctx_event
= {
1032 .trace
= trace_ctx_print
,
1033 .raw
= trace_ctx_raw
,
1034 .hex
= trace_ctx_hex
,
1035 .binary
= trace_ctxwake_bin
,
1038 static struct trace_event trace_wake_event
= {
1040 .trace
= trace_wake_print
,
1041 .raw
= trace_wake_raw
,
1042 .hex
= trace_wake_hex
,
1043 .binary
= trace_ctxwake_bin
,
1047 static enum print_line_t
trace_special_print(struct trace_iterator
*iter
,
1050 struct special_entry
*field
;
1052 trace_assign_type(field
, iter
->ent
);
1054 if (!trace_seq_printf(&iter
->seq
, "# %ld %ld %ld\n",
1058 return TRACE_TYPE_PARTIAL_LINE
;
1060 return TRACE_TYPE_HANDLED
;
1063 static enum print_line_t
trace_special_hex(struct trace_iterator
*iter
,
1066 struct special_entry
*field
;
1067 struct trace_seq
*s
= &iter
->seq
;
1069 trace_assign_type(field
, iter
->ent
);
1071 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg1
);
1072 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg2
);
1073 SEQ_PUT_HEX_FIELD_RET(s
, field
->arg3
);
1075 return TRACE_TYPE_HANDLED
;
1078 static enum print_line_t
trace_special_bin(struct trace_iterator
*iter
,
1081 struct special_entry
*field
;
1082 struct trace_seq
*s
= &iter
->seq
;
1084 trace_assign_type(field
, iter
->ent
);
1086 SEQ_PUT_FIELD_RET(s
, field
->arg1
);
1087 SEQ_PUT_FIELD_RET(s
, field
->arg2
);
1088 SEQ_PUT_FIELD_RET(s
, field
->arg3
);
1090 return TRACE_TYPE_HANDLED
;
1093 static struct trace_event trace_special_event
= {
1094 .type
= TRACE_SPECIAL
,
1095 .trace
= trace_special_print
,
1096 .raw
= trace_special_print
,
1097 .hex
= trace_special_hex
,
1098 .binary
= trace_special_bin
,
1103 static enum print_line_t
trace_stack_print(struct trace_iterator
*iter
,
1106 struct stack_entry
*field
;
1107 struct trace_seq
*s
= &iter
->seq
;
1110 trace_assign_type(field
, iter
->ent
);
1112 if (!trace_seq_puts(s
, "<stack trace>\n"))
1114 for (i
= 0; i
< FTRACE_STACK_ENTRIES
; i
++) {
1115 if (!field
->caller
[i
] || (field
->caller
[i
] == ULONG_MAX
))
1117 if (!trace_seq_puts(s
, " => "))
1120 if (!seq_print_ip_sym(s
, field
->caller
[i
], flags
))
1122 if (!trace_seq_puts(s
, "\n"))
1126 return TRACE_TYPE_HANDLED
;
1129 return TRACE_TYPE_PARTIAL_LINE
;
1132 static struct trace_event trace_stack_event
= {
1133 .type
= TRACE_STACK
,
1134 .trace
= trace_stack_print
,
1135 .raw
= trace_special_print
,
1136 .hex
= trace_special_hex
,
1137 .binary
= trace_special_bin
,
1140 /* TRACE_USER_STACK */
1141 static enum print_line_t
trace_user_stack_print(struct trace_iterator
*iter
,
1144 struct userstack_entry
*field
;
1145 struct trace_seq
*s
= &iter
->seq
;
1147 trace_assign_type(field
, iter
->ent
);
1149 if (!trace_seq_puts(s
, "<user stack trace>\n"))
1152 if (!seq_print_userip_objs(field
, s
, flags
))
1155 return TRACE_TYPE_HANDLED
;
1158 return TRACE_TYPE_PARTIAL_LINE
;
1161 static struct trace_event trace_user_stack_event
= {
1162 .type
= TRACE_USER_STACK
,
1163 .trace
= trace_user_stack_print
,
1164 .raw
= trace_special_print
,
1165 .hex
= trace_special_hex
,
1166 .binary
= trace_special_bin
,
1170 static enum print_line_t
1171 trace_bprint_print(struct trace_iterator
*iter
, int flags
)
1173 struct trace_entry
*entry
= iter
->ent
;
1174 struct trace_seq
*s
= &iter
->seq
;
1175 struct bprint_entry
*field
;
1177 trace_assign_type(field
, entry
);
1179 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1182 if (!trace_seq_puts(s
, ": "))
1185 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1188 return TRACE_TYPE_HANDLED
;
1191 return TRACE_TYPE_PARTIAL_LINE
;
1195 static enum print_line_t
1196 trace_bprint_raw(struct trace_iterator
*iter
, int flags
)
1198 struct bprint_entry
*field
;
1199 struct trace_seq
*s
= &iter
->seq
;
1201 trace_assign_type(field
, iter
->ent
);
1203 if (!trace_seq_printf(s
, ": %lx : ", field
->ip
))
1206 if (!trace_seq_bprintf(s
, field
->fmt
, field
->buf
))
1209 return TRACE_TYPE_HANDLED
;
1212 return TRACE_TYPE_PARTIAL_LINE
;
1216 static struct trace_event trace_bprint_event
= {
1217 .type
= TRACE_BPRINT
,
1218 .trace
= trace_bprint_print
,
1219 .raw
= trace_bprint_raw
,
1223 static enum print_line_t
trace_print_print(struct trace_iterator
*iter
,
1226 struct print_entry
*field
;
1227 struct trace_seq
*s
= &iter
->seq
;
1229 trace_assign_type(field
, iter
->ent
);
1231 if (!seq_print_ip_sym(s
, field
->ip
, flags
))
1234 if (!trace_seq_printf(s
, ": %s", field
->buf
))
1237 return TRACE_TYPE_HANDLED
;
1240 return TRACE_TYPE_PARTIAL_LINE
;
1243 static enum print_line_t
trace_print_raw(struct trace_iterator
*iter
, int flags
)
1245 struct print_entry
*field
;
1247 trace_assign_type(field
, iter
->ent
);
1249 if (!trace_seq_printf(&iter
->seq
, "# %lx %s", field
->ip
, field
->buf
))
1252 return TRACE_TYPE_HANDLED
;
1255 return TRACE_TYPE_PARTIAL_LINE
;
1258 static struct trace_event trace_print_event
= {
1259 .type
= TRACE_PRINT
,
1260 .trace
= trace_print_print
,
1261 .raw
= trace_print_raw
,
1265 static struct trace_event
*events
[] __initdata
= {
1269 &trace_special_event
,
1271 &trace_user_stack_event
,
1272 &trace_bprint_event
,
1277 __init
static int init_events(void)
1279 struct trace_event
*event
;
1282 for (i
= 0; events
[i
]; i
++) {
1285 ret
= register_ftrace_event(event
);
1287 printk(KERN_WARNING
"event %d failed to register\n",
1295 device_initcall(init_events
);