可视化多线程 C++ 的工具应用程序调用图、多线程代码覆盖率?
我想知道是否有工具可以
- 帮助可视化大型多线程应用程序的调用图。
- 具体来说,我想看看多个线程如何在一个核心上交错/在多个核心上同时执行。
- 该工具理想地可以识别可能的等待/死锁/竞争条件。
最终,我想根据运行时线程之间的交互方式进行代码覆盖(多线程代码覆盖工具),以便发现潜在的多线程错误。
如果我没有清楚地解释我的问题,我很抱歉,我很乐意提供任何细节。
I would like to know if there are tools that can
- Help visualize call graph of a large multi-threaded application.
- Specifically I want to see how multiple threads interleaves on one core / executes simultaneously on multiple cores.
- The tool would ideally identify possible wait/deadlock/race conditions.
Ultimately I want to do code coverage in terms of how threads interacts with each other during runtime (multi-thread-wise code coverage tool) so as to find potential multi-threaded bugs.
I apologize if I haven't explained my question clearly and I would love to provide any details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
英特尔的 VTune Profiler 可以执行以下操作:你问。来自 VTune 站点:
锁定和等待:使用英特尔® 性能分析工具快速查找并行程序中性能缓慢的常见原因:锁定等待时间过长,而等待期间内核未得到充分利用。
时间轴可视化线程行为:查看线程何时运行和等待,以及何时发生转换。
如果您正在寻找开源/免费的东西,那么 Valgrind 有一个名为 Helgrind 的实验工具据说可以在多线程程序中找到竞争。我没用过,无法评论。
我应该指出,我还没有成功地利用这些或其他分析器进行多线程调试和优化,相反,我开发了自己的技术。
为了识别锁争用,我的首选技术是使用扩展的 Mutex 类来记录在每个实例上完成的所有操作。我以非常轻量级的方式执行此操作,以便应用程序性能不会发生很大变化。
为了确定竞争条件,我发现蛮力方法是最好的。我只是设计一个可以运行很长一段时间的测试,有时需要几个小时或几天,具体取决于情况。我总是在至少两个不同的平台上运行测试(如果可以的话更多),因为不同的操作系统使用不同的调度程序,这可以提供更好的覆盖范围。
The VTune Profiler from Intel can do some of what you ask. From the VTune site:
Locks and Waits: Use the Intel® performance profiling tools to quickly find a common cause of slow performance in parallel programs: waiting too long on a lock while the cores are underutilized during the wait.
Timeline Visualizes Thread Behavior: See when threads are running and waiting, and when transitions occur.
If you were looking for something that is open source/free, then Valgrind has an experimental tool called Helgrind that supposedly finds races in multi-threaded programs. I can't comment on it, I haven't used it.
I should note that I haven't been successful in utilizing these or other profilers for multi-threaded debugging and optimizations, and instead I have developed my own techniques.
For identifying lock contention my preferred technique is to use an extended Mutex class that records all the operations done on each instance. I do this in a very lightweight way, so that the application performance doesn't change in a big way.
To identify race conditions I find the brute force approach the best. I just design a test that can be run for an extended period of time, some times this is hours, or days, depending on the case. And I always run my test on at least two different platforms (more if I can), since different OSes use different schedulers and that gives you better coverage.
虽然我(还!)无法解决您的大多数问题,但我认为我们的 C++ 测试覆盖率工具可以非常轻松地为您提供多线程测试覆盖率数据。
该工具可以检测您的源代码;你编译并运行它。你最终得到(便宜)
代码中代表各种块的仪器探针。仪器仪表
记录程序的哪些部分执行,名义上作为带有 1 的位向量
每个仪器探头位。在执行结束时(或任何你喜欢的时候),这
位向量被转储出来,查看器会将其叠加在代码上显示给您。
获得多线程测试覆盖率的技巧是知道我们为您提供了完整的
控制定义仪器探头的工作方式;它们是宏。所以而不是
的默认宏
使用本质上在布尔数组上
,您可以在 int 数组上实现(或者通过预先计算该值来巧妙地更便宜)。
这可能只需要几行代码即可实现。
人们可能会注意到这在技术上存在同步问题。
确实如此,但顶多损失一点
的覆盖率数据,并且反对它的可能性相当高。大多数人
对“相当不错”的数据感到满意,而不是完美。如果你坚持
在完美的情况下,您将付出高昂的同步代价使用一些
原子更新指令。
我们还为您提供对探针转储逻辑的控制;你可以修改它写出
特定于线程的覆盖数据(在数十行自定义代码范围内)。
然后,测试覆盖率数据查看器将让您查看特定于线程的覆盖率
(只需选择正确的覆盖向量);它还具有内置设施
轻松计算/显示交集/并集/差异
在覆盖向量上,它准确地给出了每个线程覆盖率的关系。
While I can't help (yet!) on most of your issues, I think our C++ Test Coverage tool could provide you with multithreaded test coverage data pretty easily.
This tool instruments your source code; you compile and run that. You end up with (cheap)
instrumentation probes in your code representing various blocks. The instrumentation
records which parts of your program execute, nominally as a bit vector with one
bit per instrumentation probe. At the end of execution (or whenever you like), this
bit vector is dumped out and a viewer will show it to you superimposed on the code.
The trick to getting multihread test coverage is to know that we provide you complete
control over defining how the instrument probes work; they are macros. So rather than
using the default macro of essentially
on a boolean array, you can instead implement
on an int array (or something cleverly cheaper by precomputing this value).
This likely takes only a few lines of code to implement.
Folks might note this technically has synchronization troubles.
That's true, but at most it loses a bit
of coverage data, and the odds against it are pretty high. Most people
are happy with "pretty good" data rather than perfect. If you insist
on perfection, you'll pay a high synchonization price using some
atomic update instruction.
We also provide you control over the probe dumping logic; you can revise it to write out
thread-specific coverage data (in the tens of lines of custom code range).
The test coverage data viewer will then let you see thread-specific coverage
(just choose the right coverage vector); it also has built-in facility for
easily computing/displaying intersection/union/diff
on coverage vectors, which gives you exactly your relation of coverage-per-thread.
Concurrency Visualizer(Visual Studio 的免费插件)是非常好的并行线程可视化工具。包括可视化互斥锁、抢占和调用堆栈。 https://msdn.microsoft.com/en-us/library/dd537632。 ASPX
Concurrency Visualizer (a free add on to visual studio) is really nice visualizer of parallel threads. Including visualizing mutex locks, preemption and callstacks. https://msdn.microsoft.com/en-us/library/dd537632.aspx