Chapter 29. Adding and removing tracepoints from a running perf collector without stopping or restarting perf
By using the control pipe interface to enable and disable different tracepoints in a running perf
collector, you can dynamically adjust what data you are collecting without having to stop or restart perf
. This ensures you do not lose performance data that would have otherwise been recorded during the stopping or restarting process.
29.1. Adding tracepoints to a running perf collector without stopping or restarting perf
Add tracepoints to a running perf
collector using the control pipe interface to adjust the data you are recording without having to stop perf
and losing performance data.
Prerequisites
-
You have the
perf
user space tool installed as described in Installing perf.
Procedure
Configure the control pipe interface:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow mkfifo control ack perf.pipe
# mkfifo control ack perf.pipe
Run
perf record
with the control file setup and events you are interested in enabling:Copy to Clipboard Copied! Toggle word wrap Toggle overflow perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
# perf record --control=fifo:control,ack -D -1 --no-buffering -e 'sched:*' -o - > perf.pipe
In this example, declaring
'sched:*'
after the-e
option startsperf record
with scheduler events.In a second terminal, start the read side of the control pipe:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow cat perf.pipe | perf --no-pager script -i -
# cat perf.pipe | perf --no-pager script -i -
Starting the read side of the control pipe triggers the following message in the first terminal:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Events disabled
Events disabled
In a third terminal, enable a tracepoint using the control file:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow echo 'enable sched:sched_process_fork' > control
# echo 'enable sched:sched_process_fork' > control
This command triggers
perf
to scan the current event list in the control file for the declared event. If the event is present, the tracepoint is enabled and the following message appears in the first terminal:Copy to Clipboard Copied! Toggle word wrap Toggle overflow event sched:sched_process_fork enabled
event sched:sched_process_fork enabled
Once the tracepoint is enabled, the second terminal displays the output from
perf
detecting the tracepoint:Copy to Clipboard Copied! Toggle word wrap Toggle overflow bash 33349 [034] 149587.674295: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34056
bash 33349 [034] 149587.674295: sched:sched_process_fork: comm=bash pid=33349 child_comm=bash child_pid=34056
29.2. Removing tracepoints from a running perf collector without stopping or restarting perf
Remove tracepoints from a running perf
collector using the control pipe interface to reduce the scope of data you are collecting without having to stop perf
and losing performance data.
Prerequisites
-
You have the
perf
user space tool installed as described in Installing perf. -
You have added tracepoints to a running
perf
collector via the control pipe interface. For more information, see Adding tracepoints to a running perf collector without stopping or restarting perf.
Procedure
Remove the tracepoint:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow echo 'disable sched:sched_process_fork' > control
# echo 'disable sched:sched_process_fork' > control
NoteThis example assumes you have previously loaded scheduler events into the control file and enabled the tracepoint
sched:sched_process_fork
.This command triggers
perf
to scan the current event list in the control file for the declared event. If the event is present, the tracepoint is disabled and the following message appears in the terminal used to configure the control pipe:Copy to Clipboard Copied! Toggle word wrap Toggle overflow event sched:sched_process_fork disabled
event sched:sched_process_fork disabled