2012-01-25 09:24:08 -08:00
|
|
|
/* -*- indent-tabs-mode: nil -*- */
|
2011-05-12 11:22:35 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* the Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2011
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Taras Glek <tglek@mozilla.com>
|
2011-12-14 12:04:25 -08:00
|
|
|
* Vladan Djeric <vdjeric@mozilla.com>
|
2011-05-12 11:22:35 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
const Cu = Components.utils;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2011-10-24 16:04:04 -07:00
|
|
|
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-05-31 17:23:34 -07:00
|
|
|
// When modifying the payload in incompatible ways, please bump this version number
|
|
|
|
const PAYLOAD_VERSION = 1;
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
const PREF_SERVER = "toolkit.telemetry.server";
|
|
|
|
const PREF_ENABLED = "toolkit.telemetry.enabled";
|
|
|
|
// Do not gather data more than once a minute
|
2011-08-11 14:19:47 -07:00
|
|
|
const TELEMETRY_INTERVAL = 60000;
|
2011-05-12 11:22:35 -07:00
|
|
|
// Delay before intializing telemetry (ms)
|
|
|
|
const TELEMETRY_DELAY = 60000;
|
|
|
|
// about:memory values to turn into histograms
|
|
|
|
const MEM_HISTOGRAMS = {
|
2011-06-29 22:44:17 -07:00
|
|
|
"js-gc-heap": "MEMORY_JS_GC_HEAP",
|
2011-08-10 19:00:38 -07:00
|
|
|
"js-compartments-system": "MEMORY_JS_COMPARTMENTS_SYSTEM",
|
|
|
|
"js-compartments-user": "MEMORY_JS_COMPARTMENTS_USER",
|
2011-12-12 19:04:12 -08:00
|
|
|
"explicit": "MEMORY_EXPLICIT",
|
2011-06-20 14:47:58 -07:00
|
|
|
"resident": "MEMORY_RESIDENT",
|
2012-01-03 00:27:05 -08:00
|
|
|
"storage-sqlite": "MEMORY_STORAGE_SQLITE",
|
2011-07-03 23:16:01 -07:00
|
|
|
"explicit/images/content/used/uncompressed":
|
|
|
|
"MEMORY_IMAGES_CONTENT_USED_UNCOMPRESSED",
|
2011-07-07 06:14:53 -07:00
|
|
|
"heap-allocated": "MEMORY_HEAP_ALLOCATED",
|
2011-12-19 08:57:57 -08:00
|
|
|
"page-faults-hard": "PAGE_FAULTS_HARD",
|
|
|
|
"low-memory-events-virtual": "LOW_MEMORY_EVENTS_VIRTUAL",
|
|
|
|
"low-memory-events-physical": "LOW_MEMORY_EVENTS_PHYSICAL"
|
2011-05-12 11:22:35 -07:00
|
|
|
};
|
2011-10-07 12:10:42 -07:00
|
|
|
// Seconds of idle time before pinging.
|
|
|
|
// On idle-daily a gather-telemetry notification is fired, during it probes can
|
|
|
|
// start asynchronous tasks to gather data. On the next idle the data is sent.
|
|
|
|
const IDLE_TIMEOUT_SECONDS = 5 * 60;
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-08-11 14:19:47 -07:00
|
|
|
var gLastMemoryPoll = null;
|
|
|
|
|
2011-07-13 10:00:04 -07:00
|
|
|
function getLocale() {
|
|
|
|
return Cc["@mozilla.org/chrome/chrome-registry;1"].
|
|
|
|
getService(Ci.nsIXULChromeRegistry).
|
|
|
|
getSelectedLocale('global');
|
|
|
|
}
|
|
|
|
|
2011-10-19 15:03:34 -07:00
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "Telemetry",
|
|
|
|
"@mozilla.org/base/telemetry;1",
|
|
|
|
"nsITelemetry");
|
|
|
|
XPCOMUtils.defineLazyServiceGetter(this, "idleService",
|
|
|
|
"@mozilla.org/widget/idleservice;1",
|
|
|
|
"nsIIdleService");
|
2011-05-12 11:22:35 -07:00
|
|
|
|
|
|
|
function generateUUID() {
|
2011-06-21 14:39:11 -07:00
|
|
|
let str = Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator).generateUUID().toString();
|
|
|
|
// strip {}
|
|
|
|
return str.substring(1, str.length - 1);
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
|
|
|
|
2011-05-31 17:23:34 -07:00
|
|
|
/**
|
|
|
|
* Gets a series of simple measurements (counters). At the moment, this
|
|
|
|
* only returns startup data from nsIAppStartup.getStartupInfo().
|
|
|
|
*
|
|
|
|
* @return simple measurements as a dictionary.
|
|
|
|
*/
|
|
|
|
function getSimpleMeasurements() {
|
2011-10-24 14:38:39 -07:00
|
|
|
let si = Services.startup.getStartupInfo();
|
2011-05-31 17:23:34 -07:00
|
|
|
|
|
|
|
var ret = {
|
|
|
|
// uptime in minutes
|
|
|
|
uptime: Math.round((new Date() - si.process) / 60000)
|
|
|
|
}
|
2011-07-07 15:40:33 -07:00
|
|
|
|
2012-01-27 12:37:28 -08:00
|
|
|
// Look for app-specific timestamps
|
|
|
|
var appTimestamps = {};
|
|
|
|
try {
|
|
|
|
let o = {};
|
|
|
|
Cu.import("resource:///modules/TelemetryTimestamps.jsm", o);
|
|
|
|
appTimestamps = o.TelemetryTimestamps.get();
|
|
|
|
} catch (ex) {}
|
|
|
|
|
2011-07-14 10:02:20 -07:00
|
|
|
if (si.process) {
|
2012-02-19 23:04:28 -08:00
|
|
|
for each (let field in Object.keys(si))]) {
|
|
|
|
if (field == "process")
|
2011-07-14 10:02:20 -07:00
|
|
|
continue;
|
|
|
|
ret[field] = si[field] - si.process
|
|
|
|
}
|
2012-01-27 12:37:28 -08:00
|
|
|
|
|
|
|
for (let p in appTimestamps) {
|
|
|
|
if (!(p in ret) && appTimestamps[p])
|
|
|
|
ret[p] = appTimestamps[p] - si.process;
|
|
|
|
}
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
2012-01-27 12:37:28 -08:00
|
|
|
|
2011-10-24 14:38:39 -07:00
|
|
|
ret.startupInterrupted = new Number(Services.startup.interrupted);
|
2011-07-07 15:40:33 -07:00
|
|
|
|
|
|
|
ret.js = Cc["@mozilla.org/js/xpc/XPConnect;1"]
|
|
|
|
.getService(Ci.nsIJSEngineTelemetryStats)
|
|
|
|
.telemetryValue;
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-01-25 12:12:26 -08:00
|
|
|
/**
|
|
|
|
* Read the update channel from defaults only. We do this to ensure that
|
|
|
|
* the channel is tightly coupled with the application and does not apply
|
|
|
|
* to other installations of the application that may use the same profile.
|
|
|
|
*/
|
|
|
|
function getUpdateChannel() {
|
|
|
|
var channel = "default";
|
|
|
|
var prefName;
|
|
|
|
var prefValue;
|
|
|
|
|
|
|
|
var defaults = Services.prefs.getDefaultBranch(null);
|
|
|
|
try {
|
|
|
|
channel = defaults.getCharPref("app.update.channel");
|
|
|
|
} catch (e) {
|
|
|
|
// use default when pref not found
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
var partners = Services.prefs.getChildList("app.partner.");
|
|
|
|
if (partners.length) {
|
|
|
|
channel += "-cck";
|
|
|
|
partners.sort();
|
|
|
|
|
|
|
|
for each (prefName in partners) {
|
|
|
|
prefValue = Services.prefs.getCharPref(prefName);
|
|
|
|
channel += "-" + prefValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
Cu.reportError(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
function TelemetryPing() {}
|
|
|
|
|
|
|
|
TelemetryPing.prototype = {
|
|
|
|
_histograms: {},
|
2011-06-30 14:58:00 -07:00
|
|
|
_initialized: false,
|
2011-06-16 11:38:23 -07:00
|
|
|
_prevValues: {},
|
2011-12-23 10:56:38 -08:00
|
|
|
// Generate a unique id once per session so the server can cope with
|
|
|
|
// duplicate submissions.
|
|
|
|
_uuid: generateUUID(),
|
2012-02-13 12:04:21 -08:00
|
|
|
// Regex that matches histograms we carea bout during startup.
|
|
|
|
_startupHistogramRegex: /SQLITE|HTTP|SPDY|CACHE|DNS/,
|
|
|
|
_slowSQLStartup: {},
|
2011-11-11 13:10:59 -08:00
|
|
|
|
|
|
|
/**
|
2012-01-25 09:23:38 -08:00
|
|
|
* When reflecting a histogram into JS, Telemetry hands us an object
|
|
|
|
* with the following properties:
|
|
|
|
*
|
|
|
|
* - min, max, histogram_type, sum: simple integers;
|
|
|
|
* - counts: array of counts for histogram buckets;
|
|
|
|
* - ranges: array of calculated bucket sizes.
|
|
|
|
*
|
|
|
|
* This format is not straightforward to read and potentially bulky
|
|
|
|
* with lots of zeros in the counts array. Packing histograms makes
|
|
|
|
* raw histograms easier to read and compresses the data a little bit.
|
|
|
|
*
|
|
|
|
* Returns an object:
|
|
|
|
* { range: [min, max], bucket_count: <number of buckets>,
|
|
|
|
* histogram_type: <histogram_type>, sum: <sum>
|
|
|
|
* values: { bucket1: count1, bucket2: count2, ... } }
|
2011-11-11 13:10:59 -08:00
|
|
|
*/
|
2012-01-25 09:23:38 -08:00
|
|
|
packHistogram: function packHistogram(hgram) {
|
|
|
|
let r = hgram.ranges;;
|
|
|
|
let c = hgram.counts;
|
|
|
|
let retgram = {
|
|
|
|
range: [r[1], r[r.length - 1]],
|
|
|
|
bucket_count: r.length,
|
|
|
|
histogram_type: hgram.histogram_type,
|
|
|
|
values: {},
|
|
|
|
sum: hgram.sum
|
|
|
|
};
|
|
|
|
let first = true;
|
|
|
|
let last = 0;
|
|
|
|
|
|
|
|
for (let i = 0; i < c.length; i++) {
|
|
|
|
let value = c[i];
|
|
|
|
if (!value)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
// add a lower bound
|
|
|
|
if (i && first) {
|
|
|
|
retgram.values[r[i - 1]] = 0;
|
|
|
|
}
|
|
|
|
first = false;
|
|
|
|
last = i + 1;
|
|
|
|
retgram.values[r[i]] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add an upper bound
|
|
|
|
if (last && last < c.length)
|
|
|
|
retgram.values[r[last]] = 0;
|
|
|
|
return retgram;
|
|
|
|
},
|
|
|
|
|
2012-02-02 09:14:19 -08:00
|
|
|
getHistograms: function getHistograms() {
|
|
|
|
let hls = Telemetry.histogramSnapshots;
|
2012-01-06 11:40:45 -08:00
|
|
|
let info = Telemetry.registeredHistograms;
|
2011-11-11 13:10:59 -08:00
|
|
|
let ret = {};
|
|
|
|
|
2012-01-06 11:40:45 -08:00
|
|
|
for (let name in hls) {
|
|
|
|
if (info[name]) {
|
2012-01-25 09:23:38 -08:00
|
|
|
ret[name] = this.packHistogram(hls[name]);
|
2012-01-10 16:19:06 -08:00
|
|
|
let startup_name = "STARTUP_" + name;
|
|
|
|
if (hls[startup_name])
|
2012-01-25 09:23:38 -08:00
|
|
|
ret[startup_name] = this.packHistogram(hls[startup_name]);
|
2012-01-06 11:40:45 -08:00
|
|
|
}
|
2011-11-11 13:10:59 -08:00
|
|
|
}
|
2012-01-06 11:40:45 -08:00
|
|
|
|
2011-11-11 13:10:59 -08:00
|
|
|
return ret;
|
|
|
|
},
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2012-01-25 09:24:08 -08:00
|
|
|
getAddonHistograms: function getAddonHistograms() {
|
|
|
|
let ahs = Telemetry.addonHistogramSnapshots;
|
|
|
|
let ret = {};
|
|
|
|
|
|
|
|
for (let name in ahs) {
|
|
|
|
ret[name] = this.convertHistogram(ahs[name]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2011-07-03 23:16:01 -07:00
|
|
|
addValue: function addValue(name, id, val) {
|
|
|
|
let h = this._histograms[name];
|
|
|
|
if (!h) {
|
|
|
|
h = Telemetry.getHistogramById(id);
|
|
|
|
this._histograms[name] = h;
|
|
|
|
}
|
|
|
|
h.add(val);
|
|
|
|
},
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-10-24 16:04:04 -07:00
|
|
|
/**
|
|
|
|
* Descriptive metadata
|
|
|
|
*
|
|
|
|
* @param reason
|
|
|
|
* The reason for the telemetry ping, this will be included in the
|
|
|
|
* returned metadata,
|
|
|
|
* @return The metadata as a JS object
|
|
|
|
*/
|
|
|
|
getMetadata: function getMetadata(reason) {
|
|
|
|
let ai = Services.appinfo;
|
|
|
|
let ret = {
|
|
|
|
reason: reason,
|
|
|
|
OS: ai.OS,
|
|
|
|
appID: ai.ID,
|
|
|
|
appVersion: ai.version,
|
|
|
|
appName: ai.name,
|
|
|
|
appBuildID: ai.appBuildID,
|
2012-01-25 12:12:26 -08:00
|
|
|
appUpdateChannel: getUpdateChannel(),
|
|
|
|
platformBuildID: ai.platformBuildID
|
2011-10-24 16:04:04 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// sysinfo fields are not always available, get what we can.
|
|
|
|
let sysInfo = Cc["@mozilla.org/system-info;1"].getService(Ci.nsIPropertyBag2);
|
2011-11-14 11:51:34 -08:00
|
|
|
let fields = ["cpucount", "memsize", "arch", "version", "device", "manufacturer", "hardware",
|
|
|
|
"hasMMX", "hasSSE", "hasSSE2", "hasSSE3",
|
|
|
|
"hasSSSE3", "hasSSE4A", "hasSSE4_1", "hasSSE4_2",
|
|
|
|
"hasEDSP", "hasARMv6", "hasNEON"];
|
2011-10-24 16:04:04 -07:00
|
|
|
for each (let field in fields) {
|
|
|
|
let value;
|
|
|
|
try {
|
|
|
|
value = sysInfo.getProperty(field);
|
|
|
|
} catch (e) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if (field == "memsize") {
|
|
|
|
// Send RAM size in megabytes. Rounding because sysinfo doesn't
|
|
|
|
// always provide RAM in multiples of 1024.
|
|
|
|
value = Math.round(value / 1024 / 1024)
|
|
|
|
}
|
|
|
|
ret[field] = value
|
|
|
|
}
|
|
|
|
|
2012-01-22 22:58:34 -08:00
|
|
|
// gfxInfo fields are not always available, get what we can.
|
|
|
|
let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo);
|
|
|
|
let gfxfields = ["adapterDescription", "adapterVendorID", "adapterDeviceID",
|
|
|
|
"adapterRAM", "adapterDriver", "adapterDriverVersion",
|
|
|
|
"adapterDriverDate", "adapterDescription2",
|
|
|
|
"adapterVendorID2", "adapterDeviceID2", "adapterRAM2",
|
|
|
|
"adapterDriver2", "adapterDriverVersion2",
|
|
|
|
"adapterDriverDate2", "isGPU2Active", "D2DEnabled;",
|
|
|
|
"DWriteEnabled", "DWriteVersion"
|
|
|
|
];
|
|
|
|
|
|
|
|
if (gfxInfo) {
|
|
|
|
for each (let field in gfxfields) {
|
|
|
|
try {
|
|
|
|
let value = "";
|
|
|
|
value = gfxInfo[field];
|
|
|
|
if (value != "")
|
|
|
|
ret[field] = value;
|
|
|
|
} catch (e) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 16:04:04 -07:00
|
|
|
let theme = LightweightThemeManager.currentTheme;
|
|
|
|
if (theme)
|
|
|
|
ret.persona = theme.id;
|
|
|
|
|
|
|
|
if (this._addons)
|
|
|
|
ret.addons = this._addons;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
/**
|
|
|
|
* Pull values from about:memory into corresponding histograms
|
|
|
|
*/
|
|
|
|
gatherMemory: function gatherMemory() {
|
|
|
|
let mgr;
|
|
|
|
try {
|
|
|
|
mgr = Cc["@mozilla.org/memory-reporter-manager;1"].
|
|
|
|
getService(Ci.nsIMemoryReporterManager);
|
|
|
|
} catch (e) {
|
|
|
|
// OK to skip memory reporters in xpcshell
|
2011-06-16 11:38:23 -07:00
|
|
|
return;
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
let e = mgr.enumerateReporters();
|
|
|
|
while (e.hasMoreElements()) {
|
|
|
|
let mr = e.getNext().QueryInterface(Ci.nsIMemoryReporter);
|
2011-06-20 14:47:58 -07:00
|
|
|
let id = MEM_HISTOGRAMS[mr.path];
|
2011-12-12 19:04:12 -08:00
|
|
|
if (!id) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// mr.amount is expensive to read in some cases, so get it only once.
|
|
|
|
let amount = mr.amount;
|
|
|
|
if (amount == -1) {
|
2011-05-12 11:22:35 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-06-27 10:03:28 -07:00
|
|
|
let val;
|
2011-06-16 11:38:23 -07:00
|
|
|
if (mr.units == Ci.nsIMemoryReporter.UNITS_BYTES) {
|
2011-12-12 19:04:12 -08:00
|
|
|
val = Math.floor(amount / 1024);
|
2011-06-16 11:38:23 -07:00
|
|
|
}
|
|
|
|
else if (mr.units == Ci.nsIMemoryReporter.UNITS_COUNT) {
|
2011-12-12 19:04:12 -08:00
|
|
|
val = amount;
|
2011-07-24 20:56:50 -07:00
|
|
|
}
|
|
|
|
else if (mr.units == Ci.nsIMemoryReporter.UNITS_COUNT_CUMULATIVE) {
|
|
|
|
// If the reporter gives us a cumulative count, we'll report the
|
|
|
|
// difference in its value between now and our previous ping.
|
2011-06-16 11:38:23 -07:00
|
|
|
|
2011-07-02 17:45:28 -07:00
|
|
|
if (!(mr.path in this._prevValues)) {
|
2011-06-16 11:38:23 -07:00
|
|
|
// If this is the first time we're reading this reporter, store its
|
|
|
|
// current value but don't report it in the telemetry ping, so we
|
|
|
|
// ignore the effect startup had on the reporter.
|
2011-12-12 19:04:12 -08:00
|
|
|
this._prevValues[mr.path] = amount;
|
2011-06-16 11:38:23 -07:00
|
|
|
continue;
|
|
|
|
}
|
2011-07-02 17:45:28 -07:00
|
|
|
|
2011-12-12 19:04:12 -08:00
|
|
|
val = amount - this._prevValues[mr.path];
|
|
|
|
this._prevValues[mr.path] = amount;
|
2011-06-16 11:38:23 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
NS_ASSERT(false, "Can't handle memory reporter with units " + mr.units);
|
|
|
|
continue;
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
2011-07-03 23:16:01 -07:00
|
|
|
this.addValue(mr.path, id, val);
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
|
|
|
},
|
2012-02-13 12:04:21 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return true if we're interested in having a STARTUP_* histogram for
|
|
|
|
* the given histogram name.
|
|
|
|
*/
|
|
|
|
isInterestingStartupHistogram: function isInterestingStartupHistogram(name) {
|
|
|
|
return this._startupHistogramRegex.test(name);
|
|
|
|
},
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-11-11 13:10:59 -08:00
|
|
|
/**
|
2012-02-13 12:04:21 -08:00
|
|
|
* Make a copy of interesting histograms at startup.
|
2011-11-11 13:10:59 -08:00
|
|
|
*/
|
2012-02-13 12:04:21 -08:00
|
|
|
gatherStartupInformation: function gatherStartupInformation() {
|
2012-01-06 11:40:45 -08:00
|
|
|
let info = Telemetry.registeredHistograms;
|
2012-02-13 12:04:21 -08:00
|
|
|
let snapshots = Telemetry.histogramSnapshots;
|
2012-01-06 11:40:45 -08:00
|
|
|
for (let name in info) {
|
2012-02-13 12:04:21 -08:00
|
|
|
// Only duplicate histograms with actual data.
|
|
|
|
if (this.isInterestingStartupHistogram(name) && name in snapshots) {
|
2012-01-06 11:40:45 -08:00
|
|
|
Telemetry.histogramFrom("STARTUP_" + name, name);
|
2012-02-13 12:04:21 -08:00
|
|
|
}
|
2011-11-11 13:10:59 -08:00
|
|
|
}
|
2012-02-13 12:04:21 -08:00
|
|
|
this._slowSQLStartup = Telemetry.slowSQL;
|
2011-11-11 13:10:59 -08:00
|
|
|
},
|
|
|
|
|
2012-02-02 09:14:19 -08:00
|
|
|
getSessionPayloadAndSlug: function getSessionPayloadAndSlug(reason) {
|
|
|
|
let isTestPing = (reason == "test-ping");
|
|
|
|
let slug = (isTestPing ? reason : this._uuid);
|
|
|
|
let payloadObj = {
|
|
|
|
ver: PAYLOAD_VERSION,
|
|
|
|
info: this.getMetadata(reason),
|
|
|
|
simpleMeasurements: getSimpleMeasurements(),
|
|
|
|
histograms: this.getHistograms(),
|
2012-01-25 09:24:08 -08:00
|
|
|
slowSQL: Telemetry.slowSQL,
|
|
|
|
addonHistograms: this.getAddonHistograms()
|
2012-02-02 09:14:19 -08:00
|
|
|
};
|
2012-02-13 12:04:21 -08:00
|
|
|
if (Object.keys(this._slowSQLStartup.mainThread).length
|
|
|
|
|| Object.keys(this._slowSQLStartup.otherThreads).length) {
|
|
|
|
payloadObj.slowSQLStartup = this._slowSQLStartup;
|
|
|
|
}
|
2012-02-02 09:14:19 -08:00
|
|
|
|
|
|
|
return { slug: slug, payload: JSON.stringify(payloadObj) };
|
|
|
|
},
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
/**
|
|
|
|
* Send data to the server. Record success/send-time in histograms
|
|
|
|
*/
|
|
|
|
send: function send(reason, server) {
|
|
|
|
// populate histograms one last time
|
|
|
|
this.gatherMemory();
|
2011-12-23 10:56:38 -08:00
|
|
|
|
2012-02-02 09:14:19 -08:00
|
|
|
let data = this.getSessionPayloadAndSlug(reason);
|
2011-12-23 10:56:38 -08:00
|
|
|
let isTestPing = (reason == "test-ping");
|
2012-02-02 09:14:19 -08:00
|
|
|
let submitPath = "/submit/telemetry/" + data.slug;
|
|
|
|
|
|
|
|
let hping = Telemetry.getHistogramById("TELEMETRY_PING");
|
|
|
|
let hsuccess = Telemetry.getHistogramById("TELEMETRY_SUCCESS");
|
2011-10-24 16:04:04 -07:00
|
|
|
|
2011-12-23 10:56:38 -08:00
|
|
|
let url = server + submitPath;
|
2011-05-12 11:22:35 -07:00
|
|
|
let request = Cc["@mozilla.org/xmlextras/xmlhttprequest;1"]
|
|
|
|
.createInstance(Ci.nsIXMLHttpRequest);
|
|
|
|
request.mozBackgroundRequest = true;
|
|
|
|
request.open("POST", url, true);
|
|
|
|
request.overrideMimeType("text/plain");
|
2011-06-21 14:39:11 -07:00
|
|
|
request.setRequestHeader("Content-Type", "application/json");
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-06-16 11:38:23 -07:00
|
|
|
let startTime = new Date();
|
2011-05-12 11:22:35 -07:00
|
|
|
|
2011-06-21 14:39:11 -07:00
|
|
|
function finishRequest(channel) {
|
|
|
|
let success = false;
|
|
|
|
try {
|
|
|
|
success = channel.QueryInterface(Ci.nsIHttpChannel).requestSucceeded;
|
|
|
|
} catch(e) {
|
|
|
|
}
|
2012-02-02 09:14:19 -08:00
|
|
|
hsuccess.add(success);
|
|
|
|
hping.add(new Date() - startTime);
|
|
|
|
if (isTestPing)
|
2011-05-12 11:22:35 -07:00
|
|
|
Services.obs.notifyObservers(null, "telemetry-test-xhr-complete", null);
|
|
|
|
}
|
2011-09-29 09:06:36 -07:00
|
|
|
request.addEventListener("error", function(aEvent) finishRequest(request.channel), false);
|
|
|
|
request.addEventListener("load", function(aEvent) finishRequest(request.channel), false);
|
2011-06-21 14:39:11 -07:00
|
|
|
|
2012-02-02 09:14:19 -08:00
|
|
|
request.send(data.payload);
|
2011-05-12 11:22:35 -07:00
|
|
|
},
|
|
|
|
|
2011-06-28 16:57:44 -07:00
|
|
|
attachObservers: function attachObservers() {
|
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
2011-08-11 14:19:47 -07:00
|
|
|
Services.obs.addObserver(this, "cycle-collector-begin", false);
|
2011-06-28 16:57:44 -07:00
|
|
|
Services.obs.addObserver(this, "idle-daily", false);
|
|
|
|
},
|
|
|
|
|
|
|
|
detachObservers: function detachObservers() {
|
|
|
|
if (!this._initialized)
|
|
|
|
return;
|
|
|
|
Services.obs.removeObserver(this, "idle-daily");
|
2011-08-11 14:19:47 -07:00
|
|
|
Services.obs.removeObserver(this, "cycle-collector-begin");
|
2011-10-07 12:10:42 -07:00
|
|
|
if (this._isIdleObserver) {
|
2011-10-19 15:03:34 -07:00
|
|
|
idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
|
2011-10-07 12:10:42 -07:00
|
|
|
this._isIdleObserver = false;
|
|
|
|
}
|
2011-06-28 16:57:44 -07:00
|
|
|
},
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
/**
|
|
|
|
* Initializes telemetry within a timer. If there is no PREF_SERVER set, don't turn on telemetry.
|
|
|
|
*/
|
|
|
|
setup: function setup() {
|
|
|
|
let enabled = false;
|
|
|
|
try {
|
|
|
|
enabled = Services.prefs.getBoolPref(PREF_ENABLED);
|
|
|
|
this._server = Services.prefs.getCharPref(PREF_SERVER);
|
|
|
|
} catch (e) {
|
|
|
|
// Prerequesite prefs aren't set
|
|
|
|
}
|
2011-06-28 16:57:44 -07:00
|
|
|
if (!enabled) {
|
|
|
|
// Turn off local telemetry if telemetry is disabled.
|
|
|
|
// This may change once about:telemetry is added.
|
|
|
|
Telemetry.canRecord = false;
|
2011-05-12 11:22:35 -07:00
|
|
|
return;
|
2011-06-28 16:57:44 -07:00
|
|
|
}
|
|
|
|
Services.obs.addObserver(this, "private-browsing", false);
|
|
|
|
Services.obs.addObserver(this, "profile-before-change", false);
|
2011-11-11 13:10:59 -08:00
|
|
|
Services.obs.addObserver(this, "sessionstore-windows-restored", false);
|
2011-06-28 16:57:44 -07:00
|
|
|
|
|
|
|
// Delay full telemetry initialization to give the browser time to
|
|
|
|
// run various late initializers. Otherwise our gathered memory
|
|
|
|
// footprint and other numbers would be too optimistic.
|
2011-05-12 11:22:35 -07:00
|
|
|
let self = this;
|
|
|
|
this._timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
|
|
|
let timerCallback = function() {
|
2011-06-28 16:57:44 -07:00
|
|
|
self._initialized = true;
|
|
|
|
self.attachObservers();
|
2011-05-12 11:22:35 -07:00
|
|
|
self.gatherMemory();
|
2011-05-16 16:03:36 -07:00
|
|
|
delete self._timer
|
2011-05-12 11:22:35 -07:00
|
|
|
}
|
|
|
|
this._timer.initWithCallback(timerCallback, TELEMETRY_DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
|
|
|
|
},
|
|
|
|
|
2011-05-16 16:03:36 -07:00
|
|
|
/**
|
|
|
|
* Remove observers to avoid leaks
|
|
|
|
*/
|
|
|
|
uninstall: function uninstall() {
|
2011-06-28 16:57:44 -07:00
|
|
|
this.detachObservers()
|
2011-11-11 13:10:59 -08:00
|
|
|
Services.obs.removeObserver(this, "sessionstore-windows-restored");
|
2011-05-16 16:03:36 -07:00
|
|
|
Services.obs.removeObserver(this, "profile-before-change");
|
2011-06-28 16:57:44 -07:00
|
|
|
Services.obs.removeObserver(this, "private-browsing");
|
2011-05-16 16:03:36 -07:00
|
|
|
},
|
|
|
|
|
2011-05-12 11:22:35 -07:00
|
|
|
/**
|
|
|
|
* This observer drives telemetry.
|
|
|
|
*/
|
|
|
|
observe: function (aSubject, aTopic, aData) {
|
|
|
|
// Allows to change the server for testing
|
|
|
|
var server = this._server;
|
|
|
|
|
|
|
|
switch (aTopic) {
|
2011-10-24 16:04:04 -07:00
|
|
|
case "Add-ons":
|
|
|
|
this._addons = aData;
|
|
|
|
break;
|
2011-05-12 11:22:35 -07:00
|
|
|
case "profile-after-change":
|
|
|
|
this.setup();
|
|
|
|
break;
|
2011-05-16 16:03:36 -07:00
|
|
|
case "profile-before-change":
|
|
|
|
this.uninstall();
|
|
|
|
break;
|
2011-08-11 14:19:47 -07:00
|
|
|
case "cycle-collector-begin":
|
|
|
|
let now = new Date();
|
|
|
|
if (!gLastMemoryPoll
|
|
|
|
|| (TELEMETRY_INTERVAL <= now - gLastMemoryPoll)) {
|
|
|
|
gLastMemoryPoll = now;
|
|
|
|
this.gatherMemory();
|
|
|
|
}
|
2011-05-12 11:22:35 -07:00
|
|
|
break;
|
2011-06-28 16:57:44 -07:00
|
|
|
case "private-browsing":
|
|
|
|
Telemetry.canRecord = aData == "exit";
|
|
|
|
if (aData == "enter") {
|
|
|
|
this.detachObservers()
|
|
|
|
} else {
|
|
|
|
this.attachObservers()
|
|
|
|
}
|
|
|
|
break;
|
2011-11-11 13:10:59 -08:00
|
|
|
case "sessionstore-windows-restored":
|
2012-02-13 12:04:21 -08:00
|
|
|
this.gatherStartupInformation();
|
2011-11-11 13:10:59 -08:00
|
|
|
break;
|
2011-10-07 12:10:42 -07:00
|
|
|
case "idle-daily":
|
|
|
|
// Enqueue to main-thread, otherwise components may be inited by the
|
|
|
|
// idle-daily category and miss the gather-telemetry notification.
|
|
|
|
Services.tm.mainThread.dispatch((function() {
|
|
|
|
// Notify that data should be gathered now, since ping will happen soon.
|
|
|
|
Services.obs.notifyObservers(null, "gather-telemetry", null);
|
|
|
|
// The ping happens at the first idle of length IDLE_TIMEOUT_SECONDS.
|
2011-10-19 15:03:34 -07:00
|
|
|
idleService.addIdleObserver(this, IDLE_TIMEOUT_SECONDS);
|
2011-10-07 12:10:42 -07:00
|
|
|
this._isIdleObserver = true;
|
|
|
|
}).bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
|
|
|
break;
|
2012-01-10 16:19:06 -08:00
|
|
|
case "get-payload":
|
|
|
|
this.gatherMemory();
|
2012-02-13 12:04:21 -08:00
|
|
|
this.gatherStartupInformation();
|
2012-01-10 16:19:06 -08:00
|
|
|
let data = this.getSessionPayloadAndSlug("gather-payload");
|
|
|
|
|
|
|
|
aSubject.QueryInterface(Ci.nsISupportsString).data = data.payload;
|
|
|
|
break;
|
2011-05-12 11:22:35 -07:00
|
|
|
case "test-ping":
|
|
|
|
server = aData;
|
|
|
|
// fall through
|
2011-10-07 12:10:42 -07:00
|
|
|
case "idle":
|
|
|
|
if (this._isIdleObserver) {
|
2011-10-19 15:03:34 -07:00
|
|
|
idleService.removeIdleObserver(this, IDLE_TIMEOUT_SECONDS);
|
2011-10-07 12:10:42 -07:00
|
|
|
this._isIdleObserver = false;
|
|
|
|
}
|
2012-02-01 20:42:20 -08:00
|
|
|
reason = (Telemetry.canSend && aTopic == "idle"
|
|
|
|
? "idle-daily"
|
|
|
|
: "test-ping");
|
|
|
|
this.send(reason, server);
|
2011-05-12 11:22:35 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
classID: Components.ID("{55d6a5fa-130e-4ee6-a158-0133af3b86ba}"),
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
|
|
|
};
|
|
|
|
|
|
|
|
let NSGetFactory = XPCOMUtils.generateNSGetFactory([TelemetryPing]);
|