Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 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 | */ |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
| 13 | #include <linux/uaccess.h> |
| 14 | #include <linux/ftrace.h> |
Ingo Molnar | 2e0f576 | 2008-05-12 21:20:49 +0200 | [diff] [blame] | 15 | #include <linux/fs.h> |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 16 | |
| 17 | #include "trace.h" |
| 18 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 19 | static void function_reset(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 20 | { |
| 21 | int cpu; |
| 22 | |
Ingo Molnar | 750ed1a | 2008-05-12 21:20:46 +0200 | [diff] [blame] | 23 | tr->time_start = ftrace_now(tr->cpu); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 24 | |
| 25 | for_each_online_cpu(cpu) |
| 26 | tracing_reset(tr->data[cpu]); |
| 27 | } |
| 28 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 29 | static void start_function_trace(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 30 | { |
Steven Rostedt | 26bc83f | 2008-07-10 20:58:14 -0400 | [diff] [blame^] | 31 | tr->cpu = get_cpu(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 32 | function_reset(tr); |
Steven Rostedt | 26bc83f | 2008-07-10 20:58:14 -0400 | [diff] [blame^] | 33 | put_cpu(); |
| 34 | |
Steven Rostedt | 41bc814 | 2008-05-22 11:49:22 -0400 | [diff] [blame] | 35 | tracing_start_cmdline_record(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 36 | tracing_start_function_trace(); |
| 37 | } |
| 38 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 39 | static void stop_function_trace(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 40 | { |
| 41 | tracing_stop_function_trace(); |
Steven Rostedt | 41bc814 | 2008-05-22 11:49:22 -0400 | [diff] [blame] | 42 | tracing_stop_cmdline_record(); |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 43 | } |
| 44 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 45 | static void function_trace_init(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 46 | { |
| 47 | if (tr->ctrl) |
| 48 | start_function_trace(tr); |
| 49 | } |
| 50 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 51 | static void function_trace_reset(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 52 | { |
| 53 | if (tr->ctrl) |
| 54 | stop_function_trace(tr); |
| 55 | } |
| 56 | |
Ingo Molnar | e309b41 | 2008-05-12 21:20:51 +0200 | [diff] [blame] | 57 | static void function_trace_ctrl_update(struct trace_array *tr) |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 58 | { |
| 59 | if (tr->ctrl) |
| 60 | start_function_trace(tr); |
| 61 | else |
| 62 | stop_function_trace(tr); |
| 63 | } |
| 64 | |
| 65 | static struct tracer function_trace __read_mostly = |
| 66 | { |
| 67 | .name = "ftrace", |
| 68 | .init = function_trace_init, |
| 69 | .reset = function_trace_reset, |
| 70 | .ctrl_update = function_trace_ctrl_update, |
Steven Rostedt | 60a1177 | 2008-05-12 21:20:44 +0200 | [diff] [blame] | 71 | #ifdef CONFIG_FTRACE_SELFTEST |
| 72 | .selftest = trace_selftest_startup_function, |
| 73 | #endif |
Steven Rostedt | 1b29b01 | 2008-05-12 21:20:42 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | static __init int init_function_trace(void) |
| 77 | { |
| 78 | return register_tracer(&function_trace); |
| 79 | } |
| 80 | |
| 81 | device_initcall(init_function_trace); |