在批处理模式下,将每个输出间隔的输出重新格式化为一行

时间:2016-05-02 05:41:18

标签: unix monitoring perf

我使用perf stat来记录一些硬件计数器,它有一个批处理模式,它在每​​1s(或任何间隔)打印计数器值。我希望在一行中输出一个间隔而不是多行,如下所示:

#           time             counts events
     1.000650887        4015.442880 task-clock (msec)         [100.00%]
     1.000650887                214 context-switches          [100.00%]
     1.000650887                  2 cpu-migrations            [100.00%]
     1.000650887                 14 page-faults
     1.000650887         58,447,833 cycles                    [83.19%]
     1.000650887         50,476,562 stalled-cycles-frontend   [83.26%]
     1.000650887         18,469,093 stalled-cycles-backend    [66.85%]
     1.000650887         13,861,731 instructions              [83.56%]
     1.000650887          3,963,967 branches                  [83.60%]
     1.000650887            180,104 branch-misses             [83.21%]
     2.004854486        4003.706096 task-clock (msec)
     2.004854486                245 context-switches
     2.004854486                  0 cpu-migrations
     2.004854486                 30 page-faults
     2.004854486         60,750,234 cycles                    [83.27%]
     2.004854486         38,491,129 stalled-cycles-frontend   [83.26%]
     2.004854486         20,561,260 stalled-cycles-backend    [66.95%]
     2.004854486         15,651,369 instructions              [83.36%]
     2.004854486          3,826,936 branches                  [83.25%]
     2.004854486            183,319 branch-misses             [83.27%]

这样它就可以保存为csv文件,每个计数器值一个区间作为一行。有一个简单的方法吗?

类似的东西:

task-clock, context-switches, page-faults, cycles, instructions, branches
4105, 214, 14, 58447833, 13861, 3963967
4003, 245, 30, 60750234, 15651369, 3826936

我的性能版本是:3.13.11.10

1 个答案:

答案 0 :(得分:1)

我会将perf stat的输出传递给像

这样的东西
awk '/task-clock/{printf("%d ", $2);} /page-faults/{printf("%d ", $2);} /branch-misses/{printf("%d\n", $2);} '

我没有在这里添加所有字段和标题。增加很明显