【问题标题】:Can Linux perf compare per - thread performance?Linux perf 可以比较每个线程的性能吗?
【发布时间】:2014-08-30 05:13:08
【问题描述】:

我知道 perf 可以分析单个进度或单个线程使用 perf stat -p tid/pidperf top -p tid/pid

但我想分析每个线程的进度,并比较事件,得到哪个线程是高消耗的,然后对其进行优化。 perf 可以做到这一点吗?如果没有,哪些工具可以做到这一点?

谢谢。

【问题讨论】:

  • 您的问题是 Python 特有的吗?

标签: performance perf


【解决方案1】:

有人建议将 --per-thread 选项添加到 perf stat (并且使用间隔模式 -I 1000 可以每秒查看每个线程的当前计数器):https://lwn.net/Articles/649001/ "perf stat: Introduce - -per-thread 选项”来自:Jiri Olsa,日期:2015 年 6 月 23 日,星期二

增加了显示每个线程的统计数据的可能性。

允许以下命令和输出:

$ perf stat -e 循环,指令 --per-thread -p 30190,30242 ^C 进程 ID '30190,30242' 的性能计数器统计信息:

           cat-30190                     0      cycles
           yes-30242         3,842,525,421      cycles
           cat-30190                     0      instructions
           yes-30242        10,370,817,010      instructions

     1.143155657 seconds time elapsed

也可以在间隔模式下工作:

$ perf stat -e 循环,指令 --per-thread -p 30190,30242 -I 1000

#           time             comm-pid                  counts   unit events
   1.000073435              cat-30190                89,058      cycles
   1.000073435              yes-30242         3,360,786,902      cycles                     (100.00%)
   1.000073435              cat-30190                14,066      instructions
   1.000073435              yes-30242         9,069,937,462      instructions
   2.000204830              cat-30190                     0      cycles
   2.000204830              yes-30242         3,351,667,626      cycles
   2.000204830              cat-30190                     0      instructions
   2.000204830              yes-30242         9,045,796,885      instructions   
  ^C
   2.771286639              cat-30190                     0      cycles
   2.771286639              yes-30242         2,593,884,166      cycles
   2.771286639              cat-30190                     0      instructions
   2.771286639              yes-30242         7,001,171,191      instructions

可在此处获得:
git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
perf/per_thread

【讨论】:

  • 如果 pid/tid 未知怎么办?在像perf stat -e <events> ./myApp 这样调用应用程序的场景中
【解决方案2】:

是的。当然。

您可以使用perf_event_open() 系统调用来打开性能计数器。 然后使用proctl/ioctl 读取计数器。

您可以查看 linux 手册页了解所有详细信息。

【讨论】:

    【解决方案3】:

    你看到这个问题了吗?

    How to profile multi-threaded C++ application on Linux?

    我认为你可以从 valgrind 开始:

    http://valgrind.org/docs/manual/cl-manual.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      相关资源
      最近更新 更多