Merge branches 'tracing/branch-tracer', 'tracing/ftrace', 'tracing/function-graph...
[linux-2.6] / kernel / trace / trace_functions.c
1 /*
2  * ring buffer based function tracer
3  *
4  * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5  * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
6  *
7  * Based on code from the latency_tracer, that is:
8  *
9  *  Copyright (C) 2004-2006 Ingo Molnar
10  *  Copyright (C) 2004 William Lee Irwin III
11  */
12 #include <linux/debugfs.h>
13 #include <linux/uaccess.h>
14 #include <linux/ftrace.h>
15 #include <linux/fs.h>
16
17 #include "trace.h"
18
19 static void function_reset(struct trace_array *tr)
20 {
21         int cpu;
22
23         tr->time_start = ftrace_now(tr->cpu);
24
25         for_each_online_cpu(cpu)
26                 tracing_reset(tr, cpu);
27 }
28
29 static void start_function_trace(struct trace_array *tr)
30 {
31         tr->cpu = get_cpu();
32         function_reset(tr);
33         put_cpu();
34
35         tracing_start_cmdline_record();
36         tracing_start_function_trace();
37 }
38
39 static void stop_function_trace(struct trace_array *tr)
40 {
41         tracing_stop_function_trace();
42         tracing_stop_cmdline_record();
43 }
44
45 static int function_trace_init(struct trace_array *tr)
46 {
47         start_function_trace(tr);
48         return 0;
49 }
50
51 static void function_trace_reset(struct trace_array *tr)
52 {
53         stop_function_trace(tr);
54 }
55
56 static void function_trace_start(struct trace_array *tr)
57 {
58         function_reset(tr);
59 }
60
61 static struct tracer function_trace __read_mostly =
62 {
63         .name        = "function",
64         .init        = function_trace_init,
65         .reset       = function_trace_reset,
66         .start       = function_trace_start,
67 #ifdef CONFIG_FTRACE_SELFTEST
68         .selftest    = trace_selftest_startup_function,
69 #endif
70 };
71
72 static __init int init_function_trace(void)
73 {
74         return register_tracer(&function_trace);
75 }
76
77 device_initcall(init_function_trace);