What stream does the perf
command use!? I've been trying to capture it with
(perf stat -x, -ecache-misses ./a.out>/dev/null) 2> results
following https://stackoverflow.com/q/13232889/50305, but to no avail. Why can I not capture the input… it's like letting some fish get away!!
Best Answer
Older versions of perf ~2.6.x
I'm using perf version: 2.6.35.14-106.
Capture all the output
I don't have the
-x
switch on my Fedora 14 system so I'm not sure if that's your actual problem or not. I'll investigate on a newer Ubuntu 12.10 system later on but this worked for me:I only want perf's output
You could try this, the output from
ls
will get redirected to/dev/null
. The output formperf
(both STDERR and STDOUT) goes to the file,stat.log
.Newer versions of perf 3.x+
I'm using perf version: 3.5.7
Capturing only perf's output
With the newer versions of
perf
there are dedicated options for controlling where messages get sent. You have the choice of either sending them to a file via the-o|--output
option. Simply give either of those switches a filename to capture the output.The alternative is to redirect the output to a alternate file descriptor,
3
, for example. All you need to do is direct this alternate file handle prior to streaming to it.So if we wanted to collect the
perf
output for thels
command you could use this command:If you use the
--append
version then the contents of multiple commands will be appended to the same log file,results.log
in our case.Installing perf
Installation is pretty trivial:
Fedora
Ubuntu/Debian
References