diff options
author | Li Zefan <lizf@cn.fujitsu.com> | 2009-04-08 23:40:27 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2009-04-09 01:28:10 -0400 |
commit | 66bb74888eb4bef4ba7c87c931ecb7ecca3a240c (patch) | |
tree | 567e333523e16ba7285deac89efb645f72a97529 /Documentation/trace/tracepoints.txt | |
parent | 9eb85125ce218a8b8d9a7c982510388e227adbec (diff) |
tracing: consolidate documents
Move kmemtrace.txt, tracepoints.txt, ftrace.txt and mmiotrace.txt to
the new trace/ directory.
I didnt find any references to those documents in both source
files and documents, so no extra work needs to be done.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
Acked-by: Pekka Paalanen <pq@iki.fi>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
LKML-Reference: <49DD6E2B.6090200@cn.fujitsu.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'Documentation/trace/tracepoints.txt')
-rw-r--r-- | Documentation/trace/tracepoints.txt | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/Documentation/trace/tracepoints.txt b/Documentation/trace/tracepoints.txt new file mode 100644 index 000000000000..c0e1ceed75a4 --- /dev/null +++ b/Documentation/trace/tracepoints.txt | |||
@@ -0,0 +1,116 @@ | |||
1 | Using the Linux Kernel Tracepoints | ||
2 | |||
3 | Mathieu Desnoyers | ||
4 | |||
5 | |||
6 | This document introduces Linux Kernel Tracepoints and their use. It | ||
7 | provides examples of how to insert tracepoints in the kernel and | ||
8 | connect probe functions to them and provides some examples of probe | ||
9 | functions. | ||
10 | |||
11 | |||
12 | * Purpose of tracepoints | ||
13 | |||
14 | A tracepoint placed in code provides a hook to call a function (probe) | ||
15 | that you can provide at runtime. A tracepoint can be "on" (a probe is | ||
16 | connected to it) or "off" (no probe is attached). When a tracepoint is | ||
17 | "off" it has no effect, except for adding a tiny time penalty | ||
18 | (checking a condition for a branch) and space penalty (adding a few | ||
19 | bytes for the function call at the end of the instrumented function | ||
20 | and adds a data structure in a separate section). When a tracepoint | ||
21 | is "on", the function you provide is called each time the tracepoint | ||
22 | is executed, in the execution context of the caller. When the function | ||
23 | provided ends its execution, it returns to the caller (continuing from | ||
24 | the tracepoint site). | ||
25 | |||
26 | You can put tracepoints at important locations in the code. They are | ||
27 | lightweight hooks that can pass an arbitrary number of parameters, | ||
28 | which prototypes are described in a tracepoint declaration placed in a | ||
29 | header file. | ||
30 | |||
31 | They can be used for tracing and performance accounting. | ||
32 | |||
33 | |||
34 | * Usage | ||
35 | |||
36 | Two elements are required for tracepoints : | ||
37 | |||
38 | - A tracepoint definition, placed in a header file. | ||
39 | - The tracepoint statement, in C code. | ||
40 | |||
41 | In order to use tracepoints, you should include linux/tracepoint.h. | ||
42 | |||
43 | In include/trace/subsys.h : | ||
44 | |||
45 | #include <linux/tracepoint.h> | ||
46 | |||
47 | DECLARE_TRACE(subsys_eventname, | ||
48 | TP_PROTO(int firstarg, struct task_struct *p), | ||
49 | TP_ARGS(firstarg, p)); | ||
50 | |||
51 | In subsys/file.c (where the tracing statement must be added) : | ||
52 | |||
53 | #include <trace/subsys.h> | ||
54 | |||
55 | DEFINE_TRACE(subsys_eventname); | ||
56 | |||
57 | void somefct(void) | ||
58 | { | ||
59 | ... | ||
60 | trace_subsys_eventname(arg, task); | ||
61 | ... | ||
62 | } | ||
63 | |||
64 | Where : | ||
65 | - subsys_eventname is an identifier unique to your event | ||
66 | - subsys is the name of your subsystem. | ||
67 | - eventname is the name of the event to trace. | ||
68 | |||
69 | - TP_PROTO(int firstarg, struct task_struct *p) is the prototype of the | ||
70 | function called by this tracepoint. | ||
71 | |||
72 | - TP_ARGS(firstarg, p) are the parameters names, same as found in the | ||
73 | prototype. | ||
74 | |||
75 | Connecting a function (probe) to a tracepoint is done by providing a | ||
76 | probe (function to call) for the specific tracepoint through | ||
77 | register_trace_subsys_eventname(). Removing a probe is done through | ||
78 | unregister_trace_subsys_eventname(); it will remove the probe. | ||
79 | |||
80 | tracepoint_synchronize_unregister() must be called before the end of | ||
81 | the module exit function to make sure there is no caller left using | ||
82 | the probe. This, and the fact that preemption is disabled around the | ||
83 | probe call, make sure that probe removal and module unload are safe. | ||
84 | See the "Probe example" section below for a sample probe module. | ||
85 | |||
86 | The tracepoint mechanism supports inserting multiple instances of the | ||
87 | same tracepoint, but a single definition must be made of a given | ||
88 | tracepoint name over all the kernel to make sure no type conflict will | ||
89 | occur. Name mangling of the tracepoints is done using the prototypes | ||
90 | to make sure typing is correct. Verification of probe type correctness | ||
91 | is done at the registration site by the compiler. Tracepoints can be | ||
92 | put in inline functions, inlined static functions, and unrolled loops | ||
93 | as well as regular functions. | ||
94 | |||
95 | The naming scheme "subsys_event" is suggested here as a convention | ||
96 | intended to limit collisions. Tracepoint names are global to the | ||
97 | kernel: they are considered as being the same whether they are in the | ||
98 | core kernel image or in modules. | ||
99 | |||
100 | If the tracepoint has to be used in kernel modules, an | ||
101 | EXPORT_TRACEPOINT_SYMBOL_GPL() or EXPORT_TRACEPOINT_SYMBOL() can be | ||
102 | used to export the defined tracepoints. | ||
103 | |||
104 | * Probe / tracepoint example | ||
105 | |||
106 | See the example provided in samples/tracepoints | ||
107 | |||
108 | Compile them with your kernel. They are built during 'make' (not | ||
109 | 'make modules') when CONFIG_SAMPLE_TRACEPOINTS=m. | ||
110 | |||
111 | Run, as root : | ||
112 | modprobe tracepoint-sample (insmod order is not important) | ||
113 | modprobe tracepoint-probe-sample | ||
114 | cat /proc/tracepoint-sample (returns an expected error) | ||
115 | rmmod tracepoint-sample tracepoint-probe-sample | ||
116 | dmesg | ||