Monday, 9 February 2009

Windows CE: Kernel Profiler Considerations

Hi all,

The kernel profiler under Windows CE is a very useful tool to measure your systems performance. It is implemented in the OAL (think of it as the driver for the kernel) and basically works as follows:

  • OEMProfileTimerEnable(DWORD dwUSec) programs an interrupt to occur at a specified interval (default 200us)

  • OEMProfileTimerDisable(void) disables the profiler timer interrupt

  • Record the interrupt using ProfilerHit() in the appropriate timer ISR

All MS supplied BSPs have the appropriate implementation already included but some 3rd party BSPs unfortunately do not. There is however a very easy, yet not very sophisticated way to implement the kernel profiler. Sue Loh’s articele “Poor Man’s Monte Carlo” describes the necessary steps explicitly. This method is a great way if you do not have a free timer on your HW and hence you have to instrument the system tick for the purpose of kernel profiling. Now all you need to do to enable profiling is to set the IMGPROFILER environment variable which can be found in your project properties and make a run-time image. Now you are set to go. One thing to keep in mind is, that you should not try to draw any conclusions from a short run of the kernel profiler.

There are three kernel profiler modes in Windows CE:

  • Monte Carlo Profiling which periodically samples the CPU program counter

  • System Call Profiling which counts calls made to the API

  • Instrumented Kernel Profiling which tracks the amount of time the kernel requires executing kernel-internal calls

Now let’s talk about how to control the kernel profiler. There are three ways to do so:
  • Via the Target Control (CE Shell) which can be started from the PlatformBuilder IDE. Here a KITL connection is needed. The command looks as follows: prof on off [DataType ][ StorageType][OtherOptions]. The output will be displayed in PlatformBuilder’s Output window after you stop profiling.

  • Stand aloe on the device via the ProfileStart and ProfileStop API. There is some sample code in the MSDN help: “Controlling the Kernel Profiler by Using the Profiler API”. In this case the output will be displayed in a terminal program using the debug UART connection.

  • Also the target devices keyboard or command prompt can be used to control the kernel profiler. The command prompt works just like the Target Control with the prof on off [DataType ][ StorageType][OtherOptions] command whereas there are special key mappings for keyboard usage.

Although most of this information is available in the MSDN help, a lot of people have asked me about it, so I hope this is a helpful summary of the kernel profiler under Windows CE.

Have fun!

No comments: