Merge branches 'tracing/ftrace' and 'tracing/urgent' into tracing/core
[linux-2.6] / kernel / trace / trace_functions_return.c
1 /*
2  *
3  * Function return tracer.
4  * Copyright (c) 2008 Frederic Weisbecker <fweisbec@gmail.com>
5  * Mostly borrowed from function tracer which
6  * is Copyright (c) Steven Rostedt <srostedt@redhat.com>
7  *
8  */
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/ftrace.h>
12 #include <linux/fs.h>
13
14 #include "trace.h"
15
16
17 static int return_trace_init(struct trace_array *tr)
18 {
19         int cpu;
20         for_each_online_cpu(cpu)
21                 tracing_reset(tr, cpu);
22
23         return register_ftrace_return(&trace_function_return);
24 }
25
26 static void return_trace_reset(struct trace_array *tr)
27 {
28                 unregister_ftrace_return();
29 }
30
31
32 enum print_line_t
33 print_return_function(struct trace_iterator *iter)
34 {
35         struct trace_seq *s = &iter->seq;
36         struct trace_entry *entry = iter->ent;
37         struct ftrace_ret_entry *field;
38         int ret;
39
40         if (entry->type == TRACE_FN_RET) {
41                 trace_assign_type(field, entry);
42                 ret = trace_seq_printf(s, "%pF -> ", (void *)field->parent_ip);
43                 if (!ret)
44                         return TRACE_TYPE_PARTIAL_LINE;
45                 ret = seq_print_ip_sym(s, field->ip,
46                                         trace_flags & TRACE_ITER_SYM_MASK);
47                 if (!ret)
48                         return TRACE_TYPE_PARTIAL_LINE;
49                 ret = trace_seq_printf(s, " (%llu ns)\n",
50                                         field->rettime - field->calltime);
51                 if (!ret)
52                         return TRACE_TYPE_PARTIAL_LINE;
53                 else
54                         return TRACE_TYPE_HANDLED;
55         }
56         return TRACE_TYPE_UNHANDLED;
57 }
58
59 static struct tracer return_trace __read_mostly =
60 {
61         .name        = "return",
62         .init        = return_trace_init,
63         .reset       = return_trace_reset,
64         .print_line = print_return_function
65 };
66
67 static __init int init_return_trace(void)
68 {
69         return register_tracer(&return_trace);
70 }
71
72 device_initcall(init_return_trace);