Linux上的线程利用率分析 [英] Thread Utilization profiling on linux

查看:119
本文介绍了Linux上的线程利用率分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Linux性能工具非常适合在CPU周期中查找热点并优化这些热点.但是一旦将某些部分并行化,就很难发现顺序的部分,因为它们占用了大量的时间,但并不一定要占用很多CPU周期(并行的部分已经在燃烧这些部分了).

Linux perf-tools are great for finding hotspots in CPU cycles and optimizing those hotspots. But once some parts are parallelized it becomes difficult to spot the sequential parts since they take up significant wall time but not necessarily many CPU cycles (the parallel parts are already burning those).

为避免XY问题:我的基本动机是在多线程代码中查找顺序瓶颈.尽管由于 amdahl的缘故,但是并行阶段可以轻松地控制总体CPU周期统计信息法律.

To avoid the XY-problem: My underlying motivation is to find sequential bottlenecks in multi-threaded code. The parallel phases can easily dominate the aggregate CPU-cycle statistics even though the sequential phases dominate wall time due to amdahl's law.

对于Java应用程序来说,使用带有线程使用时间表的visualvm或yourkit相当容易实现.

For java applications this is fairly easy to achieve with visualvm or yourkit which have a thread-utilization timelines.

请注意,它同时显示了选定状态或时间点的线程状态(可运行,正在等待,已阻止)和堆栈样本.

Note that it shows both thread state (runnable, waiting, blocked) and stack samples for selected ranges or points in time.

如何在Linux上实现与Perf或其他本机探查器相当的功能?不必是GUI可视化,而只是查找顺序瓶颈和与之相关联的CPU示例的一种方法.

How do I achieve something comparable with perf or other native profilers on linux? It doesn't have to be a GUI visualization, just a way to find sequential bottlenecks and CPU samples associated with them.

推荐答案

Oracle的Developer Studio性能分析器可能会完全满足您的需求. (如果您在Solaris上运行,我知道它会将完全按照您的要求进行操作,但是我从未在Linux上使用过它,并且现在无法访问Linux系统适合尝试).

Oracle's Developer Studio Performance Analyzer might do exactly what you're looking for. (Were you running on Solaris, I know it would do exactly what you're looking for, but I've never used it on Linux, and I don't have access right now to a Linux system suitable to try it on).

这是在x86 Solaris 11系统上运行的多线程IO测试程序的屏幕截图:

This is a screenshot of a multithreaded IO test program, running on an x86 Solaris 11 system:

请注意,您可以看到每个线程的调用堆栈以及确切的线程交互方式-在发布的示例中,您可以看到实际执行IO的线程的起始位置,并且每个线程都可以看到他们表演.

Note that you can see the call stack of every thread along with seeing exactly how the threads interact - in the posted example, you can see where the threads that actually perform the IO start, and you can see each of the threads as they perform.

此视图准确显示线程2在突出显示的时刻的位置:

This is a view that shows exactly where thread 2 is at the highlighted moment:

此视图已启用同步事件视图,该视图显示线程2在突出显示的时间段内停留在sem_wait调用中.请注意图形数据的其他行,其中显示了同步事件(sem_wait()pthread_cond_wait()pthread_mutex_lock()等):

This view has synchronization event view enabled, showing that thread 2 is stuck in a sem_wait call for the highlighted period. Note the additional rows of graphical data, showing the synchronization events (sem_wait(), pthread_cond_wait(), pthread_mutex_lock() etc):

其他视图包括呼叫树:

线程概述(仅对少数几个线程不是很有用,但是如果您有数百个或更多线程,则可能非常有用

a thread overview (not very useful with only a handful of threads, but likely very useful if you have hundreds or more

和显示功能CPU利用率的视图

and a view showing function CPU utilization

您会看到在每一行代码上花费了多少时间:

And you can see how much time is spent on each line of code:

不足为奇的是,一个写大型文件以测试IO性能的过程几乎全部时间都花在了write()函数中.

Unsurprisingly, a process that's writing a large file to test IO performance spent almost all its time in the write() function.

有关Oracle的完整摘要,请参见

The full Oracle brief is at https://www.oracle.com/technetwork/server-storage/solarisstudio/documentation/o11-151-perf-analyzer-brief-1405338.pdf

快速用法概述:

  • collect performance data using the collect utility. See https://docs.oracle.com/cd/E77782_01/html/E77798/afadm.html#scrolltoc
  • Start the analyzer GUI to analyze the data collected above.

这篇关于Linux上的线程利用率分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆