I am running two programs where one’s stdout is piped into the other’s stdin. I did this using named pipes in the following way (simplified for presentation):
$ mkfifo feedback
$ ./program1 < feedback | ./program2 > feedback
I have noticed some performance problems in program number 1, so I tried running it under perf-record
, like so:
$ perf record -g ./program1 < feedback | ./program2 > feedback
But then program number 2 failed claiming invalid input. Here is a hexdump:
$ perf record -g ./program1 < feedback | tee p1_to_p2 | ./program2 > feedback
$ hexdump -C p1_to_p2
00000000 50 45 52 46 49 4c 45 32 10 00 00 00 00 00 00 00 |PERFILE2........|
00000010
From a quick google search, I found that PERFILE2
is the magic number for perf data files, so it looks like perf sends its data out through stdout
when used in a pipe.
I would like to avoid this behavior and just have perf output a file like normal, but found nothing relevant in perf’s manual.
How can I force perf to output to a file?
2
Use perf-record
‘s -o
or --output
flag. From man perf-record
:
-o, --output=
Output file name.
Then we can write
$ perf record -o perf.data -g ./program1 < feedback | ./program2 > feedback
And perf
will write its output data to the specified file even if it is being used in a pipe.