perf之timechart(系统性能图形化分析工具)
2017-11-06 10:07
1031 查看
perf record可以统计系统在一段时间内,进程的性能表现,但是其结果不适合直接阅读,有很多图形化工具可以把其结果转换成图形界面的方式,而perf自带了timechart分析工具,当然它只记录了进程粒度上的表现,还是替代不了火焰图这种可以在函数级别上进行分析的工具,最好可以配合使用。下面我们通过一个栗子来看看:
先写一个消耗cpu的进程
#include <iostream> #include <thread> #include <unistd.h> void test() { int i = 0; while(i < 5000000000) i++; } int main() { std::thread *th[12]; for(int i = 0; i < 12; i++) { th[i] = new std::thread(test); } for(int i = 0; i < 12; i++) { th[i]->join(); delete th[i]; } return 0; }
度量结果
./thread 新的终端下运行: sudo perf timechart record 几秒后ctl+c中断 sudo perf timechart 结果输出在output.svg下面
修改为8线程
分析
通过上图我们可以看到进程在CPU上面的调度结果,通过将线程数量修改为当前CPU数量,我们还会看见CPU密集型的程序,并不是线程数开的越多越好(12线程的在CPU上明显空隙挺多),因为进程调度需要切换上下文,切换上下文本身也是一件需要消耗资源的事情。相关文章推荐
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具perf的介绍与使用[转]
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf详解讲解
- 系统级性能分析工具 — Perf
- 系统级CPU性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf
- 系统级性能分析工具 — Perf