Bug 695829 - Add telemetry metrics for private browsing transitions. r=ehsan

--HG--
rename : browser/components/privatebrowsing/test/unit/test_privatebrowsing_autostart.js => browser/components/privatebrowsing/test/unit/test_privatebrowsing_telemetry.js
rename : browser/components/privatebrowsing/test/unit/test_privatebrowsingwrapper_autostart.js => browser/components/privatebrowsing/test/unit/test_privatebrowsingwrapper_telemetry.js
This commit is contained in:
Paolo Amadini 2012-04-27 15:05:20 +02:00
parent dfd7155be0
commit b03aa5460e
6 changed files with 194 additions and 0 deletions

View File

@ -133,6 +133,10 @@ PrivateBrowsingService.prototype = {
// Whether private browsing has been turned on from the command line
_lastChangedByCommandLine: false,
// Telemetry measurements
_enterTimestamps: {},
_exitTimestamps: {},
// XPCOM registration
classID: Components.ID("{c31f4883-839b-45f6-82ad-a6a9bc5ad599}"),
@ -308,6 +312,7 @@ PrivateBrowsingService.prototype = {
// restore has been completed
this._currentStatus = STATE_IDLE;
this._obs.notifyObservers(null, "private-browsing-transition-complete", "");
this._recordTransitionTime("completed");
break;
case STATE_WAITING_FOR_RESTORE:
// too soon to notify...
@ -323,6 +328,51 @@ PrivateBrowsingService.prototype = {
}
},
_recordTransitionTime: function PBS__recordTransitionTime(aPhase) {
// To record the time spent in private browsing transitions, note that we
// cannot use the TelemetryStopwatch module, because it reports its results
// immediately when the timer is stopped. In this case, we need to delay
// the actual histogram update after we are out of private browsing mode.
if (this._inPrivateBrowsing) {
this._enterTimestamps[aPhase] = Date.now();
} else {
if (this._quitting) {
// If we are quitting the browser, we don't care collecting the data,
// because we wouldn't be able to record it with telemetry.
return;
}
this._exitTimestamps[aPhase] = Date.now();
if (aPhase == "completed") {
// After we finished exiting the private browsing mode, we can finally
// record the telemetry data, for the enter and the exit processes.
this._reportTelemetry();
}
}
},
_reportTelemetry: function PBS__reportTelemetry() {
function reportTelemetryEntry(aHistogramId, aValue) {
try {
Services.telemetry.getHistogramById(aHistogramId).add(aValue);
} catch (ex) {
Cu.reportError(ex);
}
}
reportTelemetryEntry(
"PRIVATE_BROWSING_TRANSITION_ENTER_PREPARATION_MS",
this._enterTimestamps.prepared - this._enterTimestamps.started);
reportTelemetryEntry(
"PRIVATE_BROWSING_TRANSITION_ENTER_TOTAL_MS",
this._enterTimestamps.completed - this._enterTimestamps.started);
reportTelemetryEntry(
"PRIVATE_BROWSING_TRANSITION_EXIT_PREPARATION_MS",
this._exitTimestamps.prepared - this._exitTimestamps.started);
reportTelemetryEntry(
"PRIVATE_BROWSING_TRANSITION_EXIT_TOTAL_MS",
this._exitTimestamps.completed - this._exitTimestamps.started);
},
_canEnterPrivateBrowsingMode: function PBS__canEnterPrivateBrowsingMode() {
let cancelEnter = Cc["@mozilla.org/supports-PRBool;1"].
createInstance(Ci.nsISupportsPRBool);
@ -537,6 +587,8 @@ PrivateBrowsingService.prototype = {
this._autoStarted = this._prefs.getBoolPref("browser.privatebrowsing.autostart");
this._inPrivateBrowsing = val != false;
this._recordTransitionTime("started");
let data = val ? "enter" : "exit";
let quitting = Cc["@mozilla.org/supports-PRBool;1"].
@ -551,6 +603,8 @@ PrivateBrowsingService.prototype = {
this._obs.notifyObservers(quitting, "private-browsing", data);
this._recordTransitionTime("prepared");
// load the appropriate session
this._onAfterPrivateBrowsingModeChange();
} catch (ex) {

View File

@ -0,0 +1,42 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
XPCOMUtils.defineLazyServiceGetter(this, "gPrivateBrowsing",
PRIVATEBROWSING_CONTRACT_ID,
"nsIPrivateBrowsingService");
function waitForTransition(aEnabled, aCallback) {
Services.obs.addObserver(function PBT_transition(aSubject, aTopic, aData) {
Services.obs.removeObserver(PBT_transition, aTopic, false);
// Telemetry data is recorded just after the private browsing transition
// observers are notified, thus we must wait for this observer to return.
do_execute_soon(aCallback);
}, "private-browsing-transition-complete", false);
gPrivateBrowsing.privateBrowsingEnabled = aEnabled;
}
function checkHistogram(aId) {
// Check that we have data either in the first bucket (that doesn't
// count towards the sum) or one of the other buckets, by checking
// the sum of the values.
let snapshot = Services.telemetry.getHistogramById(aId).snapshot();
do_check_true(snapshot.sum > 0 || snapshot.counts[0] > 0);
}
function do_test() {
do_test_pending();
waitForTransition(true, function PBT_enabled() {
waitForTransition(false, function PBT_disabled() {
checkHistogram("PRIVATE_BROWSING_TRANSITION_ENTER_PREPARATION_MS");
checkHistogram("PRIVATE_BROWSING_TRANSITION_ENTER_TOTAL_MS");
checkHistogram("PRIVATE_BROWSING_TRANSITION_EXIT_PREPARATION_MS");
checkHistogram("PRIVATE_BROWSING_TRANSITION_EXIT_TOTAL_MS");
do_test_finished();
});
});
}

View File

@ -0,0 +1,44 @@
/* ***** 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 Original Code is Private Browsing Tests.
*
* The Initial Developer of the Original Code is
* Ehsan Akhgari.
* Portions created by the Initial Developer are Copyright (C) 2008
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
// Checks that telemetry data for private browsing transitions is recorded.
function run_test() {
PRIVATEBROWSING_CONTRACT_ID = "@mozilla.org/privatebrowsing;1";
load("do_test_privatebrowsing_telemetry.js");
do_test();
}

View File

@ -0,0 +1,44 @@
/* ***** 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 Original Code is Private Browsing Tests.
*
* The Initial Developer of the Original Code is
* Ehsan Akhgari.
* Portions created by the Initial Developer are Copyright (C) 2009
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Ehsan Akhgari <ehsan.akhgari@gmail.com> (Original Author)
*
* Alternatively, the contents of this file may be used under the terms of
* either of 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 ***** */
// Checks that telemetry data for private browsing transitions is recorded.
function run_test() {
PRIVATEBROWSING_CONTRACT_ID = "@mozilla.org/privatebrowsing-wrapper;1";
load("do_test_privatebrowsing_telemetry.js");
do_test();
}

View File

@ -12,12 +12,14 @@ tail = tail_privatebrowsing.js
[test_privatebrowsing_autostart.js]
[test_privatebrowsing_commandline.js]
[test_privatebrowsing_exit.js]
[test_privatebrowsing_telemetry.js]
[test_privatebrowsingwrapper_autostart.js]
[test_privatebrowsingwrapper_commandline.js]
[test_privatebrowsingwrapper_exit.js]
[test_privatebrowsingwrapper_placesTitleNoUpdate.js]
[test_privatebrowsingwrapper_removeDataFromDomain.js]
[test_privatebrowsingwrapper_removeDataFromDomain_activeDownloads.js]
[test_privatebrowsingwrapper_telemetry.js]
[test_removeDataFromDomain.js]
[test_removeDataFromDomain_activeDownloads.js]
[test_transition_nooffline.js]

View File

@ -395,6 +395,14 @@ HISTOGRAM(XUL_INITIAL_FRAME_CONSTRUCTION, 1, 3000, 10, EXPONENTIAL, "initial xul
HISTOGRAM_BOOLEAN(XMLHTTPREQUEST_ASYNC_OR_SYNC, "Type of XMLHttpRequest, async or sync")
HISTOGRAM_BOOLEAN(MULTIPART_XHR_RESPONSE, "XMLHttpRequest response was of type multipart/x-mixed-replace.")
/**
* Private browsing transition telemetry.
*/
HISTOGRAM(PRIVATE_BROWSING_TRANSITION_ENTER_PREPARATION_MS, 1, 3000, 10, EXPONENTIAL, "Time spent on private browsing enter transition, excluding session restore (ms)")
HISTOGRAM(PRIVATE_BROWSING_TRANSITION_ENTER_TOTAL_MS, 1, 10000, 50, EXPONENTIAL, "Time spent on private browsing enter transition, including session restore (ms)")
HISTOGRAM(PRIVATE_BROWSING_TRANSITION_EXIT_PREPARATION_MS, 1, 3000, 10, EXPONENTIAL, "Time spent on private browsing exit transition, excluding session restore (ms)")
HISTOGRAM(PRIVATE_BROWSING_TRANSITION_EXIT_TOTAL_MS, 1, 10000, 50, EXPONENTIAL, "Time spent on private browsing exit transition, including session restore (ms)")
/**
* DOM telemetry.
*/