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"];
7 const Cu = Components.utils;
10 * This module's purpose is to collect timestamps for important
11 * application-specific events.
13 * The TelemetryPing component attaches the timestamps stored by this module to
14 * the telemetry submission, substracting the process lifetime so that the times
15 * are relative to process startup. The overall goal is to produce a basic
16 * timeline of the startup process.
20 this.TelemetryTimestamps = {
22 * Adds a timestamp to the list. The addition of TimeStamps that already have
23 * a value stored is ignored.
25 * @param name must be a unique, generally "camelCase" descriptor of what the
26 * timestamp represents. e.g.: "delayedStartupStarted"
27 * @param value is a timeStamp in milliseconds since the epoch. If omitted,
28 * defaults to Date.now().
30 add: function TT_add(name, value) {
31 // Default to "now" if not specified
36 throw new Error("Value must be a timestamp");
38 // If there's an existing value, just ignore the new value.
39 if (timeStamps.hasOwnProperty(name))
42 timeStamps[name] = value;
46 * Returns a JS object containing all of the timeStamps as properties (can be
47 * easily serialized to JSON). Used by TelemetryPing to retrieve the data
48 * to attach to the telemetry submission.
50 get: function TT_get() {
51 // Return a copy of the object.
52 return Cu.cloneInto(timeStamps, {});