Bug 732874 - Telemetry stopwatch: key was already initialized errors in logs. r=felipc

This commit is contained in:
Andres Hernandez 2012-09-26 14:21:28 -06:00
parent 7f0785e84a
commit 6553a87a24
3 changed files with 52 additions and 4 deletions

View File

@ -3651,8 +3651,10 @@ let SessionStoreInternal = {
TelemetryStopwatch.start("FX_SESSION_RESTORE_COLLECT_DATA_MS");
var oState = this._getCurrentState(aUpdateAll, pinnedOnly);
if (!oState)
if (!oState) {
TelemetryStopwatch.cancel("FX_SESSION_RESTORE_COLLECT_DATA_MS");
return;
}
#ifndef XP_MACOSX
// We want to restore closed windows that are marked with _shouldRestore.
@ -4429,7 +4431,8 @@ let SessionStoreInternal = {
* String data
*/
_writeFile: function ssi_writeFile(aFile, aData) {
TelemetryStopwatch.start("FX_SESSION_RESTORE_WRITE_FILE_MS");
let refObj = {};
TelemetryStopwatch.start("FX_SESSION_RESTORE_WRITE_FILE_MS", refObj);
// Initialize the file output stream.
var ostream = Cc["@mozilla.org/network/safe-file-output-stream;1"].
createInstance(Ci.nsIFileOutputStream);
@ -4445,7 +4448,7 @@ let SessionStoreInternal = {
var self = this;
NetUtil.asyncCopy(istream, ostream, function(rc) {
if (Components.isSuccessCode(rc)) {
TelemetryStopwatch.finish("FX_SESSION_RESTORE_WRITE_FILE_MS");
TelemetryStopwatch.finish("FX_SESSION_RESTORE_WRITE_FILE_MS", refObj);
Services.obs.notifyObservers(null,
"sessionstore-state-write-complete",
"");

View File

@ -58,6 +58,38 @@ let TelemetryStopwatch = {
return true;
},
/**
* Deletes the timer associated with a telemetry histogram. The timer can be
* directly associated with a histogram, or with a pair of a histogram and
* an object. Important: Only use this method when a legitimate cancellation
* should be done.
*
* @param aHistogram a string which must be a valid histogram name
* from TelemetryHistograms.json
*
* @param aObj Optional parameter. If specified, the timer is associated
* with this object, meaning that multiple timers for a same
* histogram may be run concurrently, as long as they are
* associated with different objects.
*
* @return true if the timer exist and it was cleared, false otherwise.
*/
cancel: function ts_cancel(aHistogram, aObj) {
if (!validTypes(aHistogram, aObj))
return false;
let timers = aObj
? objectTimers.get(aObj, {})
: simpleTimers;
if (timers.hasOwnProperty(aHistogram)) {
delete timers[aHistogram];
return true;
}
return false;
},
/**
* Stops the timer associated with the given histogram (and object),
* calculates the time delta between start and finish, and adds the value

View File

@ -86,11 +86,24 @@ function run_test() {
do_check_true(TelemetryStopwatch.finish(HIST_NAME));
do_check_true(TelemetryStopwatch.finish(HIST_NAME, refObj));
do_check_false(TelemetryStopwatch.finish("unknown-mark")); // Unknown marker
do_check_false(TelemetryStopwatch.finish("unknown-mark", {})); // Unknown object
do_check_false(TelemetryStopwatch.finish(HIST_NAME, {})); // Known mark on unknown object
// Test cancel
do_check_true(TelemetryStopwatch.start(HIST_NAME));
do_check_true(TelemetryStopwatch.start(HIST_NAME, refObj));
do_check_true(TelemetryStopwatch.cancel(HIST_NAME));
do_check_true(TelemetryStopwatch.cancel(HIST_NAME, refObj));
// Verify that can not cancel twice
do_check_false(TelemetryStopwatch.cancel(HIST_NAME));
do_check_false(TelemetryStopwatch.cancel(HIST_NAME, refObj));
// Verify that cancel removes the timers
do_check_false(TelemetryStopwatch.finish(HIST_NAME));
do_check_false(TelemetryStopwatch.finish(HIST_NAME, refObj));
finishTest();
}