blob: 4165d34bd28a4db79023f9698f9639d4a53851ab [file] [log] [blame]
Steven Rostedt1b29b012008-05-12 21:20:42 +02001/*
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 */
Steven Rostedt1b29b012008-05-12 21:20:42 +020012#include <linux/debugfs.h>
13#include <linux/uaccess.h>
14#include <linux/ftrace.h>
Ingo Molnar2e0f5762008-05-12 21:20:49 +020015#include <linux/fs.h>
Steven Rostedt1b29b012008-05-12 21:20:42 +020016
17#include "trace.h"
18
Ingo Molnare309b412008-05-12 21:20:51 +020019static void function_reset(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020020{
21 int cpu;
22
Ingo Molnar750ed1a2008-05-12 21:20:46 +020023 tr->time_start = ftrace_now(tr->cpu);
Steven Rostedt1b29b012008-05-12 21:20:42 +020024
25 for_each_online_cpu(cpu)
26 tracing_reset(tr->data[cpu]);
27}
28
Ingo Molnare309b412008-05-12 21:20:51 +020029static void start_function_trace(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020030{
31 function_reset(tr);
32 tracing_start_function_trace();
33}
34
Ingo Molnare309b412008-05-12 21:20:51 +020035static void stop_function_trace(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020036{
37 tracing_stop_function_trace();
38}
39
Ingo Molnare309b412008-05-12 21:20:51 +020040static void function_trace_init(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020041{
42 if (tr->ctrl)
43 start_function_trace(tr);
44}
45
Ingo Molnare309b412008-05-12 21:20:51 +020046static void function_trace_reset(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020047{
48 if (tr->ctrl)
49 stop_function_trace(tr);
50}
51
Ingo Molnare309b412008-05-12 21:20:51 +020052static void function_trace_ctrl_update(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020053{
54 if (tr->ctrl)
55 start_function_trace(tr);
56 else
57 stop_function_trace(tr);
58}
59
60static struct tracer function_trace __read_mostly =
61{
62 .name = "ftrace",
63 .init = function_trace_init,
64 .reset = function_trace_reset,
65 .ctrl_update = function_trace_ctrl_update,
Steven Rostedt60a11772008-05-12 21:20:44 +020066#ifdef CONFIG_FTRACE_SELFTEST
67 .selftest = trace_selftest_startup_function,
68#endif
Steven Rostedt1b29b012008-05-12 21:20:42 +020069};
70
71static __init int init_function_trace(void)
72{
73 return register_tracer(&function_trace);
74}
75
76device_initcall(init_function_trace);