2012-01-11 04:19:06 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.EXPORTED_SYMBOLS = ["TelemetryTimestamps"];
|
2012-01-11 04:19:06 +04:00
|
|
|
|
2014-02-26 18:29:34 +04:00
|
|
|
const Cu = Components.utils;
|
|
|
|
|
2012-02-01 21:41:55 +04:00
|
|
|
/**
|
|
|
|
* This module's purpose is to collect timestamps for important
|
|
|
|
* application-specific events.
|
|
|
|
*
|
2015-04-27 19:07:58 +03:00
|
|
|
* The TelemetryController component attaches the timestamps stored by this module to
|
2012-02-01 21:41:55 +04:00
|
|
|
* the telemetry submission, substracting the process lifetime so that the times
|
|
|
|
* are relative to process startup. The overall goal is to produce a basic
|
|
|
|
* timeline of the startup process.
|
|
|
|
*/
|
2015-09-15 21:19:45 +03:00
|
|
|
var timeStamps = {};
|
2012-02-01 21:41:55 +04:00
|
|
|
|
2012-10-31 20:13:28 +04:00
|
|
|
this.TelemetryTimestamps = {
|
2012-02-01 21:41:55 +04:00
|
|
|
/**
|
|
|
|
* Adds a timestamp to the list. The addition of TimeStamps that already have
|
|
|
|
* a value stored is ignored.
|
|
|
|
*
|
|
|
|
* @param name must be a unique, generally "camelCase" descriptor of what the
|
|
|
|
* timestamp represents. e.g.: "delayedStartupStarted"
|
|
|
|
* @param value is a timeStamp in milliseconds since the epoch. If omitted,
|
|
|
|
* defaults to Date.now().
|
|
|
|
*/
|
2012-01-11 04:19:06 +04:00
|
|
|
add: function TT_add(name, value) {
|
|
|
|
// Default to "now" if not specified
|
|
|
|
if (value == null)
|
|
|
|
value = Date.now();
|
|
|
|
|
|
|
|
if (isNaN(value))
|
|
|
|
throw new Error("Value must be a timestamp");
|
|
|
|
|
|
|
|
// If there's an existing value, just ignore the new value.
|
2012-02-01 21:41:55 +04:00
|
|
|
if (timeStamps.hasOwnProperty(name))
|
2012-01-11 04:19:06 +04:00
|
|
|
return;
|
|
|
|
|
2012-02-01 21:41:55 +04:00
|
|
|
timeStamps[name] = value;
|
2012-01-11 04:19:06 +04:00
|
|
|
},
|
2012-02-01 21:41:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a JS object containing all of the timeStamps as properties (can be
|
2015-04-27 19:07:58 +03:00
|
|
|
* easily serialized to JSON). Used by TelemetryController to retrieve the data
|
2012-02-01 21:41:55 +04:00
|
|
|
* to attach to the telemetry submission.
|
|
|
|
*/
|
2012-01-11 04:19:06 +04:00
|
|
|
get: function TT_get() {
|
2014-02-26 14:55:40 +04:00
|
|
|
// Return a copy of the object.
|
|
|
|
return Cu.cloneInto(timeStamps, {});
|
2012-01-11 04:19:06 +04:00
|
|
|
}
|
|
|
|
};
|