I'm trying to write a script to capture output of perf top

Similar to top, perf top detects the screen size and fill information to the screen. But sadly unlike top which has a batch mode, perf does not. So what I thought would be smart to do is to launch perf top using screen -d -m and get the output by calling -X hardcopy.

Actual command used to launch screen & perf top (Backtick substituted with single quote due to escape character):

screen -S 'cat $session' -d -m perf top

Strange thing happening here is that calling screen -S 'cat $session' -X hardcopy would yield an empty file. But once I have attached and detached from the screen, -X hardcopy would produce the expected output of perf top.

Any idea on how I can capture the output of perf top or working around the issue in screen? Thanks.

  • Could you explain (edit your question) what you're trying to do with the captured output? Do perf record and perf report not give you the information you're after? – Stephen Kitt May 27 '15 at 11:43
  • If I'm not mistaken, perf record only record metrics of a certain command? I'd like to capture perf top when system performance (measured using other scripts) meets some certain condition. – Angelos May 27 '15 at 11:49
  • 2
    You can capture all the activity in a system with -a; for example perf record -a sleep 5 records all the activity for five seconds. We're monitoring sleep 5 but with everything else as well... – Stephen Kitt May 27 '15 at 14:09
  • Thanks, it does exactly what I needed. Hope I could understand the man page better. – Angelos May 28 '15 at 2:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.