Analyzers
Talk to fellow users of Intel Analyzer tools (Intel VTune™ Profiler, Intel Advisor)
5122 Discussions

VTune Pause/Resume API and Multi-Threaded runtime

sqrt
Beginner
951 Views

Hello!

We are currently evaluating VTune (and Thread Profiler) with our multi-threaded VS2008 C++ application.
Right now all we want to do is to get sampled function timings.

Because window context switches impact the result a lot, we have to launch our application with sampling paused and have to resume sampling within our application.
A VTune dll is loaded when we call VTResume(), so everything is apperantly set up right.
However sampling is not resumed in the VTune Performance Analyser (the external application).

Now I found the following in a version 9 release note: "Pause/Resume APIs do not support multithreaded applications."

This is very disappointing because this would render the profiler pretty much useless for us.
Is there any way to work around this?

Thanks for your Infos!

0 Kudos
3 Replies
Peter_W_Intel
Employee
951 Views

Hi,

Based on my experience, you can control start/stop/pause/resume in your code, so you don't need operate corresponding buttons on VTune? Analyzer's GUI, either launching VTune? Analyzer is unnecessary during sampling. (you can use VTune? Analzyer for post-analyzing on the result)

Here is a simple example to useVTuneAPI code:

============================================================================

U32 u32Return;

VTUNE_EVENT events[] = {
{ 10000, 0, 0, 0, "CPU_CLK_UNHALTED.CORE" }, //my system is Core 2 Duo
{ 10000, 0, 0, 0, "INST_RETIRED.ANY" },
};

U32 numEvents = sizeof(events) / sizeof(VTUNE_EVENT);
VTUNE_SAMPLING_PARAMS params = {
sizeof(VTUNE_SAMPLING_PARAMS),
sizeof(VTUNE_EVENT),
0,
0,
0,
0,
1000,
40,
1,
numEvents,
events,
"results.tb5", // save to result file
0,
0,
""
};

u32Return = VTStartSampling(&params);
if (u32Return) {
printf("Can't start samplingn");
exit(0);
}
for (int i=0; i<10000000L; i++);

VTPauseSampling(); //Don't collect data
for (int i=0; i<10000000L; i++);

VTResumeSampling(); //Collect data again
for (int i=0; i<10000000L; i++);


u32Return = VTStopSampling(1); //Stop collecting data and write result into TB5 file, use VTune to import it!
if (u32Return) {
printf("Can't stop samplingn");
exit(0);
}
================================================================

Back to your questions, why can't we support VTuneAPIs on multithreaded applications. The reason is that we can't know which thread will be executed first, which thread will be executed next - if you specify VTStop() in thread B, because you think that thread A will be executed first and you already specified VTStart(). But it is not alwasys true sometime, threads' scheduler is from OS...

You can use VTuneAPIs in some situations for multithreaded applications. For example, you have main thread to create thread A, B and C for task 1, then thread D, E, F for task 2, you could have below scenario:

VTStart() before running thread A, B, C => VTPause() after fork-join for A,B,C =>VTResume() before running thread D,E,F => VTStop() after fork-join for D,E,F

You started VTune sampling in one process, so you can't create other instance in other process - there is only *ONE* Sampling Parameters to be set into the system. I don't think you can control VTuneAPIs in multiple processes.

Hope that I have answered your questions.

Regards, Peter

0 Kudos
schleprock
Beginner
951 Views
is there a better example/explanation of the VTStart/Stop sampling api calls? all that i have seen so far is the example in this thread and the example in the header file. i would really like to take advantage of these calls for gathering information but there is a huge lack of information about these api calls.
0 Kudos
Peter_W_Intel
Employee
951 Views
Quoting - schleprock
is there a better example/explanation of the VTStart/Stop sampling api calls? all that i have seen so far is the example in this thread and the example in the header file. i would really like to take advantage of these calls for gathering information but there is a huge lack of information about these api calls.

The user can refer to online help - VTune Performance Analyzer -> Collecting Data Using APIs

Regards, Peter
0 Kudos
Reply