TelemetryLog.jsm 933 B

123456789101112131415161718192021222324252627282930313233343536
  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
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. this.EXPORTED_SYMBOLS = ["TelemetryLog"];
  5. const Cc = Components.classes;
  6. const Ci = Components.interfaces;
  7. const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
  8. var gLogEntries = [];
  9. this.TelemetryLog = Object.freeze({
  10. log: function(id, data) {
  11. id = String(id);
  12. var ts;
  13. try {
  14. ts = Math.floor(Telemetry.msSinceProcessStart());
  15. } catch (e) {
  16. // If timestamp is screwed up, we just give up instead of making up
  17. // data.
  18. return;
  19. }
  20. var entry = [id, ts];
  21. if (data !== undefined) {
  22. entry = entry.concat(Array.prototype.map.call(data, String));
  23. }
  24. gLogEntries.push(entry);
  25. },
  26. entries: function() {
  27. return gLogEntries;
  28. }
  29. });