Bug 1305444 - Move telemetry assignment, remove variable use; r?Yoric draft
authorGregory Szorc <gps@mozilla.com>
Sat, 24 Sep 2016 17:18:21 -0700
changeset 417658 d4c60188e82c85d8d324706961ecc56b09838b4b
parent 417383 29beaebdfaccbdaeb4c1ee5a43a9795ab015ef49
child 417659 e2bf76dd2b69a5f1d845c6b49124048f78cced37
push id30450
push userbmo:gps@mozilla.com
push dateMon, 26 Sep 2016 15:33:36 +0000
reviewersYoric
bugs1305444
milestone52.0a1
Bug 1305444 - Move telemetry assignment, remove variable use; r?Yoric We have an unused "telemetry" variable. Use this variable and move the telemetry assignment to immediately after the operation it is recording. While I was here, I also cleaned up the timing variables. I eliminated the end time variable and moved the declaration of the start time variable so its scope is shorter. MozReview-Commit-ID: IbGOK5pPkcR
browser/components/sessionstore/SessionWorker.js
--- a/browser/components/sessionstore/SessionWorker.js
+++ b/browser/components/sessionstore/SessionWorker.js
@@ -145,34 +145,33 @@ var Agent = {
           tab.entries = tab.entries.slice(lower, upper);
           tab.index -= lower;
         }
       }
     }
 
     let stateString = JSON.stringify(state);
     let data = Encoder.encode(stateString);
-    let startWriteMs, stopWriteMs;
 
     try {
 
       if (this.state == STATE_CLEAN || this.state == STATE_EMPTY) {
         // The backups directory may not exist yet. In all other cases,
         // we have either already read from or already written to this
         // directory, so we are satisfied that it exists.
         File.makeDir(this.Paths.backups);
       }
 
       if (this.state == STATE_CLEAN) {
         // Move $Path.clean out of the way, to avoid any ambiguity as
         // to which file is more recent.
         File.move(this.Paths.clean, this.Paths.cleanBackup);
       }
 
-      startWriteMs = Date.now();
+      let startWriteMs = Date.now();
 
       if (options.isFinalWrite) {
         // We are shutting down. At this stage, we know that
         // $Paths.clean is either absent or corrupted. If it was
         // originally present and valid, it has been moved to
         // $Paths.cleanBackup a long time ago. We can therefore write
         // with the guarantees that we erase no important data.
         File.writeAtomic(this.Paths.clean, data, {
@@ -193,17 +192,18 @@ var Agent = {
         // In other cases, either $Path.recovery is not necessary, or
         // it doesn't exist or it has been corrupted. Regardless,
         // don't backup $Path.recovery.
         File.writeAtomic(this.Paths.recovery, data, {
           tmpPath: this.Paths.recovery + ".tmp"
         });
       }
 
-      stopWriteMs = Date.now();
+      telemetry[FX_SESSION_RESTORE_WRITE_FILE_MS] = Date.now() - startWriteMs;
+      telemetry[FX_SESSION_RESTORE_FILE_SIZE_BYTES] = data.byteLength;
 
     } catch (ex) {
       // Don't throw immediately
       exn = exn || ex;
     }
 
     // If necessary, perform an upgrade backup
     let upgradeBackupComplete = false;
@@ -271,20 +271,17 @@ var Agent = {
     if (exn) {
       throw exn;
     }
 
     return {
       result: {
         upgradeBackup: upgradeBackupComplete
       },
-      telemetry: {
-        FX_SESSION_RESTORE_WRITE_FILE_MS: stopWriteMs - startWriteMs,
-        FX_SESSION_RESTORE_FILE_SIZE_BYTES: data.byteLength,
-      }
+      telemetry: telemetry,
     };
   },
 
   /**
    * Wipes all files holding session data from disk.
    */
   wipe: function () {