Kernel Profiler Sample Application (Compact 2013)
3/26/2014
To control the kernel profiler, you can call the ProfileStart and ProfileStop functions from an existing application. The following code sample shows a standalone application that controls the kernel profiler.
#include <windows.h>
#include <profiler.h>
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd)
{
DWORD dwUSecInterval = 200; // Default sampling interval
DWORD dwProfOptions = 0; // Default flags for ProfileStart
PTCHAR p;
// USAGE: profctl [-i <interval>] [-buffer/-kcall/-obj/-stop/-pause/
// -continue/-startpaused]
// EXAMPLE: profctl -i 300 -buffer //Start profiler in Monte Carlo
// mode, buffering data, sampling at 300us interval
// profctl -stop //Stop profiler
if (_tcsstr(lpCmdLine, TEXT("-stop"))) {
ProfileStop();
return 0;
}
if (_tcsstr (lpCmdLine, _T("-pause"))) {
dwProfOptions = PROFILE_PAUSE;
goto startprofiler; // ignore other command-line options
}
if (_tcsstr (lpCmdLine, _T("-continue"))) {
dwProfOptions = PROFILE_CONTINUE;
goto startprofiler; // ignore other command-line options
}
if (p = _tcsstr (lpCmdLine, _T("-i")))
dwUSecInterval = _ttol (p + 3);
if (_tcsstr(lpCmdLine, TEXT("-obj")))
dwProfOptions |= PROFILE_OBJCALL;
if (_tcsstr(lpCmdLine, TEXT("-kcall")))
dwProfOptions |= PROFILE_KCALL;
if (_tcsstr(lpCmdLine, TEXT("-buffer")))
dwProfOptions |= PROFILE_BUFFER;
if (_tcsstr(lpCmdLine, TEXT("-startpaused")))
dwProfOptions |= PROFILE_STARTPAUSED;
startprofiler:
ProfileStart(dwUSecInterval, dwProfOptions);
return 0;
}
Comments
When you run the kernel profiler in buffered mode, you may want to use a sampling interval of approximately 200 microseconds (µs).
When you run the kernel profiler in unbuffered mode you may want to use a larger sampling interval, for example 1000 µs. In unbuffered mode, the kernel profiler looks up symbols while profiling. Because it takes more time to capture each sample, unbuffered mode requires a larger sampling interval than buffered mode. You must provide the OS with enough time to execute between samples.