Support for Analyzers (Intel VTune™ Profiler, Intel Advisor, Intel Inspector)
4642 Discussions

Intel Thread Profiler: naming critical sections?


I want to use Intel Thread Profiler for debugging my multi-threaded C++ Win32 coding.
Just started with a small example where two threads sum up numbers from 1 to 1000 in a common variable.
Both threads access this common variable via mutex, using CreateMutex(), WaitForSingleObject() and ReleaseMutex().
As it's possible to assign a name to a mutex (e.g. "Mutex") I'm able to see the name in the Timeline and Profile view of the Intel Thread Profiler (which can give valuable debug info for more complex coding).

If I use critical sections instead of mutex via InitializeCriticalSection(), EnterCriticalSection() etc. I can't assign a name to the critical section and therefore do not see any information in the Thread Profiler. In the Timeline and Profile view I just see "Critical Section" with some arbitrary number - which is not much help for debugging more complex coding.

My question:
Is there any possibility to name critical section so that I can debug my application easier? Or is there any other possibilty to achieve this goal?

Thank you very much!

0 Kudos
3 Replies
Black Belt
OpenMP supports named critical sections, so it's clearly possible. Unfortunately, the way this is done is hidden, beyond the extent to which you can see it when you generate asm code. As your example, according to your description, is a standard OpenMP task (not requiring explicit mutex or critical section), you might compare the profiles of hand and OpenMP threaded versions, as well as the profile generated by the openmp_profile library.
Here are two things you can try:
1. In Profile view, switch to grouping by 'Object'. Hover the mouse over the bar label and you should get a tooltip which gives the creation location for the critical section. Or bring up the context menu and there should be an item "Creation/Entry Source View". Select that to see the source stack where the critical section was created. These should help correlate the critical section name with the code.

2. Use the itt_event API to add events (which have names) near the critical section API's. You will get tick marks in timeline view showing where these events occur. See the help topic "API Support -> User Event API" for more information.

Hope these help.
Critical sections in OpenMP don't necessarily map down to critical section API's in the OS (and in fact probably don't in most implementations)