简体   繁体   中英

How can I debug what portion of a multi-threaded C++ program is taking excessive time?

I have a situation where I am working with a multithreaded C++ program in CentOS (Linux) and am trying to figure out which portion of the program is the "CPU resource hog". I have already identified the offending thread using the "top" command from the console. Now my question is, how can I find out what part of the code within that thread is hogging the CPU? Can you recommend any debugging tools / methods that would aid in this task? If it could tell me the line(s) that are being executed the most within the program, that should be helpful.

I would like to see if I can perform optimization on the offending code, and / or see if something is not happening correctly. The process itself appears to work correctly except for the fact that it slows down and hogs the CPU more than I would think it should.

I have looked into valgrind's tools a bit, and have not been able to produce anything helpful yet (although valgrind has a lot of tools). I tried the helgrind tool so far, and have looked at http://valgrind.org/docs/manual/manual.html for further guidance. It appears the callgrind tool may be useful if I can figure out how to use it. If anyone can tell me procedurally how to do debug what portions of code are being "over utilized" with valgrind, or point me to a good resource, it would be greatly appreciated.

使用探查器另外,您可以编写自己的时序代码,但这会带来不准确和错误的效率。

There are a variety of tools that give you this information and more -- sometimes too much information. If you are working in an IA (Intel Architecture) environment, you have VTune, the Intel compiler provides a whole host of analysis tools with a variety of instrumentation overheads, and there are a lot of free and experimental tools at https://software.intel.com/en-us/whatif/ . If you are on a non-IA architecture, there are a variety of compiler and other analysis tools available much better than top. There are also the various prof tools.

The IA tools from Intel can be pricey but there are various student and other discounted licenses.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM