toolkit/modules/TelemetryTimestamps.jsm

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial