blob: 9236d7e25a163b0733087d714728d5787104d08a [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 start_function_trace(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020020{
Steven Rostedt26bc83f2008-07-10 20:58:14 -040021 tr->cpu = get_cpu();
Pekka J Enberg213cc062008-12-19 12:08:39 +020022 tracing_reset_online_cpus(tr);
Steven Rostedt26bc83f2008-07-10 20:58:14 -040023 put_cpu();
24
Steven Rostedt41bc8142008-05-22 11:49:22 -040025 tracing_start_cmdline_record();
Steven Rostedt1b29b012008-05-12 21:20:42 +020026 tracing_start_function_trace();
27}
28
Ingo Molnare309b412008-05-12 21:20:51 +020029static void stop_function_trace(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020030{
31 tracing_stop_function_trace();
Steven Rostedt41bc8142008-05-22 11:49:22 -040032 tracing_stop_cmdline_record();
Steven Rostedt1b29b012008-05-12 21:20:42 +020033}
34
Frederic Weisbecker1c800252008-11-16 05:57:26 +010035static int function_trace_init(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020036{
Steven Rostedtc76f0692008-11-07 22:36:02 -050037 start_function_trace(tr);
Frederic Weisbecker1c800252008-11-16 05:57:26 +010038 return 0;
Steven Rostedt1b29b012008-05-12 21:20:42 +020039}
40
Ingo Molnare309b412008-05-12 21:20:51 +020041static void function_trace_reset(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020042{
Steven Rostedtc76f0692008-11-07 22:36:02 -050043 stop_function_trace(tr);
Steven Rostedt1b29b012008-05-12 21:20:42 +020044}
45
Steven Rostedt90369902008-11-05 16:05:44 -050046static void function_trace_start(struct trace_array *tr)
47{
Pekka J Enberg213cc062008-12-19 12:08:39 +020048 tracing_reset_online_cpus(tr);
Steven Rostedt90369902008-11-05 16:05:44 -050049}
50
Steven Rostedt1b29b012008-05-12 21:20:42 +020051static struct tracer function_trace __read_mostly =
52{
Steven Rostedt3ce83ae2008-10-06 19:06:13 -040053 .name = "function",
Steven Rostedt1b29b012008-05-12 21:20:42 +020054 .init = function_trace_init,
55 .reset = function_trace_reset,
Steven Rostedt90369902008-11-05 16:05:44 -050056 .start = function_trace_start,
Steven Rostedt60a11772008-05-12 21:20:44 +020057#ifdef CONFIG_FTRACE_SELFTEST
58 .selftest = trace_selftest_startup_function,
59#endif
Steven Rostedt1b29b012008-05-12 21:20:42 +020060};
61
62static __init int init_function_trace(void)
63{
64 return register_tracer(&function_trace);
65}
66
67device_initcall(init_function_trace);