How to profile locks in g ++ / std :: mutex?

Question

Are there any open source tools, or does anyone have methods / code to profile the degree of std::mutex content in running code?

I would like to calculate the percentage of blocking contention based on the granularity (time or amount) of each instance of std::mutex . If there is an insert tool that does not require transcoding, it will be even better.

I am looking for a technique that will work with std::thread and g ++: when I exit the application, I would like to dump the mutex competition statistics profile into a log file so that I can control the quality of the thread code in real work contexts.

Note

I saw this topic . Unfortunately, the answers either require a ton of money or work on Windows.

+6
source share
1 answer

I recommend something like AMD CodeXL or Intel VTune , CodeXL is free; Intel VTune has a free academic license, if applicable to you, or you can try the 30-day trial. Both of them work in Linux.

At the most basic level, these tools can identify hot spots, for example, by measuring how much time you spend inside the std::mutex methods. Each tool has even more advanced analysis methods / tools that can help you in the future. You do not need to change your code at all, although you may need to verify that you are compiled with debugging symbols and / or have not split the binaries. You probably also want to avoid extreme optimization levels such as -O3 , and stick with -O1 , -O2 or -Og .

PS: Like all optimization requests, I have to remind you that it always measures where your performance problems really are before you start the optimization . No matter how worried you are about a lock conflict, confirm your problems with the profiler before making a huge effort trying to alleviate any conflict you may or may not have.

+4
source

Source: https://habr.com/ru/post/948182/


All Articles