다음을 통해 공유


Controlling the Kernel Profiler by Using the Profiler API (Windows Embedded CE 6.0)

1/5/2010

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.

    ProfileStart enables you to set the time slice for each sample, and to specify a mode for the kernel profiler. For information about parameters, see ProfileStart.

To stop the kernel profiler

  • Call the ProfileStop function.

Example

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

When you run the kernel profiler in buffered mode, you may want to use a sampling interval of approximately 200 microseconds (µs).

See Also

Concepts

Kernel Profiler Modes

Other Resources

Controlling the Kernel Profiler
ProfileStart
ProfileStartEx
ProfileStop