2018-02-17 13:39:42 +08:00
|
|
|
=============
|
|
|
|
Event Tracing
|
|
|
|
=============
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
:Author: Theodore Ts'o
|
|
|
|
:Updated: Li Zefan and Tom Zanussi
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-05-19 14:43:15 +08:00
|
|
|
1. Introduction
|
|
|
|
===============
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2018-05-09 05:54:36 +08:00
|
|
|
Tracepoints (see Documentation/trace/tracepoints.rst) can be used
|
2009-04-12 03:51:18 +08:00
|
|
|
without creating custom kernel modules to register probe functions
|
|
|
|
using the event tracing infrastructure.
|
|
|
|
|
|
|
|
Not all tracepoints can be traced using the event tracing system;
|
|
|
|
the kernel developer must provide code snippets which define how the
|
|
|
|
tracing information is saved into the tracing buffer, and how the
|
2009-05-19 14:43:15 +08:00
|
|
|
tracing information should be printed.
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-05-19 14:43:15 +08:00
|
|
|
2. Using Event Tracing
|
|
|
|
======================
|
|
|
|
|
|
|
|
2.1 Via the 'set_event' interface
|
|
|
|
---------------------------------
|
2009-04-12 03:51:18 +08:00
|
|
|
|
|
|
|
The events which are available for tracing can be found in the file
|
2009-09-07 20:37:17 +08:00
|
|
|
/sys/kernel/debug/tracing/available_events.
|
2009-04-12 03:51:18 +08:00
|
|
|
|
|
|
|
To enable a particular event, such as 'sched_wakeup', simply echo it
|
2018-02-17 13:39:42 +08:00
|
|
|
to /sys/kernel/debug/tracing/set_event. For example::
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo sched_wakeup >> /sys/kernel/debug/tracing/set_event
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
.. Note:: '>>' is necessary, otherwise it will firstly disable all the events.
|
2009-04-12 03:51:18 +08:00
|
|
|
|
|
|
|
To disable an event, echo the event name to the set_event file prefixed
|
2018-02-17 13:39:42 +08:00
|
|
|
with an exclamation point::
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo '!sched_wakeup' >> /sys/kernel/debug/tracing/set_event
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To disable all events, echo an empty line to the set_event file::
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo > /sys/kernel/debug/tracing/set_event
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2018-03-08 01:44:08 +08:00
|
|
|
To enable all events, echo ``*:*`` or ``*:`` to the set_event file::
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo *:* > /sys/kernel/debug/tracing/set_event
|
2009-04-12 03:51:18 +08:00
|
|
|
|
|
|
|
The events are organized into subsystems, such as ext4, irq, sched,
|
|
|
|
etc., and a full event name looks like this: <subsystem>:<event>. The
|
|
|
|
subsystem name is optional, but it is displayed in the available_events
|
|
|
|
file. All of the events in a subsystem can be specified via the syntax
|
2018-03-08 01:44:08 +08:00
|
|
|
``<subsystem>:*``; for example, to enable all irq events, you can use the
|
2018-02-17 13:39:42 +08:00
|
|
|
command::
|
2009-04-12 03:51:18 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo 'irq:*' > /sys/kernel/debug/tracing/set_event
|
2009-05-19 14:43:15 +08:00
|
|
|
|
|
|
|
2.2 Via the 'enable' toggle
|
|
|
|
---------------------------
|
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
The events available are also listed in /sys/kernel/debug/tracing/events/ hierarchy
|
2009-05-19 14:43:15 +08:00
|
|
|
of directories.
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To enable event 'sched_wakeup'::
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo 1 > /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To disable it::
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo 0 > /sys/kernel/debug/tracing/events/sched/sched_wakeup/enable
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To enable all events in sched subsystem::
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo 1 > /sys/kernel/debug/tracing/events/sched/enable
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To enable all events::
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-09-07 20:37:17 +08:00
|
|
|
# echo 1 > /sys/kernel/debug/tracing/events/enable
|
2009-05-19 14:43:15 +08:00
|
|
|
|
|
|
|
When reading one of these enable files, there are four results:
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
- 0 - all events this file affects are disabled
|
|
|
|
- 1 - all events this file affects are enabled
|
|
|
|
- X - there is a mixture of events enabled and disabled
|
|
|
|
- ? - this file does not affect any event
|
2009-05-19 14:43:15 +08:00
|
|
|
|
2009-07-01 10:47:05 +08:00
|
|
|
2.3 Boot option
|
|
|
|
---------------
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
In order to facilitate early boot debugging, use boot option::
|
2009-07-01 10:47:05 +08:00
|
|
|
|
|
|
|
trace_event=[event-list]
|
|
|
|
|
2009-12-21 14:27:24 +08:00
|
|
|
event-list is a comma separated list of events. See section 2.1 for event
|
|
|
|
format.
|
2009-07-01 10:47:05 +08:00
|
|
|
|
2009-05-19 14:43:15 +08:00
|
|
|
3. Defining an event-enabled tracepoint
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
See The example provided in samples/trace_events
|
|
|
|
|
2009-09-11 12:13:51 +08:00
|
|
|
4. Event formats
|
|
|
|
================
|
|
|
|
|
|
|
|
Each trace event has a 'format' file associated with it that contains
|
|
|
|
a description of each field in a logged event. This information can
|
|
|
|
be used to parse the binary trace stream, and is also the place to
|
|
|
|
find the field names that can be used in event filters (see section 5).
|
|
|
|
|
|
|
|
It also displays the format string that will be used to print the
|
|
|
|
event in text mode, along with the event name and ID used for
|
|
|
|
profiling.
|
|
|
|
|
2018-03-08 01:44:08 +08:00
|
|
|
Every event has a set of ``common`` fields associated with it; these are
|
|
|
|
the fields prefixed with ``common_``. The other fields vary between
|
2009-09-11 12:13:51 +08:00
|
|
|
events and correspond to the fields defined in the TRACE_EVENT
|
|
|
|
definition for that event.
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
Each field in the format has the form::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
field:field-type field-name; offset:N; size:N;
|
|
|
|
|
|
|
|
where offset is the offset of the field in the trace record and size
|
|
|
|
is the size of the data item, in bytes.
|
|
|
|
|
|
|
|
For example, here's the information displayed for the 'sched_wakeup'
|
2018-02-17 13:39:42 +08:00
|
|
|
event::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cat /sys/kernel/debug/tracing/events/sched/sched_wakeup/format
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
name: sched_wakeup
|
|
|
|
ID: 60
|
|
|
|
format:
|
|
|
|
field:unsigned short common_type; offset:0; size:2;
|
|
|
|
field:unsigned char common_flags; offset:2; size:1;
|
|
|
|
field:unsigned char common_preempt_count; offset:3; size:1;
|
|
|
|
field:int common_pid; offset:4; size:4;
|
|
|
|
field:int common_tgid; offset:8; size:4;
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
field:char comm[TASK_COMM_LEN]; offset:12; size:16;
|
|
|
|
field:pid_t pid; offset:28; size:4;
|
|
|
|
field:int prio; offset:32; size:4;
|
|
|
|
field:int success; offset:36; size:4;
|
|
|
|
field:int cpu; offset:40; size:4;
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
print fmt: "task %s:%d [%d] success=%d [%03d]", REC->comm, REC->pid,
|
|
|
|
REC->prio, REC->success, REC->cpu
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
This event contains 10 fields, the first 5 common and the remaining 5
|
|
|
|
event-specific. All the fields for this event are numeric, except for
|
|
|
|
'comm' which is a string, a distinction important for event filtering.
|
|
|
|
|
|
|
|
5. Event filtering
|
|
|
|
==================
|
|
|
|
|
|
|
|
Trace events can be filtered in the kernel by associating boolean
|
|
|
|
'filter expressions' with them. As soon as an event is logged into
|
|
|
|
the trace buffer, its fields are checked against the filter expression
|
|
|
|
associated with that event type. An event with field values that
|
|
|
|
'match' the filter will appear in the trace output, and an event whose
|
|
|
|
values don't match will be discarded. An event with no filter
|
|
|
|
associated with it matches everything, and is the default when no
|
|
|
|
filter has been set for an event.
|
|
|
|
|
|
|
|
5.1 Expression syntax
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
A filter expression consists of one or more 'predicates' that can be
|
|
|
|
combined using the logical operators '&&' and '||'. A predicate is
|
|
|
|
simply a clause that compares the value of a field contained within a
|
|
|
|
logged event with a constant value and returns either 0 or 1 depending
|
2018-02-17 13:39:42 +08:00
|
|
|
on whether the field value matched (1) or didn't match (0)::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
field-name relational-operator value
|
|
|
|
|
|
|
|
Parentheses can be used to provide arbitrary logical groupings and
|
|
|
|
double-quotes can be used to prevent the shell from interpreting
|
|
|
|
operators as shell metacharacters.
|
|
|
|
|
|
|
|
The field-names available for use in filters can be found in the
|
|
|
|
'format' files for trace events (see section 4).
|
|
|
|
|
|
|
|
The relational-operators depend on the type of the field being tested:
|
|
|
|
|
|
|
|
The operators available for numeric fields are:
|
|
|
|
|
tracing: Add binary '&' filter for events
There are some cases when filtering on a set flag of a field of a tracepoint
is useful. But currently the only filtering commands for numbered fields
is ==, !=, <, <=, >, >=. This does not help when you just want to trace if
a specific flag is set. For example:
> # sudo trace-cmd record -e brcmfmac:brcmf_dbg -f 'level & 0x40000'
> disable all
> enable brcmfmac:brcmf_dbg
> path = /sys/kernel/debug/tracing/events/brcmfmac/brcmf_dbg/enable
> (level & 0x40000)
> ^
> parse_error: Invalid operator
>
When trying to trace brcmf_dbg when level has its 1 << 18 bit set, the
filter fails to perform.
By allowing a binary '&' operation, this gives the user the ability to
test a bit.
Note, a binary '|' is not added, as it doesn't make sense as fields must
be compared to constants (for now), and ORing a constant will always return
true.
Link: http://lkml.kernel.org/r/1371057385.9844.261.camel@gandalf.local.home
Suggested-by: Arend van Spriel <arend@broadcom.com>
Tested-by: Arend van Spriel <arend@broadcom.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-06-13 01:16:25 +08:00
|
|
|
==, !=, <, <=, >, >=, &
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
And for string fields they are:
|
|
|
|
|
2013-06-17 22:59:17 +08:00
|
|
|
==, !=, ~
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-03-08 01:44:08 +08:00
|
|
|
The glob (~) accepts a wild card character (\*,?) and character classes
|
2018-02-17 13:39:42 +08:00
|
|
|
([). For example::
|
2013-06-17 22:59:17 +08:00
|
|
|
|
|
|
|
prev_comm ~ "*sh"
|
|
|
|
prev_comm ~ "sh*"
|
|
|
|
prev_comm ~ "*sh*"
|
2016-10-05 19:58:15 +08:00
|
|
|
prev_comm ~ "ba*sh"
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
5.2 Setting filters
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
A filter for an individual event is set by writing a filter expression
|
|
|
|
to the 'filter' file for the given event.
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
For example::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/sched/sched_wakeup
|
|
|
|
# echo "common_preempt_count > 4" > filter
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
A slightly more involved example::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/signal/signal_generate
|
|
|
|
# echo "((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
If there is an error in the expression, you'll get an 'Invalid
|
|
|
|
argument' error when setting it, and the erroneous string along with
|
2018-02-17 13:39:42 +08:00
|
|
|
an error message can be seen by looking at the filter e.g.::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/signal/signal_generate
|
|
|
|
# echo "((sig >= 10 && sig < 15) || dsig == 17) && comm != bash" > filter
|
|
|
|
-bash: echo: write error: Invalid argument
|
|
|
|
# cat filter
|
|
|
|
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
|
|
|
|
^
|
|
|
|
parse_error: Field not found
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
Currently the caret ('^') for an error always appears at the beginning of
|
|
|
|
the filter string; the error message should still be useful though
|
|
|
|
even without more accurate position info.
|
|
|
|
|
|
|
|
5.3 Clearing filters
|
|
|
|
--------------------
|
|
|
|
|
|
|
|
To clear the filter for an event, write a '0' to the event's filter
|
|
|
|
file.
|
|
|
|
|
|
|
|
To clear the filters for all events in a subsystem, write a '0' to the
|
|
|
|
subsystem's filter file.
|
|
|
|
|
|
|
|
5.3 Subsystem filters
|
|
|
|
---------------------
|
|
|
|
|
|
|
|
For convenience, filters for every event in a subsystem can be set or
|
|
|
|
cleared as a group by writing a filter expression into the filter file
|
2010-03-16 18:47:56 +08:00
|
|
|
at the root of the subsystem. Note however, that if a filter for any
|
2009-09-11 12:13:51 +08:00
|
|
|
event within the subsystem lacks a field specified in the subsystem
|
|
|
|
filter, or if the filter can't be applied for any other reason, the
|
|
|
|
filter for that event will retain its previous setting. This can
|
|
|
|
result in an unintended mixture of filters which could lead to
|
|
|
|
confusing (to the user who might think different filters are in
|
|
|
|
effect) trace output. Only filters that reference just the common
|
|
|
|
fields can be guaranteed to propagate successfully to all events.
|
|
|
|
|
|
|
|
Here are a few subsystem filter examples that also illustrate the
|
|
|
|
above points:
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
Clear the filters on all events in the sched subsystem::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/sched
|
|
|
|
# echo 0 > filter
|
|
|
|
# cat sched_switch/filter
|
|
|
|
none
|
|
|
|
# cat sched_wakeup/filter
|
|
|
|
none
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
Set a filter using only common fields for all events in the sched
|
2018-02-17 13:39:42 +08:00
|
|
|
subsystem (all events end up with the same filter)::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/sched
|
|
|
|
# echo common_pid == 0 > filter
|
|
|
|
# cat sched_switch/filter
|
|
|
|
common_pid == 0
|
|
|
|
# cat sched_wakeup/filter
|
|
|
|
common_pid == 0
|
2009-09-11 12:13:51 +08:00
|
|
|
|
|
|
|
Attempt to set a filter using a non-common field for all events in the
|
2010-03-16 18:47:56 +08:00
|
|
|
sched subsystem (all events but those that have a prev_pid field retain
|
2018-02-17 13:39:42 +08:00
|
|
|
their old filters)::
|
2009-09-11 12:13:51 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing/events/sched
|
|
|
|
# echo prev_pid == 0 > filter
|
|
|
|
# cat sched_switch/filter
|
|
|
|
prev_pid == 0
|
|
|
|
# cat sched_wakeup/filter
|
|
|
|
common_pid == 0
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2015-11-04 05:37:15 +08:00
|
|
|
5.4 PID filtering
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
The set_event_pid file in the same directory as the top events directory
|
|
|
|
exists, will filter all events from tracing any task that does not have the
|
|
|
|
PID listed in the set_event_pid file.
|
2018-02-17 13:39:42 +08:00
|
|
|
::
|
2015-11-04 05:37:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# cd /sys/kernel/debug/tracing
|
|
|
|
# echo $$ > set_event_pid
|
|
|
|
# echo 1 > events/enable
|
2015-11-04 05:37:15 +08:00
|
|
|
|
|
|
|
Will only trace events for the current task.
|
|
|
|
|
|
|
|
To add more PIDs without losing the PIDs already included, use '>>'.
|
2018-02-17 13:39:42 +08:00
|
|
|
::
|
2015-11-04 05:37:15 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 123 244 1 >> set_event_pid
|
2015-11-04 05:37:15 +08:00
|
|
|
|
|
|
|
|
2013-10-24 21:59:30 +08:00
|
|
|
6. Event triggers
|
|
|
|
=================
|
|
|
|
|
|
|
|
Trace events can be made to conditionally invoke trigger 'commands'
|
|
|
|
which can take various forms and are described in detail below;
|
|
|
|
examples would be enabling or disabling other trace events or invoking
|
|
|
|
a stack trace whenever the trace event is hit. Whenever a trace event
|
|
|
|
with attached triggers is invoked, the set of trigger commands
|
|
|
|
associated with that event is invoked. Any given trigger can
|
|
|
|
additionally have an event filter of the same form as described in
|
|
|
|
section 5 (Event filtering) associated with it - the command will only
|
|
|
|
be invoked if the event being invoked passes the associated filter.
|
|
|
|
If no filter is associated with the trigger, it always passes.
|
|
|
|
|
|
|
|
Triggers are added to and removed from a particular event by writing
|
|
|
|
trigger expressions to the 'trigger' file for the given event.
|
|
|
|
|
|
|
|
A given event can have any number of triggers associated with it,
|
|
|
|
subject to any restrictions that individual commands may have in that
|
|
|
|
regard.
|
|
|
|
|
|
|
|
Event triggers are implemented on top of "soft" mode, which means that
|
|
|
|
whenever a trace event has one or more triggers associated with it,
|
|
|
|
the event is activated even if it isn't actually enabled, but is
|
|
|
|
disabled in a "soft" mode. That is, the tracepoint will be called,
|
|
|
|
but just will not be traced, unless of course it's actually enabled.
|
|
|
|
This scheme allows triggers to be invoked even for events that aren't
|
|
|
|
enabled, and also allows the current event filter implementation to be
|
|
|
|
used for conditionally invoking triggers.
|
|
|
|
|
|
|
|
The syntax for event triggers is roughly based on the syntax for
|
|
|
|
set_ftrace_filter 'ftrace filter commands' (see the 'Filter commands'
|
2018-05-12 03:41:24 +08:00
|
|
|
section of Documentation/trace/ftrace.rst), but there are major
|
2013-10-24 21:59:30 +08:00
|
|
|
differences and the implementation isn't currently tied to it in any
|
|
|
|
way, so beware about making generalizations between the two.
|
|
|
|
|
2018-05-12 03:41:24 +08:00
|
|
|
Note: Writing into trace_marker (See Documentation/trace/ftrace.rst)
|
|
|
|
can also enable triggers that are written into
|
|
|
|
/sys/kernel/tracing/events/ftrace/print/trigger
|
|
|
|
|
2013-10-24 21:59:30 +08:00
|
|
|
6.1 Expression syntax
|
|
|
|
---------------------
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
Triggers are added by echoing the command to the 'trigger' file::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
# echo 'command[:count] [if filter]' > trigger
|
|
|
|
|
|
|
|
Triggers are removed by echoing the same command but starting with '!'
|
2018-02-17 13:39:42 +08:00
|
|
|
to the 'trigger' file::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
# echo '!command[:count] [if filter]' > trigger
|
|
|
|
|
|
|
|
The [if filter] part isn't used in matching commands when removing, so
|
|
|
|
leaving that off in a '!' command will accomplish the same thing as
|
|
|
|
having it in.
|
|
|
|
|
|
|
|
The filter syntax is the same as that described in the 'Event
|
|
|
|
filtering' section above.
|
|
|
|
|
|
|
|
For ease of use, writing to the trigger file using '>' currently just
|
|
|
|
adds or removes a single trigger and there's no explicit '>>' support
|
|
|
|
('>' actually behaves like '>>') or truncation support to remove all
|
|
|
|
triggers (you have to use '!' for each one added.)
|
|
|
|
|
|
|
|
6.2 Supported trigger commands
|
|
|
|
------------------------------
|
|
|
|
|
|
|
|
The following commands are supported:
|
|
|
|
|
|
|
|
- enable_event/disable_event
|
|
|
|
|
|
|
|
These commands can enable or disable another trace event whenever
|
|
|
|
the triggering event is hit. When these commands are registered,
|
|
|
|
the other trace event is activated, but disabled in a "soft" mode.
|
|
|
|
That is, the tracepoint will be called, but just will not be traced.
|
|
|
|
The event tracepoint stays in this mode as long as there's a trigger
|
|
|
|
in effect that can trigger it.
|
|
|
|
|
|
|
|
For example, the following trigger causes kmalloc events to be
|
|
|
|
traced when a read system call is entered, and the :1 at the end
|
2018-02-17 13:39:42 +08:00
|
|
|
specifies that this enablement happens only once::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'enable_event:kmem:kmalloc:1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
The following trigger causes kmalloc events to stop being traced
|
|
|
|
when a read system call exits. This disablement happens on every
|
2018-02-17 13:39:42 +08:00
|
|
|
read system call exit::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'disable_event:kmem:kmalloc' > \
|
|
|
|
/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
The format is::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
enable_event:<system>:<event>[:count]
|
|
|
|
disable_event:<system>:<event>[:count]
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To remove the above commands::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!enable_event:kmem:kmalloc:1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/syscalls/sys_enter_read/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!disable_event:kmem:kmalloc' > \
|
|
|
|
/sys/kernel/debug/tracing/events/syscalls/sys_exit_read/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
Note that there can be any number of enable/disable_event triggers
|
|
|
|
per triggering event, but there can only be one trigger per
|
|
|
|
triggered event. e.g. sys_enter_read can have triggers enabling both
|
|
|
|
kmem:kmalloc and sched:sched_switch, but can't have two kmem:kmalloc
|
|
|
|
versions such as kmem:kmalloc and kmem:kmalloc:1 or 'kmem:kmalloc if
|
|
|
|
bytes_req == 256' and 'kmem:kmalloc if bytes_alloc == 256' (they
|
|
|
|
could be combined into a single filter on kmem:kmalloc though).
|
|
|
|
|
|
|
|
- stacktrace
|
|
|
|
|
|
|
|
This command dumps a stacktrace in the trace buffer whenever the
|
|
|
|
triggering event occurs.
|
|
|
|
|
|
|
|
For example, the following trigger dumps a stacktrace every time the
|
2018-02-17 13:39:42 +08:00
|
|
|
kmalloc tracepoint is hit::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'stacktrace' > \
|
|
|
|
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
The following trigger dumps a stacktrace the first 5 times a kmalloc
|
2018-02-17 13:39:42 +08:00
|
|
|
request happens with a size >= 64K::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'stacktrace:5 if bytes_req >= 65536' > \
|
|
|
|
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
The format is::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
stacktrace[:count]
|
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To remove the above commands::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!stacktrace' > \
|
|
|
|
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!stacktrace:5 if bytes_req >= 65536' > \
|
|
|
|
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
The latter can also be removed more simply by the following (without
|
2018-02-17 13:39:42 +08:00
|
|
|
the filter)::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!stacktrace:5' > \
|
|
|
|
/sys/kernel/debug/tracing/events/kmem/kmalloc/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
Note that there can be only one stacktrace trigger per triggering
|
|
|
|
event.
|
|
|
|
|
|
|
|
- snapshot
|
|
|
|
|
|
|
|
This command causes a snapshot to be triggered whenever the
|
|
|
|
triggering event occurs.
|
|
|
|
|
|
|
|
The following command creates a snapshot every time a block request
|
|
|
|
queue is unplugged with a depth > 1. If you were tracing a set of
|
|
|
|
events or functions at the time, the snapshot trace buffer would
|
2018-02-17 13:39:42 +08:00
|
|
|
capture those events when the trigger event occurred::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'snapshot if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To only snapshot once::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'snapshot:1 if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To remove the above commands::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!snapshot if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!snapshot:1 if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
Note that there can be only one snapshot trigger per triggering
|
|
|
|
event.
|
|
|
|
|
|
|
|
- traceon/traceoff
|
|
|
|
|
|
|
|
These commands turn tracing on and off when the specified events are
|
|
|
|
hit. The parameter determines how many times the tracing system is
|
|
|
|
turned on and off. If unspecified, there is no limit.
|
|
|
|
|
|
|
|
The following command turns tracing off the first time a block
|
|
|
|
request queue is unplugged with a depth > 1. If you were tracing a
|
|
|
|
set of events or functions at the time, you could then examine the
|
|
|
|
trace buffer to see the sequence of events that led up to the
|
2018-02-17 13:39:42 +08:00
|
|
|
trigger event::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'traceoff:1 if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To always disable tracing when nr_rq > 1::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo 'traceoff if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
To remove the above commands::
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!traceoff:1 if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
2018-02-17 13:39:42 +08:00
|
|
|
# echo '!traceoff if nr_rq > 1' > \
|
|
|
|
/sys/kernel/debug/tracing/events/block/block_unplug/trigger
|
2013-10-24 21:59:30 +08:00
|
|
|
|
|
|
|
Note that there can be only one traceon or traceoff trigger per
|
|
|
|
triggering event.
|
2016-03-04 02:54:56 +08:00
|
|
|
|
|
|
|
- hist
|
|
|
|
|
|
|
|
This command aggregates event hits into a hash table keyed on one or
|
|
|
|
more trace event format fields (or stacktrace) and a set of running
|
|
|
|
totals derived from one or more trace event format fields and/or
|
|
|
|
event counts (hitcount).
|
|
|
|
|
2018-01-16 10:51:35 +08:00
|
|
|
See Documentation/trace/histogram.txt for details and examples.
|