Posted by: felipe | February 13, 2012

Telemetry Stopwatch

Last week, I added a small module to make it easier to track time deltas measurements that are meant for telemetry. The module is called TelemetryStopwatch and it has two functions, start and finish, which do what their name imply. When you call start it takes a timestamp, and when you call finish it calculates the delta and adds the data to the chosen histogram. It’s useful to avoid sticking start timestamps as enclosed variables or private members in objects, and in cases where the start and stop measurements are disjoint and there’s not a good place to store the stamp or add code to calculate the diff.

// and later

// or, with the optional object parameter:
TelemetryStopwatch.start("MY_TELEMETRY_HISTOGRAM", refObj);
TelemetryStopwatch.finish("MY_TELEMETRY_HISTOGRAM", refObj);

You can have multiple counters at the same time. Each counter is associated with a telemetry histogram, or with a histogram + a reference object, for cases where you might need more than 1 timer running at the same time for the same histogram (e.g. some measurements related to a specific tab, where more than 1 tab might have it running at the same time). The objects are tracked on a WeakMap so you don’t have to worry about leaks. The module is in toolkit to make it widely available.
Happy metering!



  1. Are you the coder of this unfortunate TelemetryStopwatch that causes endless spam messages in the error console which cannot be switched off?

    • Which spam messages are you seeing? I wrote the module, but if error messages are showing up it’s a bug in the usage of that specific telemetry measurement, not the module.

  2. Then this seems to be one of the bugs that never will be fixed in every available new version.

    As far as I see you’d have to get rid of the module completely to make Firefox usable again.

    I would be glad – and I’m not the only one – if you threw light on how to get rid of your code.


%d bloggers like this: