Reputation: 31
I am working with perf (a Linux tool) on Ubuntu (12.0.4 LTS), and I am at the moment stuck trying to redirect the output of the tool to a file. This issue has been addressed in many posts but any of the proposed solutions did nto work for me.
What I am trying here is: trace stats of a pid
and store them in a file. In one terminal I run the perf tool and on another I kill the perf process using kill -INT command (sudo kill -INT $pid
). Inspired by different solutions on the web (e.g. how to save ouput of perf (Linux tool) to a file?) I have tried different combinations of commands, such as:
perf stat -o hhe.txt -e minor-faults,major-faults,cs -p 14615
perf stat --output hhe.txt -e minor-faults,major-faults,cs -p 14615
perf stat --output hhe.txt --append -e minor-faults,major-faults,cs -p 14615
perf stat -e minor-faults,major-faults,cs -p 14615 2> hhe.txt
perf stat -e minor-faults,major-faults,cs -p 14615 0> hhe.txt
perf stat -e minor-faults,major-faults,cs -p 14615 >> hhe.txt
For all these commands which are run in sudo mode the output is not written to the file. I am not sure why. Maybe because of the kill command; but the following link says it works: http://comments.gmane.org/gmane.linux.kernel.perf.user/911
I am not sure what I am doing wrong. Any help would be appreciated.
Upvotes: 3
Views: 8259
Reputation: 1462
I just added these two parameters at the end of command it captured everything for me in 2 files. I am not sure why we need 2 different files here but I was not able to redirect everything into 1 file. 2> is for stderr and 1> is for stdout. You can try this and see if it works. I was able to capture what I wanted to with this:
2>temp.out 1>temp1.out
For example, your command may look like -
perf stat -e minor-faults,major-faults,cs -p 14615 2>temp.out 1>temp1.out
Upvotes: 2
Reputation: 31
I also use Ubuntu 12.04, it may depends on your version of perf.
The Perf verision of mine is 3.2.40. (You can check it by:
perf --version
Since mine is above version 3.x, I have tried following commands, which works for me:
3>results.log perf stat -e cycles --log-fd 3 ls > ls.txt
So according to your case, you could try:
3>hhe.txt perf stat -e minor-faults,major-faults,cs -p 14615 --log-fd 3 ls > ls.txt
Meanwhile, I found this post very useful:
What stream does perf use?
https://unix.stackexchange.com/questions/89591/what-stream-does-perf-use
Hope this helps : )
Upvotes: 3