【问题标题】:Perf output cannot be redirected to file性能输出无法重定向到文件
【发布时间】:2013-09-17 13:09:04
【问题描述】:

我正在 Ubuntu (12.0.4 LTS) 上使用 perf(Linux 工具), 我目前正试图将工具的输出重定向到文件。 此问题已在许多帖子中解决,但其中任何一个 提议的解决方案对我不起作用。

我在这里尝试的是:跟踪 pid 的统计信息 并将它们存储在一个文件中。在一个终端上运行 perf 工具,在另一个终端上使用 kill -INT 命令 (sudo kill -INT $pid) 终止 perf 进程。受到网络上不同解决方案的启发(例如how to save ouput of perf (Linux tool) to a file?),我尝试了不同的命令组合,例如:

  1. perf stat -o hhe.txt -e minor-faults,major-faults,cs -p 14615
  2. perf stat --output hhe.txt -e minor-faults,major-faults,cs -p 14615
  3. perf stat --output hhe.txt --append -e minor-faults,major-faults,cs -p 14615
  4. perf stat -e minor-faults,major-faults,cs -p 14615 2> hhe.txt
  5. perf stat -e minor-faults,major-faults,cs -p 14615 0> hhe.txt
  6. perf stat -e minor-faults,major-faults,cs -p 14615 >> hhe.txt

对于所有在 sudo 模式下运行的命令 输出未写入文件。我不确定为什么。也许是因为 kill 命令;但下面的链接说它有效:http://comments.gmane.org/gmane.linux.kernel.perf.user/911

我不确定我做错了什么。任何帮助,将不胜感激。

【问题讨论】:

    标签: linux output perf


    【解决方案1】:
    1. 我也使用 Ubuntu 12.04,这可能取决于您的 perf 版本。

      我的 Perf 版本是 3.2.40。 (您可以通过以下方式查看:

      性能 --version

    2. 由于我的版本高于 3.x,我尝试了以下命令,这对我有用:

      3>results.log perf stat -e Cycles --log-fd 3 ls > ls.txt

      所以根据你的情况,你可以试试:

      3>hhe.txt perf stat -e minor-faults,major-faults,cs -p 14615 --log-fd 3 ls > ls.txt

    同时,我发现这篇文章非常有用:
    perf 使用什么流?
    https://unix.stackexchange.com/questions/89591/what-stream-does-perf-use

    希望这会有所帮助:)

    【讨论】:

      【解决方案2】:

      我只是在命令末尾添加了这两个参数,它为我捕获了 2 个文件中的所有内容。我不确定为什么我们在这里需要 2 个不同的文件,但我无法将所有内容重定向到 1 个文件中。 2> 用于标准错误,1> 用于标准输出。你可以试试这个,看看它是否有效。我能够用这个捕捉到我想要的东西:

      2>temp.out 1>temp1.out
      

      例如,您的命令可能看起来像 -

      perf stat -e minor-faults,major-faults,cs -p 14615 2>temp.out 1>temp1.out
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-30
        • 2011-06-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多