2012-11-12 15:50:04 -08:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This file contains metrics data providers for the Firefox Health
|
|
|
|
* Report. Ideally each provider in this file exists in separate modules
|
|
|
|
* and lives close to the code it is querying. However, because of the
|
|
|
|
* overhead of JS compartments (which are created for each module), we
|
|
|
|
* currently have all the code in one file. When the overhead of
|
|
|
|
* compartments reaches a reasonable level, this file should be split
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
this.EXPORTED_SYMBOLS = [
|
2012-11-19 13:18:30 -08:00
|
|
|
"AppInfoProvider",
|
|
|
|
"SysInfoProvider",
|
2012-11-12 15:50:04 -08:00
|
|
|
];
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
Cu.import("resource://gre/modules/Metrics.jsm");
|
2012-11-12 15:50:04 -08:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
2013-01-06 12:13:27 -08:00
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2012-11-12 15:50:04 -08:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
Cu.import("resource://services-common/preferences.js");
|
|
|
|
Cu.import("resource://services-common/utils.js");
|
|
|
|
|
|
|
|
|
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
|
|
|
"resource://gre/modules/UpdateChannel.jsm");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents basic application state.
|
|
|
|
*
|
|
|
|
* This is roughly a union of nsIXULAppInfo, nsIXULRuntime, with a few extra
|
|
|
|
* pieces thrown in.
|
|
|
|
*/
|
|
|
|
function AppInfoMeasurement() {
|
2013-01-06 12:13:27 -08:00
|
|
|
Metrics.Measurement.call(this);
|
2012-11-12 15:50:04 -08:00
|
|
|
}
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
AppInfoMeasurement.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: "appinfo",
|
|
|
|
version: 1,
|
|
|
|
|
|
|
|
LAST_TEXT_FIELDS: [
|
|
|
|
"vendor",
|
|
|
|
"name",
|
|
|
|
"id",
|
|
|
|
"version",
|
|
|
|
"appBuildID",
|
|
|
|
"platformVersion",
|
|
|
|
"platformBuildID",
|
|
|
|
"os",
|
|
|
|
"xpcomabi",
|
|
|
|
"updateChannel",
|
|
|
|
"distributionID",
|
|
|
|
"distributionVersion",
|
|
|
|
"hotfixVersion",
|
|
|
|
"locale",
|
|
|
|
],
|
|
|
|
|
|
|
|
configureStorage: function () {
|
|
|
|
let self = this;
|
|
|
|
return Task.spawn(function configureStorage() {
|
|
|
|
for (let field of self.LAST_TEXT_FIELDS) {
|
|
|
|
yield self.registerStorageField(field, self.storage.FIELD_LAST_TEXT);
|
|
|
|
}
|
|
|
|
});
|
2012-11-12 15:50:04 -08:00
|
|
|
},
|
2013-01-06 12:13:27 -08:00
|
|
|
});
|
2012-11-12 15:50:04 -08:00
|
|
|
|
|
|
|
|
2013-01-06 12:16:05 -08:00
|
|
|
function AppVersionMeasurement() {
|
|
|
|
Metrics.Measurement.call(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
AppVersionMeasurement.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: "versions",
|
|
|
|
version: 1,
|
|
|
|
|
|
|
|
configureStorage: function () {
|
|
|
|
return this.registerStorageField("version",
|
|
|
|
this.storage.FIELD_DAILY_DISCRETE_TEXT);
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2012-11-12 15:50:04 -08:00
|
|
|
this.AppInfoProvider = function AppInfoProvider() {
|
2013-01-06 12:13:27 -08:00
|
|
|
Metrics.Provider.call(this);
|
2012-11-12 15:50:04 -08:00
|
|
|
|
|
|
|
this._prefs = new Preferences({defaultBranch: null});
|
|
|
|
}
|
2013-01-06 12:13:27 -08:00
|
|
|
AppInfoProvider.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Provider.prototype,
|
|
|
|
|
|
|
|
name: "org.mozilla.appInfo",
|
|
|
|
|
2013-01-06 12:16:05 -08:00
|
|
|
measurementTypes: [AppInfoMeasurement, AppVersionMeasurement],
|
2012-11-12 15:50:04 -08:00
|
|
|
|
|
|
|
appInfoFields: {
|
|
|
|
// From nsIXULAppInfo.
|
|
|
|
vendor: "vendor",
|
|
|
|
name: "name",
|
|
|
|
id: "ID",
|
|
|
|
version: "version",
|
|
|
|
appBuildID: "appBuildID",
|
|
|
|
platformVersion: "platformVersion",
|
|
|
|
platformBuildID: "platformBuildID",
|
|
|
|
|
|
|
|
// From nsIXULRuntime.
|
|
|
|
os: "OS",
|
|
|
|
xpcomabi: "XPCOMABI",
|
|
|
|
},
|
|
|
|
|
2013-01-06 12:16:05 -08:00
|
|
|
onInit: function () {
|
|
|
|
return Task.spawn(this._onInit.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
_onInit: function () {
|
|
|
|
// Services.appInfo should always be defined for any reasonably behaving
|
|
|
|
// Gecko app. If it isn't, we insert a empty string sentinel value.
|
|
|
|
let ai;
|
|
|
|
try {
|
|
|
|
ai = Services.appinfo;
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Could not obtain Services.appinfo: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
yield this._setCurrentVersion("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ai) {
|
|
|
|
this._log.error("Services.appinfo is unavailable.");
|
|
|
|
yield this._setCurrentVersion("");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let currentVersion = ai.version;
|
|
|
|
let lastVersion = yield this.getState("lastVersion");
|
|
|
|
|
|
|
|
if (currentVersion == lastVersion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield this._setCurrentVersion(currentVersion);
|
|
|
|
},
|
|
|
|
|
|
|
|
_setCurrentVersion: function (version) {
|
|
|
|
this._log.info("Recording new application version: " + version);
|
|
|
|
let m = this.getMeasurement("versions", 1);
|
|
|
|
m.addDailyDiscreteText("version", version);
|
|
|
|
return this.setState("lastVersion", version);
|
|
|
|
},
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
collectConstantData: function () {
|
|
|
|
return this.enqueueStorageOperation(function collect() {
|
|
|
|
return Task.spawn(this._populateConstants.bind(this));
|
|
|
|
}.bind(this));
|
2012-11-12 15:50:04 -08:00
|
|
|
},
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
_populateConstants: function () {
|
|
|
|
let m = this.getMeasurement(AppInfoMeasurement.prototype.name,
|
|
|
|
AppInfoMeasurement.prototype.version);
|
2012-11-12 15:50:04 -08:00
|
|
|
|
|
|
|
let ai;
|
|
|
|
try {
|
|
|
|
ai = Services.appinfo;
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Could not obtain Services.appinfo: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ai) {
|
|
|
|
this._log.warn("Services.appinfo is unavailable.");
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (let [k, v] in Iterator(this.appInfoFields)) {
|
|
|
|
try {
|
2013-01-06 12:13:27 -08:00
|
|
|
yield m.setLastText(k, ai[v]);
|
2012-11-12 15:50:04 -08:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Error obtaining Services.appinfo." + v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2013-01-06 12:13:27 -08:00
|
|
|
yield m.setLastText("updateChannel", UpdateChannel.get());
|
2012-11-12 15:50:04 -08:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Could not obtain update channel: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
yield m.setLastText("distributionID", this._prefs.get("distribution.id", ""));
|
|
|
|
yield m.setLastText("distributionVersion", this._prefs.get("distribution.version", ""));
|
|
|
|
yield m.setLastText("hotfixVersion", this._prefs.get("extensions.hotfix.lastVersion", ""));
|
2012-11-12 15:50:04 -08:00
|
|
|
|
|
|
|
try {
|
|
|
|
let locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
|
|
|
.getService(Ci.nsIXULChromeRegistry)
|
|
|
|
.getSelectedLocale("global");
|
2013-01-06 12:13:27 -08:00
|
|
|
yield m.setLastText("locale", locale);
|
2012-11-12 15:50:04 -08:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Could not obtain application locale: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
},
|
2013-01-06 12:13:27 -08:00
|
|
|
});
|
2012-11-12 15:50:04 -08:00
|
|
|
|
2012-11-19 13:18:30 -08:00
|
|
|
|
|
|
|
function SysInfoMeasurement() {
|
2013-01-06 12:13:27 -08:00
|
|
|
Metrics.Measurement.call(this);
|
2012-11-19 13:18:30 -08:00
|
|
|
}
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
SysInfoMeasurement.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Measurement.prototype,
|
|
|
|
|
|
|
|
name: "sysinfo",
|
|
|
|
version: 1,
|
|
|
|
|
|
|
|
configureStorage: function () {
|
|
|
|
return Task.spawn(function configureStorage() {
|
|
|
|
yield this.registerStorageField("cpuCount", this.storage.FIELD_LAST_NUMERIC);
|
|
|
|
yield this.registerStorageField("memoryMB", this.storage.FIELD_LAST_NUMERIC);
|
|
|
|
yield this.registerStorageField("manufacturer", this.storage.FIELD_LAST_TEXT);
|
|
|
|
yield this.registerStorageField("device", this.storage.FIELD_LAST_TEXT);
|
|
|
|
yield this.registerStorageField("hardware", this.storage.FIELD_LAST_TEXT);
|
|
|
|
yield this.registerStorageField("name", this.storage.FIELD_LAST_TEXT);
|
|
|
|
yield this.registerStorageField("version", this.storage.FIELD_LAST_TEXT);
|
|
|
|
yield this.registerStorageField("architecture", this.storage.FIELD_LAST_TEXT);
|
|
|
|
}.bind(this));
|
2012-11-19 13:18:30 -08:00
|
|
|
},
|
2013-01-06 12:13:27 -08:00
|
|
|
});
|
2012-11-19 13:18:30 -08:00
|
|
|
|
|
|
|
|
|
|
|
this.SysInfoProvider = function SysInfoProvider() {
|
2013-01-06 12:13:27 -08:00
|
|
|
Metrics.Provider.call(this);
|
2012-11-19 13:18:30 -08:00
|
|
|
};
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
SysInfoProvider.prototype = Object.freeze({
|
|
|
|
__proto__: Metrics.Provider.prototype,
|
|
|
|
|
|
|
|
name: "org.mozilla.sysinfo",
|
|
|
|
|
|
|
|
measurementTypes: [SysInfoMeasurement],
|
2012-11-19 13:18:30 -08:00
|
|
|
|
|
|
|
sysInfoFields: {
|
|
|
|
cpucount: "cpuCount",
|
|
|
|
memsize: "memoryMB",
|
|
|
|
manufacturer: "manufacturer",
|
|
|
|
device: "device",
|
|
|
|
hardware: "hardware",
|
|
|
|
name: "name",
|
|
|
|
version: "version",
|
|
|
|
arch: "architecture",
|
|
|
|
},
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
collectConstantData: function () {
|
|
|
|
return this.enqueueStorageOperation(function collection() {
|
|
|
|
return Task.spawn(this._populateConstants.bind(this));
|
|
|
|
}.bind(this));
|
2012-11-19 13:18:30 -08:00
|
|
|
},
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
_populateConstants: function () {
|
|
|
|
let m = this.getMeasurement(SysInfoMeasurement.prototype.name,
|
|
|
|
SysInfoMeasurement.prototype.version);
|
2012-11-19 13:18:30 -08:00
|
|
|
|
|
|
|
let si = Cc["@mozilla.org/system-info;1"]
|
|
|
|
.getService(Ci.nsIPropertyBag2);
|
|
|
|
|
|
|
|
for (let [k, v] in Iterator(this.sysInfoFields)) {
|
|
|
|
try {
|
|
|
|
if (!si.hasKey(k)) {
|
|
|
|
this._log.debug("Property not available: " + k);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
let value = si.getProperty(k);
|
2013-01-06 12:13:27 -08:00
|
|
|
let method = "setLastText";
|
2012-11-19 13:18:30 -08:00
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
if (["cpucount", "memsize"].indexOf(k) != -1) {
|
2012-11-19 13:18:30 -08:00
|
|
|
let converted = parseInt(value, 10);
|
|
|
|
if (Number.isNaN(converted)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
value = converted;
|
2013-01-06 12:13:27 -08:00
|
|
|
method = "setLastNumeric";
|
2012-11-19 13:18:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Round memory to mebibytes.
|
|
|
|
if (k == "memsize") {
|
|
|
|
value = Math.round(value / 1048576);
|
|
|
|
}
|
|
|
|
|
2013-01-06 12:13:27 -08:00
|
|
|
yield m[method](v, value);
|
2012-11-19 13:18:30 -08:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Error obtaining system info field: " + k + " " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2013-01-06 12:13:27 -08:00
|
|
|
});
|
2012-11-19 13:18:30 -08:00
|
|
|
|