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? Commented May 27, 2015 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
    Commented May 27, 2015 at 11:49
  • 3
    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... Commented May 27, 2015 at 14:09
  • Thanks, it does exactly what I needed. Hope I could understand the man page better.
    – Angelos
    Commented May 28, 2015 at 2:11


You must log in to answer this question.

Browse other questions tagged .