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);
181 ftrace_print_array_seq(struct trace_seq *p, const void *buf, int buf_len,
184 const char *ret = trace_seq_buffer_ptr(p);
185 const char *prefix = "";
186 void *ptr = (void *)buf;
188 trace_seq_putc(p, '{');
190 while (ptr < buf + buf_len) {
193 trace_seq_printf(p, "%s0x%x", prefix,
197 trace_seq_printf(p, "%s0x%x", prefix,
201 trace_seq_printf(p, "%s0x%x", prefix,
205 trace_seq_printf(p, "%s0x%llx", prefix,
209 trace_seq_printf(p, "BAD SIZE:%zu 0x%x", el_size,
217 trace_seq_putc(p, '}');
218 trace_seq_putc(p, 0);
222 EXPORT_SYMBOL(ftrace_print_array_seq);
224 int ftrace_raw_output_prep(struct trace_iterator *iter,
225 struct trace_event *trace_event)
227 struct ftrace_event_call *event;
228 struct trace_seq *s = &iter->seq;
229 struct trace_seq *p = &iter->tmp_seq;
230 struct trace_entry *entry;
232 event = container_of(trace_event, struct ftrace_event_call, event);
235 if (entry->type != event->event.type) {
237 return TRACE_TYPE_UNHANDLED;
241 trace_seq_printf(s, "%s: ", ftrace_event_name(event));
243 return trace_handle_return(s);
245 EXPORT_SYMBOL(ftrace_raw_output_prep);
247 static int ftrace_output_raw(struct trace_iterator *iter, char *name,
248 char *fmt, va_list ap)
250 struct trace_seq *s = &iter->seq;
252 trace_seq_printf(s, "%s: ", name);
253 trace_seq_vprintf(s, fmt, ap);
255 return trace_handle_return(s);
258 int ftrace_output_call(struct trace_iterator *iter, char *name, char *fmt, ...)
264 ret = ftrace_output_raw(iter, name, fmt, ap);
269 EXPORT_SYMBOL_GPL(ftrace_output_call);
271 #ifdef CONFIG_KRETPROBES
272 static inline const char *kretprobed(const char *name)
274 static const char tramp_name[] = "kretprobe_trampoline";
275 int size = sizeof(tramp_name);
277 if (strncmp(tramp_name, name, size) == 0)
278 return "[unknown/kretprobe'd]";
282 static inline const char *kretprobed(const char *name)
286 #endif /* CONFIG_KRETPROBES */
289 seq_print_sym_short(struct trace_seq *s, const char *fmt, unsigned long address)
291 #ifdef CONFIG_KALLSYMS
292 char str[KSYM_SYMBOL_LEN];
295 kallsyms_lookup(address, NULL, NULL, NULL, str);
297 name = kretprobed(str);
299 trace_seq_printf(s, fmt, name);
304 seq_print_sym_offset(struct trace_seq *s, const char *fmt,
305 unsigned long address)
307 #ifdef CONFIG_KALLSYMS
308 char str[KSYM_SYMBOL_LEN];
311 sprint_symbol(str, address);
312 name = kretprobed(str);
314 trace_seq_printf(s, fmt, name);
319 # define IP_FMT "%08lx"
321 # define IP_FMT "%016lx"
324 int seq_print_user_ip(struct trace_seq *s, struct mm_struct *mm,
325 unsigned long ip, unsigned long sym_flags)
327 struct file *file = NULL;
328 unsigned long vmstart = 0;
335 const struct vm_area_struct *vma;
337 down_read(&mm->mmap_sem);
338 vma = find_vma(mm, ip);
341 vmstart = vma->vm_start;
344 ret = trace_seq_path(s, &file->f_path);
346 trace_seq_printf(s, "[+0x%lx]",
349 up_read(&mm->mmap_sem);
351 if (ret && ((sym_flags & TRACE_ITER_SYM_ADDR) || !file))
352 trace_seq_printf(s, " <" IP_FMT ">", ip);
353 return !trace_seq_has_overflowed(s);
357 seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
358 unsigned long sym_flags)
360 struct mm_struct *mm = NULL;
363 if (trace_flags & TRACE_ITER_SYM_USEROBJ) {
364 struct task_struct *task;
366 * we do the lookup on the thread group leader,
367 * since individual threads might have already quit!
370 task = find_task_by_vpid(entry->tgid);
372 mm = get_task_mm(task);
376 for (i = 0; i < FTRACE_STACK_ENTRIES; i++) {
377 unsigned long ip = entry->caller[i];
379 if (ip == ULONG_MAX || trace_seq_has_overflowed(s))
382 trace_seq_puts(s, " => ");
385 trace_seq_puts(s, "??");
386 trace_seq_putc(s, '\n');
390 seq_print_user_ip(s, mm, ip, sym_flags);
391 trace_seq_putc(s, '\n');
397 return !trace_seq_has_overflowed(s);
401 seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
404 trace_seq_putc(s, '0');
408 if (sym_flags & TRACE_ITER_SYM_OFFSET)
409 seq_print_sym_offset(s, "%s", ip);
411 seq_print_sym_short(s, "%s", ip);
413 if (sym_flags & TRACE_ITER_SYM_ADDR)
414 trace_seq_printf(s, " <" IP_FMT ">", ip);
417 return !trace_seq_has_overflowed(s);
421 * trace_print_lat_fmt - print the irq, preempt and lockdep fields
422 * @s: trace seq struct to write to
423 * @entry: The trace entry field from the ring buffer
425 * Prints the generic fields of irqs off, in hard or softirq, preempt
428 int trace_print_lat_fmt(struct trace_seq *s, struct trace_entry *entry)
436 hardirq = entry->flags & TRACE_FLAG_HARDIRQ;
437 softirq = entry->flags & TRACE_FLAG_SOFTIRQ;
440 (entry->flags & TRACE_FLAG_IRQS_OFF) ? 'd' :
441 (entry->flags & TRACE_FLAG_IRQS_NOSUPPORT) ? 'X' :
444 switch (entry->flags & (TRACE_FLAG_NEED_RESCHED |
445 TRACE_FLAG_PREEMPT_RESCHED)) {
446 case TRACE_FLAG_NEED_RESCHED | TRACE_FLAG_PREEMPT_RESCHED:
449 case TRACE_FLAG_NEED_RESCHED:
452 case TRACE_FLAG_PREEMPT_RESCHED:
461 (hardirq && softirq) ? 'H' :
466 trace_seq_printf(s, "%c%c%c",
467 irqs_off, need_resched, hardsoft_irq);
469 if (entry->preempt_count)
470 trace_seq_printf(s, "%x", entry->preempt_count);
472 trace_seq_putc(s, '.');
474 return !trace_seq_has_overflowed(s);
478 lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
480 char comm[TASK_COMM_LEN];
482 trace_find_cmdline(entry->pid, comm);
484 trace_seq_printf(s, "%8.8s-%-5d %3d",
485 comm, entry->pid, cpu);
487 return trace_print_lat_fmt(s, entry);
491 #define MARK(v, s) {.val = v, .sym = s}
492 /* trace overhead mark */
493 static const struct trace_mark {
494 unsigned long long val; /* unit: nsec */
497 MARK(1000000000ULL , '$'), /* 1 sec */
498 MARK(1000000ULL , '#'), /* 1000 usecs */
499 MARK(100000ULL , '!'), /* 100 usecs */
500 MARK(10000ULL , '+'), /* 10 usecs */
504 char trace_find_mark(unsigned long long d)
507 int size = ARRAY_SIZE(mark);
509 for (i = 0; i < size; i++) {
510 if (d >= mark[i].val)
514 return (i == size) ? ' ' : mark[i].sym;
518 lat_print_timestamp(struct trace_iterator *iter, u64 next_ts)
520 unsigned long verbose = trace_flags & TRACE_ITER_VERBOSE;
521 unsigned long in_ns = iter->iter_flags & TRACE_FILE_TIME_IN_NS;
522 unsigned long long abs_ts = iter->ts - iter->trace_buffer->time_start;
523 unsigned long long rel_ts = next_ts - iter->ts;
524 struct trace_seq *s = &iter->seq;
527 abs_ts = ns2usecs(abs_ts);
528 rel_ts = ns2usecs(rel_ts);
531 if (verbose && in_ns) {
532 unsigned long abs_usec = do_div(abs_ts, USEC_PER_MSEC);
533 unsigned long abs_msec = (unsigned long)abs_ts;
534 unsigned long rel_usec = do_div(rel_ts, USEC_PER_MSEC);
535 unsigned long rel_msec = (unsigned long)rel_ts;
538 s, "[%08llx] %ld.%03ldms (+%ld.%03ldms): ",
543 } else if (verbose && !in_ns) {
545 s, "[%016llx] %lld (+%lld): ",
546 iter->ts, abs_ts, rel_ts);
548 } else if (!verbose && in_ns) {
552 trace_find_mark(rel_ts * NSEC_PER_USEC));
554 } else { /* !verbose && !in_ns */
555 trace_seq_printf(s, " %4lld: ", abs_ts);
558 return !trace_seq_has_overflowed(s);
561 int trace_print_context(struct trace_iterator *iter)
563 struct trace_seq *s = &iter->seq;
564 struct trace_entry *entry = iter->ent;
565 unsigned long long t;
566 unsigned long secs, usec_rem;
567 char comm[TASK_COMM_LEN];
569 trace_find_cmdline(entry->pid, comm);
571 trace_seq_printf(s, "%16s-%-5d [%03d] ",
572 comm, entry->pid, iter->cpu);
574 if (trace_flags & TRACE_ITER_IRQ_INFO)
575 trace_print_lat_fmt(s, entry);
577 if (iter->iter_flags & TRACE_FILE_TIME_IN_NS) {
578 t = ns2usecs(iter->ts);
579 usec_rem = do_div(t, USEC_PER_SEC);
580 secs = (unsigned long)t;
581 trace_seq_printf(s, " %5lu.%06lu: ", secs, usec_rem);
583 trace_seq_printf(s, " %12llu: ", iter->ts);
585 return !trace_seq_has_overflowed(s);
588 int trace_print_lat_context(struct trace_iterator *iter)
591 /* trace_find_next_entry will reset ent_size */
592 int ent_size = iter->ent_size;
593 struct trace_seq *s = &iter->seq;
594 struct trace_entry *entry = iter->ent,
595 *next_entry = trace_find_next_entry(iter, NULL,
597 unsigned long verbose = (trace_flags & TRACE_ITER_VERBOSE);
599 /* Restore the original ent_size */
600 iter->ent_size = ent_size;
606 char comm[TASK_COMM_LEN];
608 trace_find_cmdline(entry->pid, comm);
611 s, "%16s %5d %3d %d %08x %08lx ",
612 comm, entry->pid, iter->cpu, entry->flags,
613 entry->preempt_count, iter->idx);
615 lat_print_generic(s, entry, iter->cpu);
618 lat_print_timestamp(iter, next_ts);
620 return !trace_seq_has_overflowed(s);
623 static const char state_to_char[] = TASK_STATE_TO_CHAR_STR;
625 static int task_state_char(unsigned long state)
627 int bit = state ? __ffs(state) + 1 : 0;
629 return bit < sizeof(state_to_char) - 1 ? state_to_char[bit] : '?';
633 * ftrace_find_event - find a registered event
634 * @type: the type of event to look for
636 * Returns an event of type @type otherwise NULL
637 * Called with trace_event_read_lock() held.
639 struct trace_event *ftrace_find_event(int type)
641 struct trace_event *event;
644 key = type & (EVENT_HASHSIZE - 1);
646 hlist_for_each_entry(event, &event_hash[key], node) {
647 if (event->type == type)
654 static LIST_HEAD(ftrace_event_list);
656 static int trace_search_list(struct list_head **list)
658 struct trace_event *e;
659 int last = __TRACE_LAST_TYPE;
661 if (list_empty(&ftrace_event_list)) {
662 *list = &ftrace_event_list;
667 * We used up all possible max events,
668 * lets see if somebody freed one.
670 list_for_each_entry(e, &ftrace_event_list, list) {
671 if (e->type != last + 1)
676 /* Did we used up all 65 thousand events??? */
677 if ((last + 1) > FTRACE_MAX_EVENT)
684 void trace_event_read_lock(void)
686 down_read(&trace_event_sem);
689 void trace_event_read_unlock(void)
691 up_read(&trace_event_sem);
695 * register_ftrace_event - register output for an event type
696 * @event: the event type to register
698 * Event types are stored in a hash and this hash is used to
699 * find a way to print an event. If the @event->type is set
700 * then it will use that type, otherwise it will assign a
703 * If you assign your own type, please make sure it is added
704 * to the trace_type enum in trace.h, to avoid collisions
705 * with the dynamic types.
707 * Returns the event type number or zero on error.
709 int register_ftrace_event(struct trace_event *event)
714 down_write(&trace_event_sem);
719 if (WARN_ON(!event->funcs))
722 INIT_LIST_HEAD(&event->list);
725 struct list_head *list = NULL;
727 if (next_event_type > FTRACE_MAX_EVENT) {
729 event->type = trace_search_list(&list);
735 event->type = next_event_type++;
736 list = &ftrace_event_list;
739 if (WARN_ON(ftrace_find_event(event->type)))
742 list_add_tail(&event->list, list);
744 } else if (event->type > __TRACE_LAST_TYPE) {
745 printk(KERN_WARNING "Need to add type to trace.h\n");
749 /* Is this event already used */
750 if (ftrace_find_event(event->type))
754 if (event->funcs->trace == NULL)
755 event->funcs->trace = trace_nop_print;
756 if (event->funcs->raw == NULL)
757 event->funcs->raw = trace_nop_print;
758 if (event->funcs->hex == NULL)
759 event->funcs->hex = trace_nop_print;
760 if (event->funcs->binary == NULL)
761 event->funcs->binary = trace_nop_print;
763 key = event->type & (EVENT_HASHSIZE - 1);
765 hlist_add_head(&event->node, &event_hash[key]);
769 up_write(&trace_event_sem);
773 EXPORT_SYMBOL_GPL(register_ftrace_event);
776 * Used by module code with the trace_event_sem held for write.
778 int __unregister_ftrace_event(struct trace_event *event)
780 hlist_del(&event->node);
781 list_del(&event->list);
786 * unregister_ftrace_event - remove a no longer used event
787 * @event: the event to remove
789 int unregister_ftrace_event(struct trace_event *event)
791 down_write(&trace_event_sem);
792 __unregister_ftrace_event(event);
793 up_write(&trace_event_sem);
797 EXPORT_SYMBOL_GPL(unregister_ftrace_event);
803 enum print_line_t trace_nop_print(struct trace_iterator *iter, int flags,
804 struct trace_event *event)
806 trace_seq_printf(&iter->seq, "type: %d\n", iter->ent->type);
808 return trace_handle_return(&iter->seq);
812 static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
813 struct trace_event *event)
815 struct ftrace_entry *field;
816 struct trace_seq *s = &iter->seq;
818 trace_assign_type(field, iter->ent);
820 seq_print_ip_sym(s, field->ip, flags);
822 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
823 trace_seq_puts(s, " <-");
824 seq_print_ip_sym(s, field->parent_ip, flags);
827 trace_seq_putc(s, '\n');
829 return trace_handle_return(s);
832 static enum print_line_t trace_fn_raw(struct trace_iterator *iter, int flags,
833 struct trace_event *event)
835 struct ftrace_entry *field;
837 trace_assign_type(field, iter->ent);
839 trace_seq_printf(&iter->seq, "%lx %lx\n",
843 return trace_handle_return(&iter->seq);
846 static enum print_line_t trace_fn_hex(struct trace_iterator *iter, int flags,
847 struct trace_event *event)
849 struct ftrace_entry *field;
850 struct trace_seq *s = &iter->seq;
852 trace_assign_type(field, iter->ent);
854 SEQ_PUT_HEX_FIELD(s, field->ip);
855 SEQ_PUT_HEX_FIELD(s, field->parent_ip);
857 return trace_handle_return(s);
860 static enum print_line_t trace_fn_bin(struct trace_iterator *iter, int flags,
861 struct trace_event *event)
863 struct ftrace_entry *field;
864 struct trace_seq *s = &iter->seq;
866 trace_assign_type(field, iter->ent);
868 SEQ_PUT_FIELD(s, field->ip);
869 SEQ_PUT_FIELD(s, field->parent_ip);
871 return trace_handle_return(s);
874 static struct trace_event_functions trace_fn_funcs = {
875 .trace = trace_fn_trace,
878 .binary = trace_fn_bin,
881 static struct trace_event trace_fn_event = {
883 .funcs = &trace_fn_funcs,
886 /* TRACE_CTX an TRACE_WAKE */
887 static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
890 struct ctx_switch_entry *field;
891 char comm[TASK_COMM_LEN];
895 trace_assign_type(field, iter->ent);
897 T = task_state_char(field->next_state);
898 S = task_state_char(field->prev_state);
899 trace_find_cmdline(field->next_pid, comm);
900 trace_seq_printf(&iter->seq,
901 " %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
910 return trace_handle_return(&iter->seq);
913 static enum print_line_t trace_ctx_print(struct trace_iterator *iter, int flags,
914 struct trace_event *event)
916 return trace_ctxwake_print(iter, "==>");
919 static enum print_line_t trace_wake_print(struct trace_iterator *iter,
920 int flags, struct trace_event *event)
922 return trace_ctxwake_print(iter, " +");
925 static int trace_ctxwake_raw(struct trace_iterator *iter, char S)
927 struct ctx_switch_entry *field;
930 trace_assign_type(field, iter->ent);
933 S = task_state_char(field->prev_state);
934 T = task_state_char(field->next_state);
935 trace_seq_printf(&iter->seq, "%d %d %c %d %d %d %c\n",
944 return trace_handle_return(&iter->seq);
947 static enum print_line_t trace_ctx_raw(struct trace_iterator *iter, int flags,
948 struct trace_event *event)
950 return trace_ctxwake_raw(iter, 0);
953 static enum print_line_t trace_wake_raw(struct trace_iterator *iter, int flags,
954 struct trace_event *event)
956 return trace_ctxwake_raw(iter, '+');
960 static int trace_ctxwake_hex(struct trace_iterator *iter, char S)
962 struct ctx_switch_entry *field;
963 struct trace_seq *s = &iter->seq;
966 trace_assign_type(field, iter->ent);
969 S = task_state_char(field->prev_state);
970 T = task_state_char(field->next_state);
972 SEQ_PUT_HEX_FIELD(s, field->prev_pid);
973 SEQ_PUT_HEX_FIELD(s, field->prev_prio);
974 SEQ_PUT_HEX_FIELD(s, S);
975 SEQ_PUT_HEX_FIELD(s, field->next_cpu);
976 SEQ_PUT_HEX_FIELD(s, field->next_pid);
977 SEQ_PUT_HEX_FIELD(s, field->next_prio);
978 SEQ_PUT_HEX_FIELD(s, T);
980 return trace_handle_return(s);
983 static enum print_line_t trace_ctx_hex(struct trace_iterator *iter, int flags,
984 struct trace_event *event)
986 return trace_ctxwake_hex(iter, 0);
989 static enum print_line_t trace_wake_hex(struct trace_iterator *iter, int flags,
990 struct trace_event *event)
992 return trace_ctxwake_hex(iter, '+');
995 static enum print_line_t trace_ctxwake_bin(struct trace_iterator *iter,
996 int flags, struct trace_event *event)
998 struct ctx_switch_entry *field;
999 struct trace_seq *s = &iter->seq;
1001 trace_assign_type(field, iter->ent);
1003 SEQ_PUT_FIELD(s, field->prev_pid);
1004 SEQ_PUT_FIELD(s, field->prev_prio);
1005 SEQ_PUT_FIELD(s, field->prev_state);
1006 SEQ_PUT_FIELD(s, field->next_cpu);
1007 SEQ_PUT_FIELD(s, field->next_pid);
1008 SEQ_PUT_FIELD(s, field->next_prio);
1009 SEQ_PUT_FIELD(s, field->next_state);
1011 return trace_handle_return(s);
1014 static struct trace_event_functions trace_ctx_funcs = {
1015 .trace = trace_ctx_print,
1016 .raw = trace_ctx_raw,
1017 .hex = trace_ctx_hex,
1018 .binary = trace_ctxwake_bin,
1021 static struct trace_event trace_ctx_event = {
1023 .funcs = &trace_ctx_funcs,
1026 static struct trace_event_functions trace_wake_funcs = {
1027 .trace = trace_wake_print,
1028 .raw = trace_wake_raw,
1029 .hex = trace_wake_hex,
1030 .binary = trace_ctxwake_bin,
1033 static struct trace_event trace_wake_event = {
1035 .funcs = &trace_wake_funcs,
1040 static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1041 int flags, struct trace_event *event)
1043 struct stack_entry *field;
1044 struct trace_seq *s = &iter->seq;
1048 trace_assign_type(field, iter->ent);
1049 end = (unsigned long *)((long)iter->ent + iter->ent_size);
1051 trace_seq_puts(s, "<stack trace>\n");
1053 for (p = field->caller; p && *p != ULONG_MAX && p < end; p++) {
1055 if (trace_seq_has_overflowed(s))
1058 trace_seq_puts(s, " => ");
1059 seq_print_ip_sym(s, *p, flags);
1060 trace_seq_putc(s, '\n');
1063 return trace_handle_return(s);
1066 static struct trace_event_functions trace_stack_funcs = {
1067 .trace = trace_stack_print,
1070 static struct trace_event trace_stack_event = {
1071 .type = TRACE_STACK,
1072 .funcs = &trace_stack_funcs,
1075 /* TRACE_USER_STACK */
1076 static enum print_line_t trace_user_stack_print(struct trace_iterator *iter,
1077 int flags, struct trace_event *event)
1079 struct userstack_entry *field;
1080 struct trace_seq *s = &iter->seq;
1082 trace_assign_type(field, iter->ent);
1084 trace_seq_puts(s, "<user stack trace>\n");
1085 seq_print_userip_objs(field, s, flags);
1087 return trace_handle_return(s);
1090 static struct trace_event_functions trace_user_stack_funcs = {
1091 .trace = trace_user_stack_print,
1094 static struct trace_event trace_user_stack_event = {
1095 .type = TRACE_USER_STACK,
1096 .funcs = &trace_user_stack_funcs,
1100 static enum print_line_t
1101 trace_bputs_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 bputs_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_puts(s, field->str);
1114 return trace_handle_return(s);
1118 static enum print_line_t
1119 trace_bputs_raw(struct trace_iterator *iter, int flags,
1120 struct trace_event *event)
1122 struct bputs_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_puts(s, field->str);
1130 return trace_handle_return(s);
1133 static struct trace_event_functions trace_bputs_funcs = {
1134 .trace = trace_bputs_print,
1135 .raw = trace_bputs_raw,
1138 static struct trace_event trace_bputs_event = {
1139 .type = TRACE_BPUTS,
1140 .funcs = &trace_bputs_funcs,
1144 static enum print_line_t
1145 trace_bprint_print(struct trace_iterator *iter, int flags,
1146 struct trace_event *event)
1148 struct trace_entry *entry = iter->ent;
1149 struct trace_seq *s = &iter->seq;
1150 struct bprint_entry *field;
1152 trace_assign_type(field, entry);
1154 seq_print_ip_sym(s, field->ip, flags);
1155 trace_seq_puts(s, ": ");
1156 trace_seq_bprintf(s, field->fmt, field->buf);
1158 return trace_handle_return(s);
1162 static enum print_line_t
1163 trace_bprint_raw(struct trace_iterator *iter, int flags,
1164 struct trace_event *event)
1166 struct bprint_entry *field;
1167 struct trace_seq *s = &iter->seq;
1169 trace_assign_type(field, iter->ent);
1171 trace_seq_printf(s, ": %lx : ", field->ip);
1172 trace_seq_bprintf(s, field->fmt, field->buf);
1174 return trace_handle_return(s);
1177 static struct trace_event_functions trace_bprint_funcs = {
1178 .trace = trace_bprint_print,
1179 .raw = trace_bprint_raw,
1182 static struct trace_event trace_bprint_event = {
1183 .type = TRACE_BPRINT,
1184 .funcs = &trace_bprint_funcs,
1188 static enum print_line_t trace_print_print(struct trace_iterator *iter,
1189 int flags, struct trace_event *event)
1191 struct print_entry *field;
1192 struct trace_seq *s = &iter->seq;
1194 trace_assign_type(field, iter->ent);
1196 seq_print_ip_sym(s, field->ip, flags);
1197 trace_seq_printf(s, ": %s", field->buf);
1199 return trace_handle_return(s);
1202 static enum print_line_t trace_print_raw(struct trace_iterator *iter, int flags,
1203 struct trace_event *event)
1205 struct print_entry *field;
1207 trace_assign_type(field, iter->ent);
1209 trace_seq_printf(&iter->seq, "# %lx %s", field->ip, field->buf);
1211 return trace_handle_return(&iter->seq);
1214 static struct trace_event_functions trace_print_funcs = {
1215 .trace = trace_print_print,
1216 .raw = trace_print_raw,
1219 static struct trace_event trace_print_event = {
1220 .type = TRACE_PRINT,
1221 .funcs = &trace_print_funcs,
1225 static struct trace_event *events[] __initdata = {
1230 &trace_user_stack_event,
1232 &trace_bprint_event,
1237 __init static int init_events(void)
1239 struct trace_event *event;
1242 for (i = 0; events[i]; i++) {
1245 ret = register_ftrace_event(event);
1247 printk(KERN_WARNING "event %d failed to register\n",
1255 early_initcall(init_events);