Implement perf stat --control for cgi#22537
Open
iluuu1994 wants to merge 4 commits into
Open
Conversation
perf stat --control allows the profiled process to enable and disable counters
at runtime. This allows us to skip profiling startup and shutdown for more
accurate results. The same already exists for valgrind.
$ perf stat -D -1 --control fifo:/tmp/perfctl,/tmp/perfack
-D -1 starts perf stat with counters disabled. --control makes perf stat connect
to the /tmp/perfctl and /tmp/perfack fifo files. These need to exist when
starting perf, so create them using mkfifo /tmp/perf{ctl,ack}. The ctl fifo is
written to by cgi to enable/disable counters, whereas the ack fifo is written to
by perf stat to acknolwedge counters have been installed.
Additionally, you'll need to set the set the PERF_STAT_CTL_FIFO and
PERF_STAT_ACK_FIFO env variables for cgi to find the fifo files.
arnaud-lb
approved these changes
Jul 1, 2026
arnaud-lb
left a comment
Member
There was a problem hiding this comment.
Looks good to me otherwise!
Comment on lines
+65
to
+70
| if (ctl_fd == -2) { | ||
| ctl_fd = zps_open_fifo(ZPS_CTL_FIFO_ENV, O_WRONLY); | ||
| } | ||
| if (ack_fd == -2) { | ||
| ack_fd = zps_open_fifo(ZPS_ACK_FIFO_ENV, O_RDONLY); | ||
| } |
Member
There was a problem hiding this comment.
For ease of debugging we should print an error message and exit when these functions fail while the env vars are set
Comment on lines
+93
to
+97
| for (ssize_t i = 0; i < bytes_read; i++) { | ||
| if (ack[i] == '\n') { | ||
| return; | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
We can likely omit this loop and just check that we have read strlen("ack\n") in total
Member
Author
There was a problem hiding this comment.
Switched the loop to just drain the pipe, that avoids potential synchronization issues.
Just drain the pipe.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
perf stat --controlallows the profiled process to enable and disable counters at runtime. This allows us to skip profiling startup and shutdown for more accurate results. The same already exists for valgrind.-D -1startsperf statwith counters disabled.--controlmakesperf statconnect to the/tmp/perfctland/tmp/perfackfifo files. These need to exist when starting perf, so create them usingmkfifo /tmp/perf{ctl,ack}. The ctl fifo is written to by cgi to enable/disable counters, whereas the ack fifo is written to byperf statto acknolwedge counters have been installed.Additionally, you'll need to set the set the
PERF_STAT_CTL_FIFOandPERF_STAT_ACK_FIFOenv variables for cgi to find the fifo files.Split off from iluuu1994#218.