xref: /linux/tools/perf/Documentation/perf-trace.txt (revision f11b2803bb88655d90b88c787710b53100913bff)
1perf-trace(1)
2=============
3
4NAME
5----
6perf-trace - strace inspired tool
7
8SYNOPSIS
9--------
10[verse]
11'perf trace'
12'perf trace record'
13
14DESCRIPTION
15-----------
16This command will show the events associated with the target, initially
17syscalls, but other system events like pagefaults, task lifetime events,
18scheduling events, etc.
19
20This is a live mode tool in addition to working with perf.data files like
21the other perf tools. Files can be generated using the 'perf record' command
22but the session needs to include the raw_syscalls events (-e 'raw_syscalls:*').
23Alternatively, 'perf trace record' can be used as a shortcut to
24automatically include the raw_syscalls events when writing events to a file.
25
26The following options apply to perf trace; options to perf trace record are
27found in the perf record man page.
28
29OPTIONS
30-------
31
32-a::
33--all-cpus::
34        System-wide collection from all CPUs.
35
36-e::
37--expr::
38--event::
39	List of syscalls and other perf events (tracepoints, HW cache events,
40	etc) to show. Globbing is supported, e.g.: "epoll_*", "*msg*", etc.
41	See 'perf list' for a complete list of events.
42	Prefixing with ! shows all syscalls but the ones specified.  You may
43	need to escape it.
44
45-D msecs::
46--delay msecs::
47After starting the program, wait msecs before measuring. This is useful to
48filter out the startup phase of the program, which is often very different.
49
50-o::
51--output=::
52	Output file name.
53
54-p::
55--pid=::
56	Record events on existing process ID (comma separated list).
57
58-t::
59--tid=::
60        Record events on existing thread ID (comma separated list).
61
62-u::
63--uid=::
64        Record events in threads owned by uid. Name or number.
65
66-G::
67--cgroup::
68	Record events in threads in a cgroup.
69
70	Look for cgroups to set at the /sys/fs/cgroup/perf_event directory, then
71	remove the /sys/fs/cgroup/perf_event/ part and try:
72
73		perf trace -G A -e sched:*switch
74
75	Will set all raw_syscalls:sys_{enter,exit}, pgfault, vfs_getname, etc
76	_and_ sched:sched_switch to the 'A' cgroup, while:
77
78		perf trace -e sched:*switch -G A
79
80	will only set the sched:sched_switch event to the 'A' cgroup, all the
81	other events (raw_syscalls:sys_{enter,exit}, etc are left "without"
82	a cgroup (on the root cgroup, sys wide, etc).
83
84	Multiple cgroups:
85
86		perf trace -G A -e sched:*switch -G B
87
88	the syscall ones go to the 'A' cgroup, the sched:sched_switch goes
89	to the 'B' cgroup.
90
91--filter-pids=::
92	Filter out events for these pids and for 'trace' itself (comma separated list).
93
94-v::
95--verbose=::
96        Verbosity level.
97
98--no-inherit::
99	Child tasks do not inherit counters.
100
101-m::
102--mmap-pages=::
103	Number of mmap data pages (must be a power of two) or size
104	specification with appended unit character - B/K/M/G. The
105	size is rounded up to have nearest pages power of two value.
106
107-C::
108--cpu::
109Collect samples only on the list of CPUs provided. Multiple CPUs can be provided as a
110comma-separated list with no space: 0,1. Ranges of CPUs are specified with -: 0-2.
111In per-thread mode with inheritance mode on (default), Events are captured only when
112the thread executes on the designated CPUs. Default is to monitor all CPUs.
113
114--duration::
115	Show only events that had a duration greater than N.M ms.
116
117--sched::
118	Accrue thread runtime and provide a summary at the end of the session.
119
120--failure::
121	Show only syscalls that failed, i.e. that returned < 0.
122
123-i::
124--input::
125	Process events from a given perf data file.
126
127-T::
128--time::
129	Print full timestamp rather time relative to first sample.
130
131--comm::
132        Show process COMM right beside its ID, on by default, disable with --no-comm.
133
134-s::
135--summary::
136	Show only a summary of syscalls by thread with min, max, and average times
137    (in msec) and relative stddev.
138
139-S::
140--with-summary::
141	Show all syscalls followed by a summary by thread with min, max, and
142    average times (in msec) and relative stddev.
143
144--tool_stats::
145	Show tool stats such as number of times fd->pathname was discovered thru
146	hooking the open syscall return + vfs_getname or via reading /proc/pid/fd, etc.
147
148-f::
149--force::
150	Don't complain, do it.
151
152-F=[all|min|maj]::
153--pf=[all|min|maj]::
154	Trace pagefaults. Optionally, you can specify whether you want minor,
155	major or all pagefaults. Default value is maj.
156
157--syscalls::
158	Trace system calls. This options is enabled by default, disable with
159	--no-syscalls.
160
161--call-graph [mode,type,min[,limit],order[,key][,branch]]::
162        Setup and enable call-graph (stack chain/backtrace) recording.
163        See `--call-graph` section in perf-record and perf-report
164        man pages for details. The ones that are most useful in 'perf trace'
165        are 'dwarf' and 'lbr', where available, try: 'perf trace --call-graph dwarf'.
166
167        Using this will, for the root user, bump the value of --mmap-pages to 4
168        times the maximum for non-root users, based on the kernel.perf_event_mlock_kb
169        sysctl. This is done only if the user doesn't specify a --mmap-pages value.
170
171--kernel-syscall-graph::
172	 Show the kernel callchains on the syscall exit path.
173
174--max-events=N::
175	Stop after processing N events. Note that strace-like events are considered
176	only at exit time or when a syscall is interrupted, i.e. in those cases this
177	option is equivalent to the number of lines printed.
178
179--switch-on EVENT_NAME::
180	Only consider events after this event is found.
181
182--switch-off EVENT_NAME::
183	Stop considering events after this event is found.
184
185--show-on-off-events::
186	Show the --switch-on/off events too.
187
188--max-stack::
189        Set the stack depth limit when parsing the callchain, anything
190        beyond the specified depth will be ignored. Note that at this point
191        this is just about the presentation part, i.e. the kernel is still
192        not limiting, the overhead of callchains needs to be set via the
193        knobs in --call-graph dwarf.
194
195        Implies '--call-graph dwarf' when --call-graph not present on the
196        command line, on systems where DWARF unwinding was built in.
197
198        Default: /proc/sys/kernel/perf_event_max_stack when present for
199                 live sessions (without --input/-i), 127 otherwise.
200
201--min-stack::
202        Set the stack depth limit when parsing the callchain, anything
203        below the specified depth will be ignored. Disabled by default.
204
205        Implies '--call-graph dwarf' when --call-graph not present on the
206        command line, on systems where DWARF unwinding was built in.
207
208--print-sample::
209	Print the PERF_RECORD_SAMPLE PERF_SAMPLE_ info for the
210	raw_syscalls:sys_{enter,exit} tracepoints, for debugging.
211
212--proc-map-timeout::
213	When processing pre-existing threads /proc/XXX/mmap, it may take a long time,
214	because the file may be huge. A time out is needed in such cases.
215	This option sets the time out limit. The default value is 500 ms.
216
217--sort-events::
218	Do sorting on batches of events, use when noticing out of order events that
219	may happen, for instance, when a thread gets migrated to a different CPU
220	while processing a syscall.
221
222--libtraceevent_print::
223	Use libtraceevent to print tracepoint arguments. By default 'perf trace' uses
224	the same beautifiers used in the strace-like enter+exit lines to augment the
225	tracepoint arguments.
226
227--map-dump::
228	Dump BPF maps setup by events passed via -e, for instance the augmented_raw_syscalls
229	living in tools/perf/examples/bpf/augmented_raw_syscalls.c. For now this
230	dumps just boolean map values and integer keys, in time this will print in hex
231	by default and use BTF when available, as well as use functions to do pretty
232	printing using the existing 'perf trace' syscall arg beautifiers to map integer
233	arguments to strings (pid to comm, syscall id to syscall name, etc).
234
235
236PAGEFAULTS
237----------
238
239When tracing pagefaults, the format of the trace is as follows:
240
241<min|maj>fault [<ip.symbol>+<ip.offset>] => <addr.dso@addr.offset> (<map type><addr level>).
242
243- min/maj indicates whether fault event is minor or major;
244- ip.symbol shows symbol for instruction pointer (the code that generated the
245  fault); if no debug symbols available, perf trace will print raw IP;
246- addr.dso shows DSO for the faulted address;
247- map type is either 'd' for non-executable maps or 'x' for executable maps;
248- addr level is either 'k' for kernel dso or '.' for user dso.
249
250For symbols resolution you may need to install debugging symbols.
251
252Please be aware that duration is currently always 0 and doesn't reflect actual
253time it took for fault to be handled!
254
255When --verbose specified, perf trace tries to print all available information
256for both IP and fault address in the form of dso@symbol+offset.
257
258EXAMPLES
259--------
260
261Trace only major pagefaults:
262
263 $ perf trace --no-syscalls -F
264
265Trace syscalls, major and minor pagefaults:
266
267 $ perf trace -F all
268
269  1416.547 ( 0.000 ms): python/20235 majfault [CRYPTO_push_info_+0x0] => /lib/x86_64-linux-gnu/libcrypto.so.1.0.0@0x61be0 (x.)
270
271  As you can see, there was major pagefault in python process, from
272  CRYPTO_push_info_ routine which faulted somewhere in libcrypto.so.
273
274Trace the first 4 open, openat or open_by_handle_at syscalls (in the future more syscalls may match here):
275
276  $ perf trace -e open* --max-events 4
277  [root@jouet perf]# trace -e open* --max-events 4
278  2272.992 ( 0.037 ms): gnome-shell/1370 openat(dfd: CWD, filename: /proc/self/stat) = 31
279  2277.481 ( 0.139 ms): gnome-shell/3039 openat(dfd: CWD, filename: /proc/self/stat) = 65
280  3026.398 ( 0.076 ms): gnome-shell/3039 openat(dfd: CWD, filename: /proc/self/stat) = 65
281  4294.665 ( 0.015 ms): sed/15879 openat(dfd: CWD, filename: /etc/ld.so.cache, flags: CLOEXEC) = 3
282  $
283
284Trace the first minor page fault when running a workload:
285
286  # perf trace -F min --max-stack=7 --max-events 1 sleep 1
287     0.000 ( 0.000 ms): sleep/18006 minfault [__clear_user+0x1a] => 0x5626efa56080 (?k)
288                                       __clear_user ([kernel.kallsyms])
289                                       load_elf_binary ([kernel.kallsyms])
290                                       search_binary_handler ([kernel.kallsyms])
291                                       __do_execve_file.isra.33 ([kernel.kallsyms])
292                                       __x64_sys_execve ([kernel.kallsyms])
293                                       do_syscall_64 ([kernel.kallsyms])
294                                       entry_SYSCALL_64 ([kernel.kallsyms])
295  #
296
297Trace the next min page page fault to take place on the first CPU:
298
299  # perf trace -F min --call-graph=dwarf --max-events 1 --cpu 0
300     0.000 ( 0.000 ms): Web Content/17136 minfault [js::gc::Chunk::fetchNextDecommittedArena+0x4b] => 0x7fbe6181b000 (?.)
301                                       js::gc::FreeSpan::initAsEmpty (inlined)
302                                       js::gc::Arena::setAsNotAllocated (inlined)
303                                       js::gc::Chunk::fetchNextDecommittedArena (/usr/lib64/firefox/libxul.so)
304                                       js::gc::Chunk::allocateArena (/usr/lib64/firefox/libxul.so)
305                                       js::gc::GCRuntime::allocateArena (/usr/lib64/firefox/libxul.so)
306                                       js::gc::ArenaLists::allocateFromArena (/usr/lib64/firefox/libxul.so)
307                                       js::gc::GCRuntime::tryNewTenuredThing<JSString, (js::AllowGC)1> (inlined)
308                                       js::AllocateString<JSString, (js::AllowGC)1> (/usr/lib64/firefox/libxul.so)
309                                       js::Allocate<JSThinInlineString, (js::AllowGC)1> (inlined)
310                                       JSThinInlineString::new_<(js::AllowGC)1> (inlined)
311                                       AllocateInlineString<(js::AllowGC)1, unsigned char> (inlined)
312                                       js::ConcatStrings<(js::AllowGC)1> (/usr/lib64/firefox/libxul.so)
313                                       [0x18b26e6bc2bd] (/tmp/perf-17136.map)
314  #
315
316Trace the next two sched:sched_switch events, four block:*_plug events, the
317next block:*_unplug and the next three net:*dev_queue events, this last one
318with a backtrace of at most 16 entries, system wide:
319
320  # perf trace -e sched:*switch/nr=2/,block:*_plug/nr=4/,block:*_unplug/nr=1/,net:*dev_queue/nr=3,max-stack=16/
321     0.000 :0/0 sched:sched_switch:swapper/2:0 [120] S ==> rcu_sched:10 [120]
322     0.015 rcu_sched/10 sched:sched_switch:rcu_sched:10 [120] R ==> swapper/2:0 [120]
323   254.198 irq/50-iwlwifi/680 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051f600 len=66
324                                       __dev_queue_xmit ([kernel.kallsyms])
325   273.977 :0/0 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051f600 len=78
326                                       __dev_queue_xmit ([kernel.kallsyms])
327   274.007 :0/0 net:net_dev_queue:dev=wlp3s0 skbaddr=0xffff93498051ff00 len=78
328                                       __dev_queue_xmit ([kernel.kallsyms])
329  2930.140 kworker/u16:58/2722 block:block_plug:[kworker/u16:58]
330  2930.162 kworker/u16:58/2722 block:block_unplug:[kworker/u16:58] 1
331  4466.094 jbd2/dm-2-8/748 block:block_plug:[jbd2/dm-2-8]
332  8050.123 kworker/u16:30/2694 block:block_plug:[kworker/u16:30]
333  8050.271 kworker/u16:30/2694 block:block_plug:[kworker/u16:30]
334  #
335
336SEE ALSO
337--------
338linkperf:perf-record[1], linkperf:perf-script[1]
339