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_sem);
19 static struct hlist_head event_hash[EVENT_HASHSIZE] __read_mostly;
21 static int next_event_type = __TRACE_LAST_TYPE + 1;
23 enum print_line_t trace_print_bputs_msg_only(struct trace_iterator *iter)
25 struct trace_seq *s = &iter->seq;
26 struct trace_entry *entry = iter->ent;
27 struct bputs_entry *field;
29 trace_assign_type(field, entry);
31 trace_seq_puts(s, field->str);
33 return trace_handle_return(s);
36 enum print_line_t trace_print_bprintk_msg_only(struct trace_iterator *iter)
38 struct trace_seq *s = &iter->seq;
39 struct trace_entry *entry = iter->ent;
40 struct bprint_entry *field;
42 trace_assign_type(field, entry);
44 trace_seq_bprintf(s, field->fmt, field->buf);
46 return trace_handle_return(s);
49 enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
51 struct trace_seq *s = &iter->seq;
52 struct trace_entry *entry = iter->ent;
53 struct print_entry *field;
55 trace_assign_type(field, entry);
57 trace_seq_puts(s, field->buf);
59 return trace_handle_return(s);
63 ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
65 const struct trace_print_flags *flag_array)
69 const char *ret = trace_seq_buffer_ptr(p);
72 for (i = 0; flag_array[i].name && flags; i++) {
74 mask = flag_array[i].mask;
75 if ((flags & mask) != mask)
78 str = flag_array[i].name;
81 trace_seq_puts(p, delim);
84 trace_seq_puts(p, str);
87 /* check for left over flags */
90 trace_seq_puts(p, delim);
91 trace_seq_printf(p, "0x%lx", flags);
98 EXPORT_SYMBOL(ftrace_print_flags_seq);
101 ftrace_print_symbols_seq(struct trace_seq *p, unsigned long val,
102 const struct trace_print_flags *symbol_array)
105 const char *ret = trace_seq_buffer_ptr(p);
107 for (i = 0; symbol_array[i].name; i++) {
109 if (val != symbol_array[i].mask)
112 trace_seq_puts(p, symbol_array[i].name);
116 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
117 trace_seq_printf(p, "0x%lx", val);
119 trace_seq_putc(p, 0);
123 EXPORT_SYMBOL(ftrace_print_symbols_seq);
125 #if BITS_PER_LONG == 32
127 ftrace_print_symbols_seq_u64(struct trace_seq *p, unsigned long long val,
128 const struct trace_print_flags_u64 *symbol_array)
131 const char *ret = trace_seq_buffer_ptr(p);
133 for (i = 0; symbol_array[i].name; i++) {
135 if (val != symbol_array[i].mask)
138 trace_seq_puts(p, symbol_array[i].name);
142 if (ret == (const char *)(trace_seq_buffer_ptr(p)))
143 trace_seq_printf(p, "0x%llx", val);
145 trace_seq_putc(p, 0);
149 EXPORT_SYMBOL(ftrace_print_symbols_seq_u64);
153 ftrace_print_bitmask_seq(struct trace_seq *p, void *bitmask_ptr,
154 unsigned int bitmask_size)
156 const char *ret = trace_seq_buffer_ptr(p);
158 trace_seq_bitmask(p, bitmask_ptr, bitmask_size * 8);
159 trace_seq_putc(p, 0);
163 EXPORT_SYMBOL_GPL(ftrace_print_bitmask_seq);
166 ftrace_print_hex_seq(struct trace_seq *p, const unsigned char *buf, int buf_len)
169 const char *ret = trace_seq_buffer_ptr(p);
171 for (i = 0; i < buf_len; i++)
172 trace_seq_printf(p, "%s%2.2x", i == 0 ? "" : " ", buf[i]);
174 trace_seq_putc(p, 0);
178 EXPORT_SYMBOL(ftrace_print_hex_seq);
180 int ftrace_raw_output_prep(struct trace_iterator *iter,
181 struct trace_event *trace_event)
183 struct ftrace_event_call *event;
184 struct trace_seq *s = &iter->seq;
185 struct trace_seq *p = &iter->tmp_seq;
186 struct trace_entry *entry;
188 event = container_of(trace_event, struct ftrace_event_call, event);
191 if (entry->type != event->event.type) {
193 return TRACE_TYPE_UNHANDLED;
197 trace_seq_printf(s, "%s: ", ftrace_event_name(event));
199 return trace_handle_return(s);
201 EXPORT_SYMBOL(ftrace_raw_output_prep);
203 static int ftrace_output_raw(struct trace_iterator *iter, char *name,
204 char *fmt, va_list ap)
206 struct trace_seq *s = &iter->seq;
208 trace_seq_printf(s, "%s: ", name);
209 trace_seq_vprintf(s, fmt, ap);
211 return trace_handle_return(s);
214 int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
220 ret = ftrace_output_raw(iter, name, fmt, ap);
225 EXPORT_SYMBOL_GPL(ftrace_output_call);
227 #ifdef CONFIG_KRETPROBES
228 static inline const char *kretprobed(const char *name)
230 static const char tramp_name[] = "kretprobe_trampoline";
231 int size = sizeof(tramp_name);
233 if (strncmp(tramp_name, name, size) == 0)
234 return "[unknown/kretprobe'd]";
238 static inline const char *kretprobed(const char *name)
242 #endif /* CONFIG_KRETPROBES */
245 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
247 #ifdef CONFIG_KALLSYMS
248 char str[KSYM_SYMBOL_LEN];
251 kallsyms_lookup(address, NULL, NULL, NULL, str);
253 name = kretprobed(str);
255 trace_seq_printf(s, fmt, name);
260 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
261 unsigned long address)
263 #ifdef CONFIG_KALLSYMS
264 char str[KSYM_SYMBOL_LEN];
267 sprint_symbol(str, address);
268 name = kretprobed(str);
270 trace_seq_printf(s, fmt, name);
275 # define IP_FMT "%08lx"
277 # define IP_FMT "%016lx"
280 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
281 unsigned long ip, unsigned long sym_flags)
283 struct file *file = NULL;
284 unsigned long vmstart = 0;
291 const struct vm_area_struct *vma;
293 down_read(&mm->mmap_sem);
294 vma = find_vma(mm, ip);
297 vmstart = vma->vm_start;
300 ret = trace_seq_path(s, &file->f_path);
302 trace_seq_printf(s, "[+0x%lx]",
305 up_read(&mm->mmap_sem);
307 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
308 trace_seq_printf(s, " <" IP_FMT ">", ip);
309 return !trace_seq_has_overflowed(s);
313 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
314 unsigned long sym_flags)
316 struct mm_struct *mm = NULL;
319 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
320 struct task_struct *task;
322 * we do the lookup on the thread group leader,
323 * since individual threads might have already quit!
326 task = find_task_by_vpid(entry->tgid);
328 mm = get_task_mm(task);
332 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
333 unsigned long ip = entry->caller[i];
335 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
338 trace_seq_puts(s, " => ");
341 trace_seq_puts(s, "??");
342 trace_seq_putc(s, '\n');
346 seq_print_user_ip(s, mm, ip, sym_flags);
347 trace_seq_putc(s, '\n');
353 return !trace_seq_has_overflowed(s);
357 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
360 trace_seq_putc(s, '0');
364 if (sym_flags & TRACE_ITER_SYM_OFFSET)
365 seq_print_sym_offset(s, "%s", ip);
367 seq_print_sym_short(s, "%s", ip);
369 if (sym_flags & TRACE_ITER_SYM_ADDR)
370 trace_seq_printf(s, " <" IP_FMT ">", ip);
373 return !trace_seq_has_overflowed(s);
377 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
378 * @s: trace seq struct to write to
379 * @entry: The trace entry field from the ring buffer
381 * Prints the generic fields of irqs off, in hard or softirq, preempt
384 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
392 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
393 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
396 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
397 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
400 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
401 TRACE_FLAG_PREEMPT_RESCHED)) {
402 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
405 case TRACE_FLAG_NEED_RESCHED:
408 case TRACE_FLAG_PREEMPT_RESCHED:
417 (hardirq && softirq) ? 'H' :
422 trace_seq_printf(s, "%c%c%c",
423 irqs_off, need_resched, hardsoft_irq);
425 if (entry->preempt_count)
426 trace_seq_printf(s, "%x", entry->preempt_count);
428 trace_seq_putc(s, '.');
430 return !trace_seq_has_overflowed(s);
434 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
436 char comm[TASK_COMM_LEN];
438 trace_find_cmdline(entry->pid, comm);
440 trace_seq_printf(s, "%8.8s-%-5d %3d",
441 comm, entry->pid, cpu);
443 return trace_print_lat_fmt(s, entry);
447 #define MARK(v, s) {.val = v, .sym = s}
448 /* trace overhead mark */
449 static const struct trace_mark {
450 unsigned long long val; /* unit: nsec */
453 MARK(1000000000ULL , '$'), /* 1 sec */
454 MARK(1000000ULL , '#'), /* 1000 usecs */
455 MARK(100000ULL , '!'), /* 100 usecs */
456 MARK(10000ULL , '+'), /* 10 usecs */
460 char trace_find_mark(unsigned long long d)
463 int size = ARRAY_SIZE(mark);
465 for (i = 0; i < size; i++) {
466 if (d >= mark[i].val)
470 return (i == size) ? ' ' : mark[i].sym;
474 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
476 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
477 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
478 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
479 unsigned long long rel_ts = next_ts - iter->ts;
480 struct trace_seq *s = &iter->seq;
483 abs_ts = ns2usecs(abs_ts);
484 rel_ts = ns2usecs(rel_ts);
487 if (verbose && in_ns) {
488 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
489 unsigned long abs_msec = (unsigned long)abs_ts;
490 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
491 unsigned long rel_msec = (unsigned long)rel_ts;
494 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
499 } else if (verbose && !in_ns) {
501 s, "[%016llx] %lld (+%lld): ",
502 iter->ts, abs_ts, rel_ts);
504 } else if (!verbose && in_ns) {
508 trace_find_mark(rel_ts * NSEC_PER_USEC));
510 } else { /* !verbose && !in_ns */
511 trace_seq_printf(s, " %4lld: ", abs_ts);
514 return !trace_seq_has_overflowed(s);
517 int trace_print_context(struct trace_iterator *iter)
519 struct trace_seq *s = &iter->seq;
520 struct trace_entry *entry = iter->ent;
521 unsigned long long t;
522 unsigned long secs, usec_rem;
523 char comm[TASK_COMM_LEN];
525 trace_find_cmdline(entry->pid, comm);
527 trace_seq_printf(s, "%16s-%-5d [%03d] ",
528 comm, entry->pid, iter->cpu);
530 if (trace_flags & TRACE_ITER_IRQ_INFO)
531 trace_print_lat_fmt(s, entry);
533 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
534 t = ns2usecs(iter->ts);
535 usec_rem = do_div(t, USEC_PER_SEC);
536 secs = (unsigned long)t;
537 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
539 trace_seq_printf(s, " %12llu: ", iter->ts);
541 return !trace_seq_has_overflowed(s);
544 int trace_print_lat_context(struct trace_iterator *iter)
547 /* trace_find_next_entry will reset ent_size */
548 int ent_size = iter->ent_size;
549 struct trace_seq *s = &iter->seq;
550 struct trace_entry *entry = iter->ent,
551 *next_entry = trace_find_next_entry(iter, NULL,
553 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
555 /* Restore the original ent_size */
556 iter->ent_size = ent_size;
562 char comm[TASK_COMM_LEN];
564 trace_find_cmdline(entry->pid, comm);
567 s, "%16s %5d %3d %d %08x %08lx ",
568 comm, entry->pid, iter->cpu, entry->flags,
569 entry->preempt_count, iter->idx);
571 lat_print_generic(s, entry, iter->cpu);
574 lat_print_timestamp(iter, next_ts);
576 return !trace_seq_has_overflowed(s);
579 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
581 static int task_state_char(unsigned long state)
583 int bit = state ? __ffs(state) + 1 : 0;
585 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
589 * ftrace_find_event - find a registered event
590 * @type: the type of event to look for
592 * Returns an event of type @type otherwise NULL
593 * Called with trace_event_read_lock() held.
595 struct trace_event *ftrace_find_event(int type)
597 struct trace_event *event;
600 key = type & (EVENT_HASHSIZE - 1);
602 hlist_for_each_entry(event, &event_hash[key], node) {
603 if (event->type == type)
610 static LIST_HEAD(ftrace_event_list);
612 static int trace_search_list(struct list_head **list)
614 struct trace_event *e;
615 int last = __TRACE_LAST_TYPE;
617 if (list_empty(&ftrace_event_list)) {
618 *list = &ftrace_event_list;
623 * We used up all possible max events,
624 * lets see if somebody freed one.
626 list_for_each_entry(e, &ftrace_event_list, list) {
627 if (e->type != last + 1)
632 /* Did we used up all 65 thousand events??? */
633 if ((last + 1) > FTRACE_MAX_EVENT)
640 void trace_event_read_lock(void)
642 down_read(&trace_event_sem);
645 void trace_event_read_unlock(void)
647 up_read(&trace_event_sem);
651 * register_ftrace_event - register output for an event type
652 * @event: the event type to register
654 * Event types are stored in a hash and this hash is used to
655 * find a way to print an event. If the @event->type is set
656 * then it will use that type, otherwise it will assign a
659 * If you assign your own type, please make sure it is added
660 * to the trace_type enum in trace.h, to avoid collisions
661 * with the dynamic types.
663 * Returns the event type number or zero on error.
665 int register_ftrace_event(struct trace_event *event)
670 down_write(&trace_event_sem);
675 if (WARN_ON(!event->funcs))
678 INIT_LIST_HEAD(&event->list);
681 struct list_head *list = NULL;
683 if (next_event_type > FTRACE_MAX_EVENT) {
685 event->type = trace_search_list(&list);
691 event->type = next_event_type++;
692 list = &ftrace_event_list;
695 if (WARN_ON(ftrace_find_event(event->type)))
698 list_add_tail(&event->list, list);
700 } else if (event->type > __TRACE_LAST_TYPE) {
701 printk(KERN_WARNING "Need to add type to trace.h\n");
705 /* Is this event already used */
706 if (ftrace_find_event(event->type))
710 if (event->funcs->trace == NULL)
711 event->funcs->trace = trace_nop_print;
712 if (event->funcs->raw == NULL)
713 event->funcs->raw = trace_nop_print;
714 if (event->funcs->hex == NULL)
715 event->funcs->hex = trace_nop_print;
716 if (event->funcs->binary == NULL)
717 event->funcs->binary = trace_nop_print;
719 key = event->type & (EVENT_HASHSIZE - 1);
721 hlist_add_head(&event->node, &event_hash[key]);
725 up_write(&trace_event_sem);
729 EXPORT_SYMBOL_GPL(register_ftrace_event);
732 * Used by module code with the trace_event_sem held for write.
734 int __unregister_ftrace_event(struct trace_event *event)
736 hlist_del(&event->node);
737 list_del(&event->list);
742 * unregister_ftrace_event - remove a no longer used event
743 * @event: the event to remove
745 int unregister_ftrace_event(struct trace_event *event)
747 down_write(&trace_event_sem);
748 __unregister_ftrace_event(event);
749 up_write(&trace_event_sem);
753 EXPORT_SYMBOL_GPL(unregister_ftrace_event);
759 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
760 struct trace_event *event)
762 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
764 return trace_handle_return(&iter->seq);
768 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
769 struct trace_event *event)
771 struct ftrace_entry *field;
772 struct trace_seq *s = &iter->seq;
774 trace_assign_type(field, iter->ent);
776 seq_print_ip_sym(s, field->ip, flags);
778 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
779 trace_seq_puts(s, " <-");
780 seq_print_ip_sym(s, field->parent_ip, flags);
783 trace_seq_putc(s, '\n');
785 return trace_handle_return(s);
788 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
789 struct trace_event *event)
791 struct ftrace_entry *field;
793 trace_assign_type(field, iter->ent);
795 trace_seq_printf(&iter->seq, "%lx %lx\n",
799 return trace_handle_return(&iter->seq);
802 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
803 struct trace_event *event)
805 struct ftrace_entry *field;
806 struct trace_seq *s = &iter->seq;
808 trace_assign_type(field, iter->ent);
810 SEQ_PUT_HEX_FIELD(s, field->ip);
811 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
813 return trace_handle_return(s);
816 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
817 struct trace_event *event)
819 struct ftrace_entry *field;
820 struct trace_seq *s = &iter->seq;
822 trace_assign_type(field, iter->ent);
824 SEQ_PUT_FIELD(s, field->ip);
825 SEQ_PUT_FIELD(s, field->parent_ip);
827 return trace_handle_return(s);
830 static struct trace_event_functions trace_fn_funcs = {
831 .trace = trace_fn_trace,
834 .binary = trace_fn_bin,
837 static struct trace_event trace_fn_event = {
839 .funcs = &trace_fn_funcs,
842 /* TRACE_CTX an TRACE_WAKE */
843 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
846 struct ctx_switch_entry *field;
847 char comm[TASK_COMM_LEN];
851 trace_assign_type(field, iter->ent);
853 T = task_state_char(field->next_state);
854 S = task_state_char(field->prev_state);
855 trace_find_cmdline(field->next_pid, comm);
856 trace_seq_printf(&iter->seq,
857 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
866 return trace_handle_return(&iter->seq);
869 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
870 struct trace_event *event)
872 return trace_ctxwake_print(iter, "==>");
875 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
876 int flags, struct trace_event *event)
878 return trace_ctxwake_print(iter, " +");
881 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
883 struct ctx_switch_entry *field;
886 trace_assign_type(field, iter->ent);
889 S = task_state_char(field->prev_state);
890 T = task_state_char(field->next_state);
891 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
900 return trace_handle_return(&iter->seq);
903 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
904 struct trace_event *event)
906 return trace_ctxwake_raw(iter, 0);
909 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
910 struct trace_event *event)
912 return trace_ctxwake_raw(iter, '+');
916 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
918 struct ctx_switch_entry *field;
919 struct trace_seq *s = &iter->seq;
922 trace_assign_type(field, iter->ent);
925 S = task_state_char(field->prev_state);
926 T = task_state_char(field->next_state);
928 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
929 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
930 SEQ_PUT_HEX_FIELD(s, S);
931 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
932 SEQ_PUT_HEX_FIELD(s, field->next_pid);
933 SEQ_PUT_HEX_FIELD(s, field->next_prio);
934 SEQ_PUT_HEX_FIELD(s, T);
936 return trace_handle_return(s);
939 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
940 struct trace_event *event)
942 return trace_ctxwake_hex(iter, 0);
945 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
946 struct trace_event *event)
948 return trace_ctxwake_hex(iter, '+');
951 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
952 int flags, struct trace_event *event)
954 struct ctx_switch_entry *field;
955 struct trace_seq *s = &iter->seq;
957 trace_assign_type(field, iter->ent);
959 SEQ_PUT_FIELD(s, field->prev_pid);
960 SEQ_PUT_FIELD(s, field->prev_prio);
961 SEQ_PUT_FIELD(s, field->prev_state);
962 SEQ_PUT_FIELD(s, field->next_cpu);
963 SEQ_PUT_FIELD(s, field->next_pid);
964 SEQ_PUT_FIELD(s, field->next_prio);
965 SEQ_PUT_FIELD(s, field->next_state);
967 return trace_handle_return(s);
970 static struct trace_event_functions trace_ctx_funcs = {
971 .trace = trace_ctx_print,
972 .raw = trace_ctx_raw,
973 .hex = trace_ctx_hex,
974 .binary = trace_ctxwake_bin,
977 static struct trace_event trace_ctx_event = {
979 .funcs = &trace_ctx_funcs,
982 static struct trace_event_functions trace_wake_funcs = {
983 .trace = trace_wake_print,
984 .raw = trace_wake_raw,
985 .hex = trace_wake_hex,
986 .binary = trace_ctxwake_bin,
989 static struct trace_event trace_wake_event = {
991 .funcs = &trace_wake_funcs,
996 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
997 int flags, struct trace_event *event)
999 struct stack_entry *field;
1000 struct trace_seq *s = &iter->seq;
1004 trace_assign_type(field, iter->ent);
1005 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1007 trace_seq_puts(s, "<stack trace>\n");
1009 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1011 if (trace_seq_has_overflowed(s))
1014 trace_seq_puts(s, " => ");
1015 seq_print_ip_sym(s, *p, flags);
1016 trace_seq_putc(s, '\n');
1019 return trace_handle_return(s);
1022 static struct trace_event_functions trace_stack_funcs = {
1023 .trace = trace_stack_print,
1026 static struct trace_event trace_stack_event = {
1027 .type = TRACE_STACK,
1028 .funcs = &trace_stack_funcs,
1031 /* TRACE_USER_STACK */
1032 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1033 int flags, struct trace_event *event)
1035 struct userstack_entry *field;
1036 struct trace_seq *s = &iter->seq;
1038 trace_assign_type(field, iter->ent);
1040 trace_seq_puts(s, "<user stack trace>\n");
1041 seq_print_userip_objs(field, s, flags);
1043 return trace_handle_return(s);
1046 static struct trace_event_functions trace_user_stack_funcs = {
1047 .trace = trace_user_stack_print,
1050 static struct trace_event trace_user_stack_event = {
1051 .type = TRACE_USER_STACK,
1052 .funcs = &trace_user_stack_funcs,
1056 static enum print_line_t
1057 trace_bputs_print(struct trace_iterator *iter, int flags,
1058 struct trace_event *event)
1060 struct trace_entry *entry = iter->ent;
1061 struct trace_seq *s = &iter->seq;
1062 struct bputs_entry *field;
1064 trace_assign_type(field, entry);
1066 seq_print_ip_sym(s, field->ip, flags);
1067 trace_seq_puts(s, ": ");
1068 trace_seq_puts(s, field->str);
1070 return trace_handle_return(s);
1074 static enum print_line_t
1075 trace_bputs_raw(struct trace_iterator *iter, int flags,
1076 struct trace_event *event)
1078 struct bputs_entry *field;
1079 struct trace_seq *s = &iter->seq;
1081 trace_assign_type(field, iter->ent);
1083 trace_seq_printf(s, ": %lx : ", field->ip);
1084 trace_seq_puts(s, field->str);
1086 return trace_handle_return(s);
1089 static struct trace_event_functions trace_bputs_funcs = {
1090 .trace = trace_bputs_print,
1091 .raw = trace_bputs_raw,
1094 static struct trace_event trace_bputs_event = {
1095 .type = TRACE_BPUTS,
1096 .funcs = &trace_bputs_funcs,
1100 static enum print_line_t
1101 trace_bprint_print(struct trace_iterator *iter, int flags,
1102 struct trace_event *event)
1104 struct trace_entry *entry = iter->ent;
1105 struct trace_seq *s = &iter->seq;
1106 struct bprint_entry *field;
1108 trace_assign_type(field, entry);
1110 seq_print_ip_sym(s, field->ip, flags);
1111 trace_seq_puts(s, ": ");
1112 trace_seq_bprintf(s, field->fmt, field->buf);
1114 return trace_handle_return(s);
1118 static enum print_line_t
1119 trace_bprint_raw(struct trace_iterator *iter, int flags,
1120 struct trace_event *event)
1122 struct bprint_entry *field;
1123 struct trace_seq *s = &iter->seq;
1125 trace_assign_type(field, iter->ent);
1127 trace_seq_printf(s, ": %lx : ", field->ip);
1128 trace_seq_bprintf(s, field->fmt, field->buf);
1130 return trace_handle_return(s);
1133 static struct trace_event_functions trace_bprint_funcs = {
1134 .trace = trace_bprint_print,
1135 .raw = trace_bprint_raw,
1138 static struct trace_event trace_bprint_event = {
1139 .type = TRACE_BPRINT,
1140 .funcs = &trace_bprint_funcs,
1144 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1145 int flags, struct trace_event *event)
1147 struct print_entry *field;
1148 struct trace_seq *s = &iter->seq;
1150 trace_assign_type(field, iter->ent);
1152 seq_print_ip_sym(s, field->ip, flags);
1153 trace_seq_printf(s, ": %s", field->buf);
1155 return trace_handle_return(s);
1158 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1159 struct trace_event *event)
1161 struct print_entry *field;
1163 trace_assign_type(field, iter->ent);
1165 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1167 return trace_handle_return(&iter->seq);
1170 static struct trace_event_functions trace_print_funcs = {
1171 .trace = trace_print_print,
1172 .raw = trace_print_raw,
1175 static struct trace_event trace_print_event = {
1176 .type = TRACE_PRINT,
1177 .funcs = &trace_print_funcs,
1181 static struct trace_event *events[] __initdata = {
1186 &trace_user_stack_event,
1188 &trace_bprint_event,
1193 __init static int init_events(void)
1195 struct trace_event *event;
1198 for (i = 0; events[i]; i++) {
1201 ret = register_ftrace_event(event);
1203 printk(KERN_WARNING "event %d failed to register\n",
1211 early_initcall(init_events);