aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/trace/events.txt159
1 files changed, 57 insertions, 102 deletions
diff --git a/Documentation/trace/events.txt b/Documentation/trace/events.txt
index abdee664c0f6..f157d7594ea7 100644
--- a/Documentation/trace/events.txt
+++ b/Documentation/trace/events.txt
@@ -1,9 +1,10 @@
1 Event Tracing 1 Event Tracing
2 2
3 Documentation written by Theodore Ts'o 3 Documentation written by Theodore Ts'o
4 Updated by Li Zefan
4 5
5Introduction 61. Introduction
6============ 7===============
7 8
8Tracepoints (see Documentation/trace/tracepoints.txt) can be used 9Tracepoints (see Documentation/trace/tracepoints.txt) can be used
9without creating custom kernel modules to register probe functions 10without creating custom kernel modules to register probe functions
@@ -12,30 +13,37 @@ using the event tracing infrastructure.
12Not all tracepoints can be traced using the event tracing system; 13Not all tracepoints can be traced using the event tracing system;
13the kernel developer must provide code snippets which define how the 14the kernel developer must provide code snippets which define how the
14tracing information is saved into the tracing buffer, and how the 15tracing information is saved into the tracing buffer, and how the
15the tracing information should be printed. 16tracing information should be printed.
16 17
17Using Event Tracing 182. Using Event Tracing
18=================== 19======================
20
212.1 Via the 'set_event' interface
22---------------------------------
19 23
20The events which are available for tracing can be found in the file 24The events which are available for tracing can be found in the file
21/sys/kernel/debug/tracing/available_events. 25/debug/tracing/available_events.
22 26
23To enable a particular event, such as 'sched_wakeup', simply echo it 27To enable a particular event, such as 'sched_wakeup', simply echo it
24to /sys/debug/tracing/set_event. For example: 28to /debug/tracing/set_event. For example:
25 29
26 # echo sched_wakeup > /sys/kernel/debug/tracing/set_event 30 # echo sched_wakeup >> /debug/tracing/set_event
27 31
28[ Note: events can also be enabled/disabled via the 'enabled' toggle 32[ Note: '>>' is necessary, otherwise it will firstly disable
29 found in the /sys/kernel/tracing/events/ hierarchy of directories. ] 33 all the events. ]
30 34
31To disable an event, echo the event name to the set_event file prefixed 35To disable an event, echo the event name to the set_event file prefixed
32with an exclamation point: 36with an exclamation point:
33 37
34 # echo '!sched_wakeup' >> /sys/kernel/debug/tracing/set_event 38 # echo '!sched_wakeup' >> /debug/tracing/set_event
39
40To disable all events, echo an empty line to the set_event file:
41
42 # echo > /debug/tracing/set_event
35 43
36To disable events, echo an empty line to the set_event file: 44To enable all events, echo '*:*' or '*:' to the set_event file:
37 45
38 # echo > /sys/kernel/debug/tracing/set_event 46 # echo *:* > /debug/tracing/set_event
39 47
40The events are organized into subsystems, such as ext4, irq, sched, 48The events are organized into subsystems, such as ext4, irq, sched,
41etc., and a full event name looks like this: <subsystem>:<event>. The 49etc., and a full event name looks like this: <subsystem>:<event>. The
@@ -44,92 +52,39 @@ file. All of the events in a subsystem can be specified via the syntax
44"<subsystem>:*"; for example, to enable all irq events, you can use the 52"<subsystem>:*"; for example, to enable all irq events, you can use the
45command: 53command:
46 54
47 # echo 'irq:*' > /sys/kernel/debug/tracing/set_event 55 # echo 'irq:*' > /debug/tracing/set_event
48 56
49Defining an event-enabled tracepoint 572.2 Via the 'enable' toggle
50------------------------------------ 58---------------------------
51 59
52A kernel developer which wishes to define an event-enabled tracepoint 60The events available are also listed in /debug/tracing/events/ hierarchy
53must declare the tracepoint using TRACE_EVENT instead of DECLARE_TRACE. 61of directories.
54This is done via two header files in include/trace. For example, to 62
55event-enable the jbd2 subsystem, we must create two files, 63To enable event 'sched_wakeup':
56include/trace/jbd2.h and include/trace/jbd2_event_types.h. The 64
57include/trace/jbd2.h file should be included by kernel source files that 65 # echo 1 > /debug/tracing/events/sched/sched_wakeup/enable
58will have a tracepoint inserted, and might look like this: 66
59 67To disable it:
60#ifndef _TRACE_JBD2_H 68
61#define _TRACE_JBD2_H 69 # echo 0 > /debug/tracing/events/sched/sched_wakeup/enable
62 70
63#include <linux/jbd2.h> 71To enable all events in sched subsystem:
64#include <linux/tracepoint.h> 72
65 73 # echo 1 > /debug/tracing/events/sched/enable
66#include <trace/jbd2_event_types.h> 74
67 75To eanble all events:
68#endif 76
69 77 # echo 1 > /debug/tracing/events/enable
70In a file that utilizes a jbd2 tracepoint, this header file would be 78
71included. Note that you still have to use DEFINE_TRACE(). So for 79When reading one of these enable files, there are four results:
72example, if fs/jbd2/commit.c planned to use the jbd2_start_commit 80
73tracepoint, it would have the following near the beginning of the file: 81 0 - all events this file affects are disabled
74 82 1 - all events this file affects are enabled
75#include <trace/jbd2.h> 83 X - there is a mixture of events enabled and disabled
76 84 ? - this file does not affect any event
77DEFINE_TRACE(jbd2_start_commit); 85
78 863. Defining an event-enabled tracepoint
79Then in the function that would call the tracepoint, it would call the 87=======================================
80tracepoint function. (For more information, please see the tracepoint 88
81documentation in Documentation/trace/tracepoints.txt): 89See The example provided in samples/trace_events
82 90
83 trace_jbd2_start_commit(journal, commit_transaction);
84
85The code snippets which allow jbd2_start_commit to be an event-enabled
86tracepoint are placed in the file include/trace/jbd2_event_types.h:
87
88/* use <trace/jbd2.h> instead */
89#ifndef TRACE_EVENT
90# error Do not include this file directly.
91# error Unless you know what you are doing.
92#endif
93
94#undef TRACE_SYSTEM
95#define TRACE_SYSTEM jbd2
96
97#include <linux/jbd2.h>
98
99TRACE_EVENT(jbd2_start_commit,
100 TP_PROTO(journal_t *journal, transaction_t *commit_transaction),
101 TP_ARGS(journal, commit_transaction),
102 TP_STRUCT__entry(
103 __array( char, devname, BDEVNAME_SIZE+24 )
104 __field( int, transaction )
105 ),
106 TP_fast_assign(
107 memcpy(__entry->devname, journal->j_devname, BDEVNAME_SIZE+24);
108 __entry->transaction = commit_transaction->t_tid;
109 ),
110 TP_printk("dev %s transaction %d",
111 __entry->devname, __entry->transaction)
112);
113
114The TP_PROTO and TP_ARGS are unchanged from DECLARE_TRACE. The new
115arguments to TRACE_EVENT are TP_STRUCT__entry, TP_fast_assign, and
116TP_printk.
117
118TP_STRUCT__entry defines the data structure which will be stored in the
119trace buffer. Normally, fields in __entry will be arrays or simple
120types. It is possible to place data structures in __entry --- however,
121pointers in the data structure can not be trusted, since they will be
122accessed sometime later by TP_printk, and if the data structure contains
123fields that will not or cannot be used by TP_printk, this will waste
124space in the trace buffer. In general, data structures should be
125avoided, unless they do only contain non-pointer types and all of the
126fields will be used by TP_printk.
127
128TP_fast_assign defines the code snippet which saves information into the
129__entry data structure, using the passed-in arguments defined in
130TP_PROTO and TP_ARGS.
131
132Finally, TP_printk will print the __entry data structure. At the time
133when the code snippet defined by TP_printk is executed, it will not have
134access to the TP_ARGS arguments; it can only use the information saved
135in the __entry data structure.