1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/telemetry/TelemetryLog.jsm Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,35 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +this.EXPORTED_SYMBOLS = ["TelemetryLog"]; 1.9 + 1.10 +const Cc = Components.classes; 1.11 +const Ci = Components.interfaces; 1.12 + 1.13 +const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry); 1.14 +var gLogEntries = []; 1.15 + 1.16 +this.TelemetryLog = Object.freeze({ 1.17 + log: function(id, data) { 1.18 + id = String(id); 1.19 + var ts; 1.20 + try { 1.21 + ts = Math.floor(Telemetry.msSinceProcessStart()); 1.22 + } catch(e) { 1.23 + // If timestamp is screwed up, we just give up instead of making up 1.24 + // data. 1.25 + return; 1.26 + } 1.27 + 1.28 + var entry = [id, ts]; 1.29 + if (data !== undefined) { 1.30 + entry = entry.concat(Array.prototype.map.call(data, String)); 1.31 + } 1.32 + gLogEntries.push(entry); 1.33 + }, 1.34 + 1.35 + entries: function() { 1.36 + return gLogEntries; 1.37 + } 1.38 +});