Bug 1493445 - Add telemetry to improve the understanding of current "about:config" usage patterns. r=paolo
authorLuke Schwalfenberg <lschwalfenberg@gmail.com>
Wed, 17 Oct 2018 10:44:24 +0100
changeset 490037 200b836d3aa5a1375edebcec36f8afa3c0cb24c0
parent 490036 2c633215c5148a0ea416237b749032e44e7708fb
child 490038 7a7d5508f873579944aee993dbf0007a5503f94f
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewerspaolo
bugs1493445
milestone64.0a1
Bug 1493445 - Add telemetry to improve the understanding of current "about:config" usage patterns. r=paolo Differential Revision: https://phabricator.services.mozilla.com/D8802
toolkit/components/telemetry/Histograms.json
toolkit/components/viewconfig/content/config.js
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -48,16 +48,25 @@
     "alert_emails": ["asurkov@mozilla.com"],
     "bug_numbers": [1424768],
     "expires_in_version": "never",
     "description": "The amount of time taken to update the accessibility tree (ms)",
     "kind" : "exponential",
     "high": 60000,
     "n_buckets": 50
   },
+  "ABOUT_CONFIG_FEATURES_USAGE": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["pamadini@mozilla.com"],
+    "expires_in_version": "67",
+    "kind": "categorical",
+    "labels": ["Show", "Search", "RegexSearch", "SortByName", "SortByStatus", "SortByType", "SortByValue", "ModifyValue", "Copy", "CopyName", "CopyValue", "CreateNew", "Reset"],
+    "bug_numbers": [1493445],
+    "description": "Record number of times particular features on about:config are used"
+  },
   "ADDON_MANAGER_UPGRADE_UI_SHOWN": {
     "record_in_processes": ["main", "content"],
     "expires_in_version": "53",
     "kind": "count",
     "description": "Recorded when the addon manager shows the modal upgrade UI. Should only be recorded once per upgrade.",
     "releaseChannelCollection": "opt-out",
     "bug_numbers": [1268548],
     "alert_emails": ["kev@mozilla.com"]
--- a/toolkit/components/viewconfig/content/config.js
+++ b/toolkit/components/viewconfig/content/config.js
@@ -28,16 +28,18 @@ const PREF_IS_LOCKED = 2;
 var gPrefHash = {};
 var gPrefArray = [];
 var gPrefView = gPrefArray; // share the JS array
 var gSortedColumn = "prefCol";
 var gSortFunction = null;
 var gSortDirection = 1; // 1 is ascending; -1 is descending
 var gFilter = null;
 
+let gCategoriesRecordedOnce = new Set();
+
 var view = {
   get rowCount() { return gPrefView.length; },
   getCellText(index, col) {
     if (!(index in gPrefView))
       return "";
 
     var value = gPrefView[index][col.id];
 
@@ -69,16 +71,17 @@ var view = {
   setTree(out) { this.treebox = out; },
   getParentIndex(rowIndex) { return -1; },
   hasNextSibling(rowIndex, afterIndex) { return false; },
   getLevel(index) { return 1; },
   getImageSrc(row, col) { return ""; },
   toggleOpenState(index) {},
   cycleHeader(col) {
     var index = this.selection.currentIndex;
+    recordTelemetryOnce(gCategoryLabelForSortColumn[col.id]);
     if (col.id == gSortedColumn) {
       gSortDirection = -gSortDirection;
       gPrefArray.reverse();
       if (gPrefView != gPrefArray)
         gPrefView.reverse();
       if (index >= 0)
         index = gPrefView.length - index - 1;
     } else {
@@ -326,16 +329,17 @@ async function onConfigLoad() {
   if (showWarning)
     document.getElementById("warningButton").focus();
   else
     ShowPrefs();
 }
 
 // Unhide the warning message
 function ShowPrefs() {
+  recordTelemetryOnce("Show");
   gPrefBranch.getChildList("").forEach(fetchPref);
 
   var descending = document.getElementsByAttribute("sortDirection", "descending");
   if (descending.item(0)) {
     gSortedColumn = descending[0].id;
     gSortDirection = -1;
   } else {
     var ascending = document.getElementsByAttribute("sortDirection", "ascending");
@@ -385,23 +389,25 @@ function onConfigUnload() {
 function FilterPrefs() {
   if (document.getElementById("configDeck").getAttribute("selectedIndex") != 1) {
     return;
   }
 
   var substring = document.getElementById("textbox").value;
   // Check for "/regex/[i]"
   if (substring.charAt(0) == "/") {
+    recordTelemetryOnce("RegexSearch");
     var r = substring.match(/^\/(.*)\/(i?)$/);
     try {
       gFilter = RegExp(r[1], r[2]);
     } catch (e) {
       return; // Do nothing on incomplete or bad RegExp
     }
   } else if (substring) {
+    recordTelemetryOnce("Search");
     gFilter = RegExp(substring.replace(/([^* \w])/g, "\\$1")
                               .replace(/^\*+/, "").replace(/\*+/g, ".*"), "i");
   } else {
     gFilter = null;
   }
 
   var prefCol = (view.selection && view.selection.currentIndex < 0) ?
                 null : gPrefView[view.selection.currentIndex].prefCol;
@@ -449,16 +455,23 @@ function valueColSortFunction(x, y) {
 const gSortFunctions =
 {
   prefCol: prefColSortFunction,
   lockCol: lockColSortFunction,
   typeCol: typeColSortFunction,
   valueCol: valueColSortFunction,
 };
 
+const gCategoryLabelForSortColumn = {
+  prefCol: "SortByName",
+  lockCol: "SortByStatus",
+  typeCol: "SortByType",
+  valueCol: "SortByValue",
+};
+
 const configController = {
   supportsCommand: function supportsCommand(command) {
     return command == "cmd_copy";
   },
   isCommandEnabled: function isCommandEnabled(command) {
     return view.selection && view.selection.currentIndex >= 0;
   },
   doCommand: function doCommand(command) {
@@ -504,39 +517,45 @@ function updateContextMenu() {
   modifySelected.hidden = canToggle;
 
   var toggleSelected = document.getElementById("toggleSelected");
   toggleSelected.setAttribute("disabled", isLocked);
   toggleSelected.hidden = !canToggle;
 }
 
 function copyPref() {
+  recordTelemetryOnce("Copy");
   var pref = gPrefView[view.selection.currentIndex];
   gClipboardHelper.copyString(pref.prefCol + ";" + pref.valueCol);
 }
 
 function copyName() {
+  recordTelemetryOnce("CopyName");
   gClipboardHelper.copyString(gPrefView[view.selection.currentIndex].prefCol);
 }
 
 function copyValue() {
+  recordTelemetryOnce("CopyValue");
   gClipboardHelper.copyString(gPrefView[view.selection.currentIndex].valueCol);
 }
 
 function ModifySelected() {
+  recordTelemetryOnce("ModifyValue");
   if (view.selection.currentIndex >= 0)
     ModifyPref(gPrefView[view.selection.currentIndex]);
 }
 
 function ResetSelected() {
+  recordTelemetryOnce("Reset");
   var entry = gPrefView[view.selection.currentIndex];
   gPrefBranch.clearUserPref(entry.prefCol);
 }
 
 async function NewPref(type) {
+  recordTelemetryOnce("CreateNew");
   var result = { value: "" };
   var dummy = { value: 0 };
 
   let [newTitle, newPrompt] = await document.l10n.formatValues([
     {id: "config-new-title", args: {type: gTypeStrs[type]} },
     {id: "config-new-prompt"}]);
 
   if (Services.prompt.prompt(window,
@@ -604,8 +623,18 @@ async function ModifyPref(entry) {
     } else {
       gPrefBranch.setStringPref(entry.prefCol, result.value);
     }
   }
 
   Services.prefs.savePrefFile(null);
   return true;
 }
+
+function recordTelemetryOnce(categoryLabel) {
+  if (!gCategoriesRecordedOnce.has(categoryLabel)) {
+    // Don't raise an exception if Telemetry is not available.
+    try {
+      Services.telemetry.getHistogramById("ABOUT_CONFIG_FEATURES_USAGE").add(categoryLabel);
+    } catch (ex) {}
+    gCategoriesRecordedOnce.add(categoryLabel);
+  }
+}