Bug 1179732 - Make tresize dump multiprocess profiles draft
authorMike Conley <mconley@mozilla.com>
Thu, 17 Dec 2015 16:50:57 -0500
changeset 316068 5017b17935d103462f5b9d244f9e59dcbfb1091e
parent 316066 02a8e13a34fb6abe9e5496301f8a7e6fdeb4e392
child 512130 66a2f6f7bd6ce85b9c5087b98bdbd44eec6866b5
push id8513
push usermconley@mozilla.com
push dateThu, 17 Dec 2015 21:52:13 +0000
bugs1179732
milestone45.0a1
Bug 1179732 - Make tresize dump multiprocess profiles
testing/talos/talos/startup_test/tresize/addon/content/Profiler.js
testing/talos/talos/startup_test/tresize/addon/content/tresize.js
--- a/testing/talos/talos/startup_test/tresize/addon/content/Profiler.js
+++ b/testing/talos/talos/startup_test/tresize/addon/content/Profiler.js
@@ -14,16 +14,18 @@
 
 // Finer grained profiler control
 //
 // Use this object to pause and resume the profiler so that it only profiles the
 // relevant parts of our tests.
 var Profiler;
 
 (function(){
+  Components.utils.import("resource://gre/modules/osfile.jsm");
+
   var _profiler;
 
   // If this script is loaded in a framescript context, there won't be a
   // document object, so just use a fallback value in that case.
   var test_name = this.document ? this.document.location.pathname : "unknown";
 
   // Whether Profiler has been initialized. Until that happens, most calls
   // will be ignored.
@@ -94,20 +96,35 @@ var Profiler;
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
     finishTest: function Profiler__finishTest () {
-      if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
-      }
+      return new Promise((resolve) => {
+        let profileFile = profiler_dir + "/" + currentTest + ".sps";
+
+        _profiler.getProfileDataAsync().then((profile) => {
+          let encoder = new TextEncoder();
+          let array = encoder.encode(JSON.stringify(profile));
+
+          OS.File.writeAtomic(profileFile, array, {
+            tmpPath: profileFile + ".tmp",
+          }).then(() => {
+            _profiler.StopProfiler();
+            resolve();
+          });
+        }, (error) => {
+          Cu.reportError("Failed to gather profile: " + error);
+          // FIXME: We should probably send a message down to the
+          // child which causes it to reject the waiting Promise.
+        });
+      });
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
     resume: function Profiler__resume (name, explicit) {
--- a/testing/talos/talos/startup_test/tresize/addon/content/tresize.js
+++ b/testing/talos/talos/startup_test/tresize/addon/content/tresize.js
@@ -30,33 +30,34 @@ function resizeTest() {
     Profiler.resume("resize " + count);
     dataSet[count] = {'start': window.performance.now()};
     window.resizeTo(windowSize,windowSize);
   } catch(ex) { finish([ex + '\n']); }
 }
 
 function testCompleted() {
   try {
-    Profiler.finishTest();
-    var total = 0;
-    var diffs = [];
-    for (var idx = 0; idx < count; idx++) {
-      var diff = dataSet[idx].end - dataSet[idx].start;
-      total += diff;
-      diffs.push(diff);
-    }
-    var average = (total/count);
-    var retVal = [];
-    if (dumpDataSet) {
-      retVal.push('__start_reporttresize-test.html,' + diffs + '__end_report\n');
-    } else {
-      retVal.push('__start_report' + average + '__end_report\n');
-    }
-    retVal.push('__startTimestamp' + Date.now() + '__endTimestamp\n');
-    finish(retVal);
+    Profiler.finishTest().then(() => {
+      var total = 0;
+      var diffs = [];
+      for (var idx = 0; idx < count; idx++) {
+        var diff = dataSet[idx].end - dataSet[idx].start;
+        total += diff;
+        diffs.push(diff);
+      }
+      var average = (total/count);
+      var retVal = [];
+      if (dumpDataSet) {
+        retVal.push('__start_reporttresize-test.html,' + diffs + '__end_report\n');
+      } else {
+        retVal.push('__start_report' + average + '__end_report\n');
+      }
+      retVal.push('__startTimestamp' + Date.now() + '__endTimestamp\n');
+      finish(retVal);
+    });
   } catch(ex) { finish([ex + '\n']); }
 }
 
 function resizeCompleted() {
   count++;
   if (count >= max) {
     testCompleted();
   } else {