我知道perf可以使用perf stat -p tid/pid
或perf top -p tid/pid
描述单个进度或单个线程。
但是我想分析进度中的每个线程,并比较事件,获取哪个线程消耗高,然后对其进行优化。可以这样做吗?如果没有,哪些工具可以做到?
谢谢。
最佳答案
有人建议在补丁中添加--per-thread选项到perf stat
(在间隔模式为-I 1000
的情况下,每个线程每秒都可以看到当前计数器):https://lwn.net/Articles/649001/“ perf stat:Introduce --per-线程选项”来自: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
性能/性能
关于performance - Linux性能可以比较每个线程的性能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24649251/