Merge branches 'tracing/fastboot', 'tracing/function-return-tracer' and 'tracing...
[cascardo/linux.git] / 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 void start_return_trace(struct trace_array *tr)
18 {
19         register_ftrace_return(&trace_function_return);
20 }
21
22 static void stop_return_trace(struct trace_array *tr)
23 {
24         unregister_ftrace_return();
25 }
26
27 static void return_trace_init(struct trace_array *tr)
28 {
29         int cpu;
30         for_each_online_cpu(cpu)
31                 tracing_reset(tr, cpu);
32
33         start_return_trace(tr);
34 }
35
36 static void return_trace_reset(struct trace_array *tr)
37 {
38                 stop_return_trace(tr);
39 }
40
41
42 enum print_line_t
43 print_return_function(struct trace_iterator *iter)
44 {
45         struct trace_seq *s = &iter->seq;
46         struct trace_entry *entry = iter->ent;
47         struct ftrace_ret_entry *field;
48         int ret;
49
50         if (entry->type == TRACE_FN_RET) {
51                 trace_assign_type(field, entry);
52                 ret = trace_seq_printf(s, "%pF -> ", (void *)field->parent_ip);
53                 if (!ret)
54                         return TRACE_TYPE_PARTIAL_LINE;
55                 ret = seq_print_ip_sym(s, field->ip,
56                                         trace_flags & TRACE_ITER_SYM_MASK);
57                 if (!ret)
58                         return TRACE_TYPE_PARTIAL_LINE;
59                 ret = trace_seq_printf(s, " (%llu ns)\n",
60                                         field->rettime - field->calltime);
61                 if (!ret)
62                         return TRACE_TYPE_PARTIAL_LINE;
63                 else
64                         return TRACE_TYPE_HANDLED;
65         }
66         return TRACE_TYPE_UNHANDLED;
67 }
68
69 static struct tracer return_trace __read_mostly =
70 {
71         .name        = "return",
72         .init        = return_trace_init,
73         .reset       = return_trace_reset,
74         .print_line = print_return_function
75 };
76
77 static __init int init_return_trace(void)
78 {
79         return register_tracer(&return_trace);
80 }
81
82 device_initcall(init_return_trace);