Symbian
Symbian OS Library

FAQ-1302 What are the best timers to use for profiling program behaviour?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Base
Created: 08/25/2005 Modified: 09/27/2005
Number: FAQ-1302
Platform: Symbian OS v6.1, Symbian OS v7.0, Symbian OS v7.0s, Symbian OS v8.0, Symbian OS v8.0a, Symbian OS v8.0b, Symbian OS v8.1a, Symbian OS v8.1b, Symbian OS v9

Question:
What are the best timers to use for profiling program behaviour?
How accurate are these timers?
Why am I getting zero time between my function calls?


Answer:
What are the best timers to use for profiling application behaviour?

TTime::HomeTime() or TTime::UniversalTime().

Differencing these values can be used where timezone and daylight savings time changes are relevant, and when fine resolution is not required. Note that these use the system time (Kern::SystemTime()) which can be changed by other processes.

On EKA2 the resolution is the same as the low level system timer (nanokernel timer), which is usually in the micro second range. You can find out the nanokernel tick period by calling: HAL::Get(HAL::ENanoTickPeriod, result);

User::FastCounter()

Gets the highest possible resolution of a Symbian OS timer. This has two advantages over TTime::HomeTime():

  • It's a lot faster - a fast exec call reading a single hardware register rather than a slow exec call doing calculations.
  • It usually has better resolution. You can get the frequency of the hardware counter used by calling:
    HAL::Get(HALData::EFastCounterFrequency, result);
    (you will need to
    #include and link with HAL.LIB - in the MMP file)

Note that if this timer is updated to the correct value when the kernel comes out of standby

User::NTickCount() / NKern::TickCount()
You can also use the nano kernel tick count directly:

  • From user side, use: User::NTickCount() and HAL::Get(HAL::ENanoTickPeriod, tickPeriod)
  • From kernel side, use: NKern::TickCount() and NKern::TickPeriod()
The nano kernel tick count does not lose time when going into standby (unless the base-port is broken.). This contrasts with some other timing services (e.g. User::After(), Tickcount, CPeriodic etc.) that appear to "lose" time when the phone is in standby (their tick counter is frozen).

Hardware timer

Semiconductor board vendors can also use a dedicated hardware timer for the purpose of kernel-side profiling. This allows the the best possible timer resolution for the specific hardware, but is obviously not part of the "Symbian OS" offering.

How accurate are these timers?
Each of the timers will have a nominal resolution based on the underlying tick timer. Note however that the real accuracy of the timers is dependent on a number of other factors, including the base port implementation, what calculation needs to be done, whether its implemented as a slow or fast exec call etc.

Why am I getting zero time between my function calls?
This is caused if a timer doesn't get incremented between two calls to a 'get-time/count' function.

This could either be because you are calling it faster than the resolution of the timer, or if the code managing the timer doesn't get to run.
E.g. with Kern::TickCount, you will get the same value with two calls if either:
a) you call it withing the same milli second
b) interrupts are disabled
c) threads are running with a higher priority than the timer thread
d) you have turned off preemption
e) you've got code (a DFC callback) executing in the timer thread which blocks.