aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2008-05-12 15:20:42 -0400
committerThomas Gleixner <tglx@linutronix.de>2008-05-23 14:32:13 -0400
commit1b29b01887e6032dcaf818c14999c7a39593b4e7 (patch)
tree6bcef64d5a7822b0f259a52b852af8cade6b3468 /kernel
parentbc0c38d139ec7fcd5c030aea16b008f3732e42ac (diff)
ftrace: function tracer
This is a simple trace that uses the ftrace infrastructure. It is designed to be fast and small, and easy to use. It is useful to record things that happen over a very short period of time, and not to analyze the system in general. Updates: available_tracers "function" is added to this file. current_tracer To enable the function tracer: echo function > /debugfs/tracing/current_tracer To disable the tracer: echo disable > /debugfs/tracing/current_tracer The output of the function_trace file is as follows "echo noverbose > /debugfs/tracing/iter_ctrl" preemption latency trace v1.1.5 on 2.6.24-rc7-tst Signed-off-by: Ingo Molnar <mingo@elte.hu> -------------------------------------------------------------------- latency: 0 us, #419428/4361791, CPU#1 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:4) ----------------- | task: -0 (uid:0 nice:0 policy:0 rt_prio:0) ----------------- _------=> CPU# / _-----=> irqs-off | / _----=> need-resched || / _---=> hardirq/softirq ||| / _--=> preempt-depth |||| / ||||| delay cmd pid ||||| time | caller \ / ||||| \ | / swapper-0 0d.h. 1595128us+: set_normalized_timespec+0x8/0x2d <c043841d> (ktime_get_ts+0x4a/0x4e <c04499d4>) swapper-0 0d.h. 1595131us+: _spin_lock+0x8/0x18 <c0630690> (hrtimer_interrupt+0x6e/0x1b0 <c0449c56>) Or with verbose turned on: "echo verbose > /debugfs/tracing/iter_ctrl" preemption latency trace v1.1.5 on 2.6.24-rc7-tst -------------------------------------------------------------------- latency: 0 us, #419428/4361791, CPU#1 | (M:desktop VP:0, KP:0, SP:0 HP:0 #P:4) ----------------- | task: -0 (uid:0 nice:0 policy:0 rt_prio:0) ----------------- swapper 0 0 9 00000000 00000000 [f3675f41] 1595.128ms (+0.003ms): set_normalized_timespec+0x8/0x2d <c043841d> (ktime_get_ts+0x4a/0x4e <c04499d4>) swapper 0 0 9 00000000 00000001 [f3675f45] 1595.131ms (+0.003ms): _spin_lock+0x8/0x18 <c0630690> (hrtimer_interrupt+0x6e/0x1b0 <c0449c56>) swapper 0 0 9 00000000 00000002 [f3675f48] 1595.135ms (+0.003ms): _spin_lock+0x8/0x18 <c0630690> (hrtimer_interrupt+0x6e/0x1b0 <c0449c56>) The "trace" file is not affected by the verbose mode, but is by the symonly. echo "nosymonly" > /debugfs/tracing/iter_ctrl tracer: [ 81.479967] CPU 0: bash:3154 register_ftrace_function+0x5f/0x66 <ffffffff80337a4d> <-- _spin_unlock_irqrestore+0xe/0x5a <ffffffff8048cc8f> [ 81.479967] CPU 0: bash:3154 _spin_unlock_irqrestore+0x3e/0x5a <ffffffff8048ccbf> <-- sub_preempt_count+0xc/0x7a <ffffffff80233d7b> [ 81.479968] CPU 0: bash:3154 sub_preempt_count+0x30/0x7a <ffffffff80233d9f> <-- in_lock_functions+0x9/0x24 <ffffffff8025a75d> [ 81.479968] CPU 0: bash:3154 vfs_write+0x11d/0x155 <ffffffff8029a043> <-- dnotify_parent+0x12/0x78 <ffffffff802d54fb> [ 81.479968] CPU 0: bash:3154 dnotify_parent+0x2d/0x78 <ffffffff802d5516> <-- _spin_lock+0xe/0x70 <ffffffff8048c910> [ 81.479969] CPU 0: bash:3154 _spin_lock+0x1b/0x70 <ffffffff8048c91d> <-- add_preempt_count+0xe/0x77 <ffffffff80233df7> [ 81.479969] CPU 0: bash:3154 add_preempt_count+0x3e/0x77 <ffffffff80233e27> <-- in_lock_functions+0x9/0x24 <ffffffff8025a75d> echo "symonly" > /debugfs/tracing/iter_ctrl tracer: [ 81.479913] CPU 0: bash:3154 register_ftrace_function+0x5f/0x66 <-- _spin_unlock_irqrestore+0xe/0x5a [ 81.479913] CPU 0: bash:3154 _spin_unlock_irqrestore+0x3e/0x5a <-- sub_preempt_count+0xc/0x7a [ 81.479913] CPU 0: bash:3154 sub_preempt_count+0x30/0x7a <-- in_lock_functions+0x9/0x24 [ 81.479914] CPU 0: bash:3154 vfs_write+0x11d/0x155 <-- dnotify_parent+0x12/0x78 [ 81.479914] CPU 0: bash:3154 dnotify_parent+0x2d/0x78 <-- _spin_lock+0xe/0x70 [ 81.479914] CPU 0: bash:3154 _spin_lock+0x1b/0x70 <-- add_preempt_count+0xe/0x77 [ 81.479914] CPU 0: bash:3154 add_preempt_count+0x3e/0x77 <-- in_lock_functions+0x9/0x24 Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: Ingo Molnar <mingo@elte.hu> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/trace/Kconfig13
-rw-r--r--kernel/trace/Makefile1
-rw-r--r--kernel/trace/trace_functions.c73
3 files changed, 87 insertions, 0 deletions
diff --git a/kernel/trace/Kconfig b/kernel/trace/Kconfig
index ce70677afbf9..1399f372b5dc 100644
--- a/kernel/trace/Kconfig
+++ b/kernel/trace/Kconfig
@@ -8,3 +8,16 @@ config TRACING
8 bool 8 bool
9 select DEBUG_FS 9 select DEBUG_FS
10 10
11config FTRACE
12 bool "Kernel Function Tracer"
13 depends on DEBUG_KERNEL && HAVE_FTRACE
14 select FRAME_POINTER
15 select TRACING
16 help
17 Enable the kernel to trace every kernel function. This is done
18 by using a compiler feature to insert a small, 5-byte No-Operation
19 instruction to the beginning of every kernel function, which NOP
20 sequence is then dynamically patched into a tracer call when
21 tracing is enabled by the administrator. If it's runtime disabled
22 (the bootup default), then the overhead of the instructions is very
23 small and not measurable even in micro-benchmarks.
diff --git a/kernel/trace/Makefile b/kernel/trace/Makefile
index 7af403175255..6bb5e50b4a40 100644
--- a/kernel/trace/Makefile
+++ b/kernel/trace/Makefile
@@ -1,5 +1,6 @@
1obj-$(CONFIG_FTRACE) += libftrace.o 1obj-$(CONFIG_FTRACE) += libftrace.o
2 2
3obj-$(CONFIG_TRACING) += trace.o 3obj-$(CONFIG_TRACING) += trace.o
4obj-$(CONFIG_FTRACE) += trace_functions.o
4 5
5libftrace-y := ftrace.o 6libftrace-y := ftrace.o
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
new file mode 100644
index 000000000000..82988c5336e0
--- /dev/null
+++ b/kernel/trace/trace_functions.c
@@ -0,0 +1,73 @@
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/fs.h>
13#include <linux/debugfs.h>
14#include <linux/uaccess.h>
15#include <linux/ftrace.h>
16
17#include "trace.h"
18
19static notrace void function_reset(struct trace_array *tr)
20{
21 int cpu;
22
23 tr->time_start = now(tr->cpu);
24
25 for_each_online_cpu(cpu)
26 tracing_reset(tr->data[cpu]);
27}
28
29static notrace void start_function_trace(struct trace_array *tr)
30{
31 function_reset(tr);
32 tracing_start_function_trace();
33}
34
35static notrace void stop_function_trace(struct trace_array *tr)
36{
37 tracing_stop_function_trace();
38}
39
40static notrace void function_trace_init(struct trace_array *tr)
41{
42 if (tr->ctrl)
43 start_function_trace(tr);
44}
45
46static notrace void function_trace_reset(struct trace_array *tr)
47{
48 if (tr->ctrl)
49 stop_function_trace(tr);
50}
51
52static notrace void function_trace_ctrl_update(struct trace_array *tr)
53{
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,
66};
67
68static __init int init_function_trace(void)
69{
70 return register_tracer(&function_trace);
71}
72
73device_initcall(init_function_trace);