Tuesday, September 3, 2013

Telemetry 2: User Defined Timers

Introduced as part of Telemetry 2.0c, user specified timers are a handy way to override Telemetry's internal timing code with your own.  This is an advanced feature and not something most customers will need, but in certain rare cases it can be helpful.  For example:
  • embedded systems with their own custom high performance timers
  • scripting systems that use their own timing mechanisms
The usage is extremely simple.  You register a timing function by calling a new API, tmStartupEx, and providing your user defined timing function.  The caveats are that:
  1. It must be thread safe
  2. It must be fast
  3. It must return a 64-bit, monotonically increasing value
  4. It must have at least microsecond accuracy
  5. It must be synchronized across processors
Anything less than microsecond accuracy can play havoc with the Telemetry back end, and tmStartupEx will error out if it detects a low resolution timer.

The final thing to watch out for is if you use accumulation zones.  The accumulation APIs are just macros that wrap calls around Telemetry's default timer function, which means that they are incompatible with a user defined one.  To get around this you'll need to write your own accumulation zone enter/leave/get start macros (just use the existing ones as templates), e.g.:

#define myGetAccumulationStart(cx) ((cx) ? myFastTime() : 0)
#define myEnterAccumulationZone(cx,z) { if (cx) (z) -= myFastTime(); }
#define myLeaveAccumulationZone(cx,z) { if (cx) (z) += myFastTime(); }

If you need any assistance with this feature, please don't hesitate to contact us!

No comments:

Post a Comment