1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
3 * You can obtain one at http://mozilla.org/MPL/2.0/. */
5 this.EXPORTED_SYMBOLS = ["TelemetryTimestamps"];
8 * This module's purpose is to collect timestamps for important
9 * application-specific events.
11 * The TelemetryPing component attaches the timestamps stored by this module to
12 * the telemetry submission, substracting the process lifetime so that the times
13 * are relative to process startup. The overall goal is to produce a basic
14 * timeline of the startup process.
18 this.TelemetryTimestamps = {
20 * Adds a timestamp to the list. The addition of TimeStamps that already have
21 * a value stored is ignored.
23 * @param name must be a unique, generally "camelCase" descriptor of what the
24 * timestamp represents. e.g.: "delayedStartupStarted"
25 * @param value is a timeStamp in milliseconds since the epoch. If omitted,
26 * defaults to Date.now().
28 add: function TT_add(name, value) {
29 // Default to "now" if not specified
34 throw new Error("Value must be a timestamp");
36 // If there's an existing value, just ignore the new value.
37 if (timeStamps.hasOwnProperty(name))
40 timeStamps[name] = value;
44 * Returns a JS object containing all of the timeStamps as properties (can be
45 * easily serialized to JSON). Used by TelemetryPing to retrieve the data
46 * to attach to the telemetry submission.
48 get: function TT_get() {
49 // Return a copy of the object by passing it through JSON.
50 return JSON.parse(JSON.stringify(timeStamps));