Bug 828546 - Part 2: Health Report probe for Places data; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Tue, 05 Feb 2013 10:44:33 -0800
changeset 120998 e2e1ea12ddc9a0563647215394ebacd662fb4434
parent 120997 4654abd41ddf4fa5198f6f393fdf23c0a577df34
child 120999 54686023b7f12b32ef39cee8d43fd4210bc665de
push id22524
push userryanvm@gmail.com
push dateWed, 06 Feb 2013 13:23:43 +0000
treeherdermozilla-inbound@470187171cf1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs828546
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 828546 - Part 2: Health Report probe for Places data; r=rnewman
services/healthreport/HealthReport.jsm
services/healthreport/HealthReportComponents.manifest
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_provider_places.js
services/healthreport/tests/xpcshell/xpcshell.ini
--- a/services/healthreport/HealthReport.jsm
+++ b/services/healthreport/HealthReport.jsm
@@ -5,16 +5,17 @@
 "use strict";
 
 this.EXPORTED_SYMBOLS = [
   "HealthReporter",
   "AddonsProvider",
   "AppInfoProvider",
   "CrashesProvider",
   "Metrics",
+  "PlacesProvider",
   "ProfileMetadataProvider",
   "SessionsProvider",
   "SysInfoProvider",
 ];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
--- a/services/healthreport/HealthReportComponents.manifest
+++ b/services/healthreport/HealthReportComponents.manifest
@@ -1,8 +1,9 @@
 # Register Firefox Health Report providers.
 category healthreport-js-provider AddonsProvider resource://gre/modules/HealthReport.jsm
 category healthreport-js-provider AppInfoProvider resource://gre/modules/HealthReport.jsm
 category healthreport-js-provider CrashesProvider resource://gre/modules/HealthReport.jsm
 category healthreport-js-provider SysInfoProvider resource://gre/modules/HealthReport.jsm
 category healthreport-js-provider ProfileMetadataProvider resource://gre/modules/HealthReport.jsm
 category healthreport-js-provider SessionsProvider resource://gre/modules/HealthReport.jsm
+category healthreport-js-provider PlacesProvider resource://gre/modules/HealthReport.jsm
 
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -16,16 +16,17 @@
 
 #ifndef MERGED_COMPARTMENT
 
 this.EXPORTED_SYMBOLS = [
   "AddonsProvider",
   "AppInfoProvider",
   "CrashDirectoryService",
   "CrashesProvider",
+  "PlacesProvider",
   "SessionsProvider",
   "SysInfoProvider",
 ];
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Metrics.jsm");
 
@@ -38,16 +39,19 @@ Cu.import("resource://gre/modules/Task.j
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://services-common/preferences.js");
 Cu.import("resource://services-common/utils.js");
 
 XPCOMUtils.defineLazyModuleGetter(this, "AddonManager",
                                   "resource://gre/modules/AddonManager.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
                                   "resource://gre/modules/UpdateChannel.jsm");
+XPCOMUtils.defineLazyModuleGetter(this, "PlacesDBUtils",
+                                  "resource://gre/modules/PlacesDBUtils.jsm");
+
 
 /**
  * Represents basic application state.
  *
  * This is roughly a union of nsIXULAppInfo, nsIXULRuntime, with a few extra
  * pieces thrown in.
  */
 function AppInfoMeasurement() {
@@ -883,8 +887,70 @@ CrashDirectoryService.prototype = Object
         throw new Task.Result(files);
       } finally {
         iterator.close();
       }
     });
   },
 });
 
+
+/**
+ * Holds basic statistics about the Places database.
+ */
+function PlacesMeasurement() {
+  Metrics.Measurement.call(this);
+}
+
+PlacesMeasurement.prototype = Object.freeze({
+  __proto__: Metrics.Measurement.prototype,
+
+  name: "places",
+  version: 1,
+
+  configureStorage: function () {
+    return Task.spawn(function registerFields() {
+      yield this.registerStorageField("pages", this.storage.FIELD_DAILY_LAST_NUMERIC);
+      yield this.registerStorageField("bookmarks", this.storage.FIELD_DAILY_LAST_NUMERIC);
+    }.bind(this));
+  },
+});
+
+
+/**
+ * Collects information about Places.
+ */
+this.PlacesProvider = function () {
+  Metrics.Provider.call(this);
+};
+
+PlacesProvider.prototype = Object.freeze({
+  __proto__: Metrics.Provider.prototype,
+
+  name: "org.mozilla.places",
+
+  measurementTypes: [PlacesMeasurement],
+
+  collectDailyData: function () {
+    return this.storage.enqueueTransaction(this._collectData.bind(this));
+  },
+
+  _collectData: function () {
+    let now = new Date();
+    let data = yield this._getDailyValues();
+
+    let m = this.getMeasurement("places", 1);
+
+    yield m.setDailyLastNumeric("pages", data.PLACES_PAGES_COUNT);
+    yield m.setDailyLastNumeric("bookmarks", data.PLACES_BOOKMARKS_COUNT);
+  },
+
+  _getDailyValues: function () {
+    let deferred = Promise.defer();
+
+    PlacesDBUtils.telemetry(null, function onResult(data) {
+      deferred.resolve(data);
+    });
+
+    return deferred.promise;
+  },
+});
+
new file mode 100644
--- /dev/null
+++ b/services/healthreport/tests/xpcshell/test_provider_places.js
@@ -0,0 +1,46 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+const {utils: Cu} = Components;
+
+Cu.import("resource://gre/modules/Metrics.jsm");
+Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
+
+
+function run_test() {
+  run_next_test();
+}
+
+add_test(function test_constructor() {
+  let provider = new PlacesProvider();
+
+  run_next_test();
+});
+
+add_task(function test_collect_smoketest() {
+  let storage = yield Metrics.Storage("collect_smoketest");
+  let provider = new PlacesProvider();
+
+  yield provider.init(storage);
+
+  let now = new Date();
+  yield provider.collectDailyData();
+
+  let m = provider.getMeasurement("places", 1);
+  let data = yield storage.getMeasurementValues(m.id);
+  do_check_eq(data.days.size, 1);
+  do_check_true(data.days.hasDay(now));
+
+  let serializer = m.serializer(m.SERIALIZE_JSON);
+  let day = serializer.daily(data.days.getDay(now));
+
+  do_check_eq(day._v, 1);
+  do_check_eq(Object.keys(day).length, 3);
+  do_check_eq(day.pages, 0);
+  do_check_eq(day.bookmarks, 0);
+
+  yield storage.close();
+});
+
--- a/services/healthreport/tests/xpcshell/xpcshell.ini
+++ b/services/healthreport/tests/xpcshell/xpcshell.ini
@@ -3,11 +3,12 @@ head = head.js
 tail =
 
 [test_load_modules.js]
 [test_profile.js]
 [test_healthreporter.js]
 [test_provider_addons.js]
 [test_provider_appinfo.js]
 [test_provider_crashes.js]
+[test_provider_places.js]
 [test_provider_sysinfo.js]
 [test_provider_sessions.js]