Controlling the Kernel Profiler by Using the Profiler API (Windows CE 5.0)

Send Feedback

To control the kernel profiler, you can call the ProfileStart and ProfileStop functions from an existing application. Alternatively, you can create a standalone application that calls these functions.

To start the kernel profiler by using the profiler API

  • Within an application, call the ProfileStart function at the beginning of each section of code that you want to profile.

To stop the kernel profiler

  • Call the ProfileStop function.

    With the ProfileStart you can set the time slice for each sample and specify a mode for the kernel profiler. For more information about the parameters for the ProfileStart function, see ProfileStart.

    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. Unbuffered mode requires a larger sampling interval than buffered mode because it takes more time to capture each sample. You must provide the OS with enough time to execute between samples. For information about buffered and unbuffered mode, see Buffered and Unbuffered Profiling.

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;
}

See Also

Controlling the Kernel Profiler | Kernel Profiler Modes | ProfileStart | ProfileStartEx | ProfileStop

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.