Use VTuneAPI in your code to profile without launching VTune(TM) Analyzer

Submit New Article

Last Modified On :   October 15, 2009 3:26 AM PDT
Rate
 


Intel(R) VTune(TM) Performance Analyzer provides VTuneAPI to allow profiling which is controlled by the user. The objective is not to collect unreasonable samples in the portion of user's code (usually the code looks like to call 3rd-party libraries, system functions, etc) when data collecting

Article <<An Introduction to Sampling and Time>> introduced how to use Pause and Resume API at page 8. However it also informed the user that checking "Start with Data Collection Paused" should be set on User Interface at page 9.

Believe me that VTune(TM) Performance Analyzer can not be launched when executing user's code which has VTune API calls, and you can get result file which can be analyzed on VTune(TM) Analyzer later.

How smart it is! How simple it is! You don't need to run VTune(TM) Analyzer to get performance data. Everything is controlled by the user, including Sampling Configure.  

See below example -

// testVTuneAPI.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "VtuneApi.h"

int _tmain(int argc, _TCHAR* argv[])
{
 U32 u32Return;

 VTUNE_EVENT events[] = {
         { 10000, 0, 0, 0, "CPU_CLK_UNHALTED.CORE" },  // Sample After Value, Reserved, Reserved, Return Status, Event Name - my system is Intel(R) Core(TM) 2 Duo
         { 10000, 0, 0, 0, "INST_RETIRED.ANY" },             //  Use "vtl query -c sampling" to know all supported events in the system, in command prompt
     };
 
     U32 numEvents = sizeof(events) / sizeof(VTUNE_EVENT);
     VTUNE_SAMPLING_PARAMS params = {
         sizeof(VTUNE_SAMPLING_PARAMS),
         sizeof(VTUNE_EVENT),
         0, // sampling options
         0, // reserved
         0, // If 1, start sampling in pause mode
         0, // maximum number of samples to be collected. 
         1000, // number of samples per buffer
         40,  // the sampling interval in milliseconds  
         1,  // "1" for event based sampling
         numEvents,  // number of events
         events, // event list array
         "results.tb5", // result file with simple or full path
         0, // reserved
         0, // "1" - generate a count file "tb5Filename.txt"
         "" // CPU mask
     };
 
     u32Return = VTStartSampling(&params); // start sampling since it is not in pause mode
     if (u32Return) {
         printf("Can't start sampling\n");
         exit(0);
     }
     for (int i=0; i<10000000L; i++);  // do some work, data is captured

     VTPauseSampling();  // pause data collection

     for (int i=0; i<10000000L; i++); // do some work, data is NOT captured

     VTResumeSampling(); // resume data collection
     
     for (int i=0; i<10000000L; i++); // do some work, data is captured again 


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


     return 0;
}





This article applies to: Intel® VTune™ Performance Analyzer for Linux* Knowledge Base,   Intel® VTune™ Performance Analyzer for Windows* Knowledge Base