1TRACE-CMD-RECORD(1)                                        TRACE-CMD-RECORD(1)
2
3
4

NAME

6       trace-cmd-record - record a trace from the Ftrace Linux internal tracer
7

SYNOPSIS

9       trace-cmd record [OPTIONS] [command]
10

DESCRIPTION

12       The trace-cmd(1) record command will set up the Ftrace Linux kernel
13       tracer to record the specified plugins or events that happen while the
14       command executes. If no command is given, then it will record until the
15       user hits Ctrl-C.
16
17       The record command of trace-cmd will set up the Ftrace tracer to start
18       tracing the various events or plugins that are given on the command
19       line. It will then create a number of tracing processes (one per CPU)
20       that will start recording from the kernel ring buffer straight into
21       temporary files. When the command is complete (or Ctrl-C is hit) all
22       the files will be combined into a trace.dat file that can later be read
23       (see trace-cmd-report(1)).
24

OPTIONS

26       -p tracer
27           Specify a tracer. Tracers usually do more than just trace an event.
28           Common tracers are: function, function_graph, preemptirqsoff,
29           irqsoff, preemptoff and wakeup. A tracer must be supported by the
30           running kernel. To see a list of available tracers, see
31           trace-cmd-list(1).
32
33       -e event
34           Specify an event to trace. Various static trace points have been
35           added to the Linux kernel. They are grouped by subsystem where you
36           can enable all events of a given subsystem or specify specific
37           events to be enabled. The event is of the format
38           "subsystem:event-name". You can also just specify the subsystem
39           without the :event-name or the event-name without the "subsystem:".
40           Using "-e sched_switch" will enable the "sched_switch" event where
41           as, "-e sched" will enable all events under the "sched" subsystem.
42
43               The 'event' can also contain glob expressions. That is, "*stat*" will
44               select all events (or subsystems) that have the characters "stat" in their
45               names.
46
47               The keyword 'all' can be used to enable all events.
48
49       -a
50           Every event that is being recorded has its output format file saved
51           in the output file to be able to display it later. But if other
52           events are enabled in the trace without trace-cmd’s knowledge, the
53           formats of those events will not be recorded and trace-cmd report
54           will not be able to display them. If this is the case, then specify
55           the -a option and the format for all events in the system will be
56           saved.
57
58       -T
59           Enable a stacktrace on each event. For example:
60
61                         <idle>-0     [003] 58549.289091: sched_switch:         kworker/0:1:0 [120] R ==> trace-cmd:2603 [120]
62                         <idle>-0     [003] 58549.289092: kernel_stack:         <stack trace>
63               => schedule (ffffffff814b260e)
64               => cpu_idle (ffffffff8100a38c)
65               => start_secondary (ffffffff814ab828)
66
67       --func-stack
68           Enable a stack trace on all functions. Note this is only applicable
69           for the "function" plugin tracer, and will only take effect if the
70           -l option is used and succeeds in limiting functions. If the
71           function tracer is not filtered, and the stack trace is enabled,
72           you can live lock the machine.
73
74       -f filter
75           Specify a filter for the previous event. This must come after a -e.
76           This will filter what events get recorded based on the content of
77           the event. Filtering is passed to the kernel directly so what
78           filtering is allowed may depend on what version of the kernel you
79           have. Basically, it will let you use C notation to check if an
80           event should be processed or not.
81
82               ==, >=, <=, >, <, &, |, && and ||
83
84           The above are usually safe to use to compare fields.
85
86       -R trigger
87           Specify a trigger for the previous event. This must come after a
88           -e. This will add a given trigger to the given event. To only
89           enable the trigger and not the event itself, then place the event
90           after the -v option.
91
92               See Documentation/trace/events.txt in the Linux kernel source for more
93               information on triggers.
94
95       -v
96           This will cause all events specified after it on the command line
97           to not be traced. This is useful for selecting a subsystem to be
98           traced but to leave out various events. For Example: "-e sched -v
99           -e "*stat\*"" will enable all events in the sched subsystem except
100           those that have "stat" in their names.
101
102               Note: the *-v* option was taken from the way grep(1) inverts the following
103               matches.
104
105       -F
106           This will filter only the executable that is given on the command
107           line. If no command is given, then it will filter itself (pretty
108           pointless). Using -F will let you trace only events that are caused
109           by the given command.
110
111       -P pid
112           Similar to -F but lets you specify a process ID to trace.
113
114       -c
115           Used with either -F (or -P if kernel supports it) to trace the
116           process' children too.
117
118       -C clock
119           Set the trace clock to "clock".
120
121               Use trace-cmd(1) list -C to see what clocks are available.
122
123       -o output-file
124           By default, trace-cmd report will create a trace.dat file. You can
125           specify a different file to write to with the -o option.
126
127       -l function-name
128           This will limit the function and function_graph tracers to only
129           trace the given function name. More than one -l may be specified on
130           the command line to trace more than one function. The limited use
131           of glob expressions are also allowed. These are match* to only
132           filter functions that start with match.  *match to only filter
133           functions that end with match.  *match\* to only filter on
134           functions that contain match.
135
136       -g function-name
137           This option is for the function_graph plugin. It will graph the
138           given function. That is, it will only trace the function and all
139           functions that it calls. You can have more than one -g on the
140           command line.
141
142       -n function-name
143           This has the opposite effect of -l. The function given with the -n
144           option will not be traced. This takes precedence, that is, if you
145           include the same function for both -n and -l, it will not be
146           traced.
147
148       -d
149           Some tracer plugins enable the function tracer by default. Like the
150           latency tracers. This option prevents the function tracer from
151           being enabled at start up.
152
153       -D
154           The option -d will try to use the function-trace option to disable
155           the function tracer (if available), otherwise it defaults to the
156           proc file: /proc/sys/kernel/ftrace_enabled, but will not touch it
157           if the function-trace option is available. The -D option will
158           disable both the ftrace_enabled proc file as well as the
159           function-trace option if it exists.
160
161               Note, this disable function tracing for all users, which includes users
162               outside of ftrace tracers (stack_tracer, perf, etc).
163
164       -O option
165           Ftrace has various options that can be enabled or disabled. This
166           allows you to set them. Appending the text no to an option disables
167           it. For example: "-O nograph-time" will disable the "graph-time"
168           Ftrace option.
169
170       -s interval
171           The processes that trace-cmd creates to record from the ring buffer
172           need to wake up to do the recording. Setting the interval to zero
173           will cause the processes to wakeup every time new data is written
174           into the buffer. But since Ftrace is recording kernel activity, the
175           act of this processes going back to sleep may cause new events into
176           the ring buffer which will wake the process back up. This will
177           needlessly add extra data into the ring buffer.
178
179               The 'interval' metric is microseconds. The default is set to 1000 (1 ms).
180               This is the time each recording process will sleep before waking up to
181               record any new data that was written to the ring buffer.
182
183       -r priority
184           The priority to run the capture threads at. In a busy system the
185           trace capturing threads may be staved and events can be lost. This
186           increases the priority of those threads to the real time (FIFO)
187           priority. But use this option with care, it can also change the
188           behaviour of the system being traced.
189
190       -b size
191           This sets the ring buffer size to size kilobytes. Because the
192           Ftrace ring buffer is per CPU, this size is the size of each per
193           CPU ring buffer inside the kernel. Using "-b 10000" on a machine
194           with 4 CPUs will make Ftrace have a total buffer size of 40 Megs.
195
196       -B buffer-name
197           If the kernel supports multiple buffers, this will add a buffer
198           with the given name. If the buffer name already exists, that buffer
199           is just reset and will not be deleted at the end of record
200           execution. If the buffer is created, it will be removed at the end
201           of execution (unless the -k is set, or start command was used).
202
203               After a buffer name is stated, all events added after that will be
204               associated with that buffer. If no buffer is specified, or an event
205               is specified before a buffer name, it will be associated with the
206               main (toplevel) buffer.
207
208               trace-cmd record -e sched -B block -e block -B time -e timer sleep 1
209
210               The above is will enable all sched events in the main buffer. It will
211               then create a 'block' buffer instance and enable all block events within
212               that buffer. A 'time' buffer instance is created and all timer events
213               will be enabled for that event.
214
215       -m size
216           The max size in kilobytes that a per cpu buffer should be. Note,
217           due to rounding to page size, the number may not be totally
218           correct. Also, this is performed by switching between two buffers
219           that are half the given size thus the output may not be of the
220           given size even if much more was written.
221
222               Use this to prevent running out of diskspace for long runs.
223
224       -M cpumask
225           Set the cpumask for to trace. It only affects the last buffer
226           instance given. If supplied before any buffer instance, then it
227           affects the main buffer. The value supplied must be a hex number.
228
229               trace-cmd record -p function -M c -B events13 -e all -M 5
230
231               If the -M is left out, then the mask stays the same. To enable all
232               CPUs, pass in a value of '-1'.
233
234       -k
235           By default, when trace-cmd is finished tracing, it will reset the
236           buffers and disable all the tracing that it enabled. This option
237           keeps trace-cmd from disabling the tracer and reseting the buffer.
238           This option is useful for debugging trace-cmd.
239
240               Note: usually trace-cmd will set the "tracing_on" file back to what it
241               was before it was called. This option will leave that file set to zero.
242
243       -i
244           By default, if an event is listed that trace-cmd does not find, it
245           will exit with an error. This option will just ignore events that
246           are listed on the command line but are not found on the system.
247
248       -N host:port
249           If another machine is running "trace-cmd listen", this option is
250           used to have the data sent to that machine with UDP packets.
251           Instead of writing to an output file, the data is sent off to a
252           remote box. This is ideal for embedded machines with little
253           storage, or having a single machine that will keep all the data in
254           a single repository.
255
256               Note: This option is not supported with latency tracer plugins:
257                 wakeup, wakeup_rt, irqsoff, preemptoff and preemptirqsoff
258
259       -t
260           This option is used with -N, when there’s a need to send the live
261           data with TCP packets instead of UDP. Although TCP is not nearly as
262           fast as sending the UDP packets, but it may be needed if the
263           network is not that reliable, the amount of data is not that
264           intensive, and a guarantee is needed that all traced information is
265           transfered successfully.
266
267       -q | --quiet
268           For use with recording an application. Suppresses normal output
269           (except for errors) to allow only the application’s output to be
270           displayed.
271
272       --date
273           With the --date option, "trace-cmd" will write timestamps into the
274           trace buffer after it has finished recording. It will then map the
275           timestamp to gettimeofday which will allow wall time output from
276           the timestamps reading the created trace.dat file.
277
278       --max-graph-depth depth
279           Set the maximum depth the function_graph tracer will trace into a
280           function. A value of one will only show where userspace enters the
281           kernel but not any functions called in the kernel. The default is
282           zero, which means no limit.
283
284       --module module
285           Filter a module’s name in function tracing. It is equivalent to
286           adding :mod:module after all other functions being filtered. If no
287           other function filter is listed, then all modules functions will be
288           filtered in the filter.
289
290               '--module snd'  is equivalent to  '-l :mod:snd'
291
292               '--module snd -l "*jack*"' is equivalent to '-l "*jack*:mod:snd"'
293
294               '--module snd -n "*"' is equivalent to '-n :mod:snd'
295
296       --profile
297           With the --profile option, "trace-cmd" will enable tracing that can
298           be used with trace-cmd-report(1) --profile option. If a tracer -p
299           is not set, and function graph depth is supported by the kernel,
300           then the function_graph tracer will be enabled with a depth of one
301           (only show where userspace enters into the kernel). It will also
302           enable various tracepoints with stack tracing such that the report
303           can show where tasks have been blocked for the longest time.
304
305               See trace-cmd-profile(1) for more details and examples.
306
307       -H event-hooks
308           Add custom event matching to connect any two events together. When
309           not used with --profile, it will save the parameter and this will
310           be used by trace-cmd report --profile, too. That is:
311
312               trace-cmd record -H hrtimer_expire_entry,hrtimer/hrtimer_expire_exit,hrtimer,sp
313               trace-cmd report --profile
314
315               Will profile hrtimer_expire_entry and hrtimer_expire_ext times.
316
317               See trace-cmd-profile(1) for format.
318
319       -S
320           (for --profile only) Only enable the tracer or events speficied on
321           the command line. With this option, the function_graph tracer is
322           not enabled, nor are any events (like sched_switch), unless they
323           are specifically specified on the command line (i.e. -p function -e
324           sched_switch -e sched_wakeup)
325
326       --ts-offset offset
327           Add an offset for the timestamp in the trace.dat file. This will
328           add a offset option into the trace.dat file such that a trace-cmd
329           report will offset all the timestamps of the events by the given
330           offset. The offset is in raw units. That is, if the event
331           timestamps are in nanoseconds the offset will also be in
332           nanoseconds even if the displayed units are in microseconds.
333
334       --stderr
335           Have output go to stderr instead of stdout, but the output of the
336           command executed will not be changed. This is useful if you want to
337           monitor the output of the command being executed, but not see the
338           output from trace-cmd.
339

EXAMPLES

341       The basic way to trace all events:
342
343            # trace-cmd record -e all ls > /dev/null
344            # trace-cmd report
345                  trace-cmd-13541 [003] 106260.693809: filemap_fault: address=0x128122 offset=0xce
346                  trace-cmd-13543 [001] 106260.693809: kmalloc: call_site=81128dd4 ptr=0xffff88003dd83800 bytes_req=768 bytes_alloc=1024 gfp_flags=GFP_KERNEL|GFP_ZERO
347                         ls-13545 [002] 106260.693809: kfree: call_site=810a7abb ptr=0x0
348                         ls-13545 [002] 106260.693818: sys_exit_write:       0x1
349
350       To use the function tracer with sched switch tracing:
351
352            # trace-cmd record -p function -e sched_switch ls > /dev/null
353            # trace-cmd report
354                         ls-13587 [002] 106467.860310: function: hrtick_start_fair <-- pick_next_task_fair
355                         ls-13587 [002] 106467.860313: sched_switch: prev_comm=trace-cmd prev_pid=13587 prev_prio=120 prev_state=R ==> next_comm=trace-cmd next_pid=13583 next_prio=120
356                  trace-cmd-13585 [001] 106467.860314: function: native_set_pte_at <-- __do_fault
357                  trace-cmd-13586 [003] 106467.860314: function:             up_read <-- do_page_fault
358                         ls-13587 [002] 106467.860317: function:             __phys_addr <-- schedule
359                  trace-cmd-13585 [001] 106467.860318: function: _raw_spin_unlock <-- __do_fault
360                         ls-13587 [002] 106467.860320: function: native_load_sp0 <-- __switch_to
361                  trace-cmd-13586 [003] 106467.860322: function: down_read_trylock <-- do_page_fault
362
363       Here is a nice way to find what interrupts have the highest latency:
364
365            # trace-cmd record -p function_graph -e irq_handler_entry  -l do_IRQ sleep 10
366            # trace-cmd report
367                     <idle>-0     [000] 157412.933969: funcgraph_entry:                  |  do_IRQ() {
368                     <idle>-0     [000] 157412.933974: irq_handler_entry:    irq=48 name=eth0
369                     <idle>-0     [000] 157412.934004: funcgraph_exit:       + 36.358 us |  }
370                     <idle>-0     [000] 157413.895004: funcgraph_entry:                  |  do_IRQ() {
371                     <idle>-0     [000] 157413.895011: irq_handler_entry:    irq=48 name=eth0
372                     <idle>-0     [000] 157413.895026: funcgraph_exit:                        + 24.014 us |  }
373                     <idle>-0     [000] 157415.891762: funcgraph_entry:                  |  do_IRQ() {
374                     <idle>-0     [000] 157415.891769: irq_handler_entry:    irq=48 name=eth0
375                     <idle>-0     [000] 157415.891784: funcgraph_exit:       + 22.928 us |  }
376                     <idle>-0     [000] 157415.934869: funcgraph_entry:                  |  do_IRQ() {
377                     <idle>-0     [000] 157415.934874: irq_handler_entry:    irq=48 name=eth0
378                     <idle>-0     [000] 157415.934906: funcgraph_exit:       + 37.512 us |  }
379                     <idle>-0     [000] 157417.888373: funcgraph_entry:                  |  do_IRQ() {
380                     <idle>-0     [000] 157417.888381: irq_handler_entry:    irq=48 name=eth0
381                     <idle>-0     [000] 157417.888398: funcgraph_exit:       + 25.943 us |  }
382
383       An example of the profile:
384
385            # trace-cmd record --profile sleep 1
386            # trace-cmd report --profile --comm sleep
387           task: sleep-21611
388             Event: sched_switch:R (1) Total: 99442 Avg: 99442 Max: 99442 Min:99442
389                <stack> 1 total:99442 min:99442 max:99442 avg=99442
390                  => ftrace_raw_event_sched_switch (0xffffffff8105f812)
391                  => __schedule (0xffffffff8150810a)
392                  => preempt_schedule (0xffffffff8150842e)
393                  => ___preempt_schedule (0xffffffff81273354)
394                  => cpu_stop_queue_work (0xffffffff810b03c5)
395                  => stop_one_cpu (0xffffffff810b063b)
396                  => sched_exec (0xffffffff8106136d)
397                  => do_execve_common.isra.27 (0xffffffff81148c89)
398                  => do_execve (0xffffffff811490b0)
399                  => SyS_execve (0xffffffff811492c4)
400                  => return_to_handler (0xffffffff8150e3c8)
401                  => stub_execve (0xffffffff8150c699)
402             Event: sched_switch:S (1) Total: 1000506680 Avg: 1000506680 Max: 1000506680 Min:1000506680
403                <stack> 1 total:1000506680 min:1000506680 max:1000506680 avg=1000506680
404                  => ftrace_raw_event_sched_switch (0xffffffff8105f812)
405                  => __schedule (0xffffffff8150810a)
406                  => schedule (0xffffffff815084b8)
407                  => do_nanosleep (0xffffffff8150b22c)
408                  => hrtimer_nanosleep (0xffffffff8108d647)
409                  => SyS_nanosleep (0xffffffff8108d72c)
410                  => return_to_handler (0xffffffff8150e3c8)
411                  => tracesys_phase2 (0xffffffff8150c304)
412             Event: sched_wakeup:21611 (1) Total: 30326 Avg: 30326 Max: 30326 Min:30326
413                <stack> 1 total:30326 min:30326 max:30326 avg=30326
414                  => ftrace_raw_event_sched_wakeup_template (0xffffffff8105f653)
415                  => ttwu_do_wakeup (0xffffffff810606eb)
416                  => ttwu_do_activate.constprop.124 (0xffffffff810607c8)
417                  => try_to_wake_up (0xffffffff8106340a)
418

SEE ALSO

420       trace-cmd(1), trace-cmd-report(1), trace-cmd-start(1),
421       trace-cmd-stop(1), trace-cmd-extract(1), trace-cmd-reset(1),
422       trace-cmd-split(1), trace-cmd-list(1), trace-cmd-listen(1),
423       trace-cmd-profile(1)
424

AUTHOR

426       Written by Steven Rostedt, <rostedt@goodmis.org[1]>
427

RESOURCES

429       git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
430

COPYING

432       Copyright (C) 2010 Red Hat, Inc. Free use of this software is granted
433       under the terms of the GNU Public License (GPL).
434

NOTES

436        1. rostedt@goodmis.org
437           mailto:rostedt@goodmis.org
438
439
440
441                                  08/07/2019               TRACE-CMD-RECORD(1)
Impressum