Bug 1182595 - Make profile dumping work with e10s. r?jmaher draft
authorMike Conley <mconley@mozilla.com>
Mon, 13 Jul 2015 15:30:07 -0400
changeset 968 3759cad0f5eb98a066fe8e81992300e284f4b4e4
parent 967 fcf766da6a45fa2502e1f8eeb3384c97b7d7ed91
child 969 13ee1d32a925604df1b9bda1f42f9f8609dfc0f2
push id5
push usermconley@mozilla.com
push dateMon, 20 Jul 2015 16:38:00 +0000
reviewersjmaher
bugs1182595
Bug 1182595 - Make profile dumping work with e10s. r?jmaher
talos/page_load_test/devtools/addon/content/Profiler.js
talos/page_load_test/tart/addon/content/Profiler.js
talos/pageloader/chrome/Profiler.js
talos/pageloader/chrome/pageloader.js
talos/scripts/Profiler.js
talos/startup_test/tresize/addon/content/Profiler.js
talos/ttest.py
--- a/talos/page_load_test/devtools/addon/content/Profiler.js
+++ b/talos/page_load_test/devtools/addon/content/Profiler.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
 // - NOTE: This file is duplicated verbatim at:
 //         - talos/scripts/Profiler.js
 //         - talos/pageloader/chrome/Profiler.js
 //         - talos/page_load_test/devtools/addon/content/Profiler.js
 //         - talos/page_load_test/tart/addon/content/Profiler.js
 //         - talos/startup_test/tresize/addon/content/Profiler.js
 //
 //  - Please keep these copies in sync.
@@ -93,20 +96,33 @@ var Profiler;
         _profiler.StartProfiler(profiler_entries, profiler_interval,
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
+
+    writeToDisk: function Profiler__writeToDisk(filename, profile) {
+      let encoder = new TextEncoder();
+      let array = encoder.encode(JSON.stringify(profile));
+      return OS.File.writeAtomic(filename, array, {
+        tmpPath: filename + ".tmp",
+      });
+    },
+
     finishTest: function Profiler__finishTest () {
+      let self = this;
       if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
+        return Task.spawn(function*() {
+          let profile = yield _profiler.getProfileDataAsync();
+          yield self.writeToDisk(profiler_dir + "/" + currentTest + ".sps", profile);
+          _profiler.StopProfiler();
+        });
       }
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
--- a/talos/page_load_test/tart/addon/content/Profiler.js
+++ b/talos/page_load_test/tart/addon/content/Profiler.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
 // - NOTE: This file is duplicated verbatim at:
 //         - talos/scripts/Profiler.js
 //         - talos/pageloader/chrome/Profiler.js
 //         - talos/page_load_test/devtools/addon/content/Profiler.js
 //         - talos/page_load_test/tart/addon/content/Profiler.js
 //         - talos/startup_test/tresize/addon/content/Profiler.js
 //
 //  - Please keep these copies in sync.
@@ -93,20 +96,33 @@ var Profiler;
         _profiler.StartProfiler(profiler_entries, profiler_interval,
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
+
+    writeToDisk: function Profiler__writeToDisk(filename, profile) {
+      let encoder = new TextEncoder();
+      let array = encoder.encode(JSON.stringify(profile));
+      return OS.File.writeAtomic(filename, array, {
+        tmpPath: filename + ".tmp",
+      });
+    },
+
     finishTest: function Profiler__finishTest () {
+      let self = this;
       if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
+        return Task.spawn(function*() {
+          let profile = yield _profiler.getProfileDataAsync();
+          yield self.writeToDisk(profiler_dir + "/" + currentTest + ".sps", profile);
+          _profiler.StopProfiler();
+        });
       }
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
--- a/talos/pageloader/chrome/Profiler.js
+++ b/talos/pageloader/chrome/Profiler.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
 // - NOTE: This file is duplicated verbatim at:
 //         - talos/scripts/Profiler.js
 //         - talos/pageloader/chrome/Profiler.js
 //         - talos/page_load_test/devtools/addon/content/Profiler.js
 //         - talos/page_load_test/tart/addon/content/Profiler.js
 //         - talos/startup_test/tresize/addon/content/Profiler.js
 //
 //  - Please keep these copies in sync.
@@ -93,20 +96,33 @@ var Profiler;
         _profiler.StartProfiler(profiler_entries, profiler_interval,
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
+
+    writeToDisk: function Profiler__writeToDisk(filename, profile) {
+      let encoder = new TextEncoder();
+      let array = encoder.encode(JSON.stringify(profile));
+      return OS.File.writeAtomic(filename, array, {
+        tmpPath: filename + ".tmp",
+      });
+    },
+
     finishTest: function Profiler__finishTest () {
+      let self = this;
       if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
+        return Task.spawn(function*() {
+          let profile = yield _profiler.getProfileDataAsync();
+          yield self.writeToDisk(profiler_dir + "/" + currentTest + ".sps", profile);
+          _profiler.StopProfiler();
+        });
       }
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
--- a/talos/pageloader/chrome/pageloader.js
+++ b/talos/pageloader/chrome/pageloader.js
@@ -423,17 +423,17 @@ function loadFail() {
 
 let plNextPage = Task.async(function*() {
   var doNextPage = false;
   if (pageCycle < numPageCycles) {
     pageCycle++;
     doNextPage = true;
   } else {
     if (profilingInfo) {
-      Profiler.finishTest();
+      yield Profiler.finishTest();
     }
 
     if (pageIndex < pages.length-1) {
       pageIndex++;
       if (profilingInfo) {
         Profiler.beginTest(getCurrentPageShortName());
       }
       recordedName = null;
--- a/talos/scripts/Profiler.js
+++ b/talos/scripts/Profiler.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
 // - NOTE: This file is duplicated verbatim at:
 //         - talos/scripts/Profiler.js
 //         - talos/pageloader/chrome/Profiler.js
 //         - talos/page_load_test/devtools/addon/content/Profiler.js
 //         - talos/page_load_test/tart/addon/content/Profiler.js
 //         - talos/startup_test/tresize/addon/content/Profiler.js
 //
 //  - Please keep these copies in sync.
@@ -93,20 +96,33 @@ var Profiler;
         _profiler.StartProfiler(profiler_entries, profiler_interval,
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
+
+    writeToDisk: function Profiler__writeToDisk(filename, profile) {
+      let encoder = new TextEncoder();
+      let array = encoder.encode(JSON.stringify(profile));
+      return OS.File.writeAtomic(filename, array, {
+        tmpPath: filename + ".tmp",
+      });
+    },
+
     finishTest: function Profiler__finishTest () {
+      let self = this;
       if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
+        return Task.spawn(function*() {
+          let profile = yield _profiler.getProfileDataAsync();
+          yield self.writeToDisk(profiler_dir + "/" + currentTest + ".sps", profile);
+          _profiler.StopProfiler();
+        });
       }
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
--- a/talos/startup_test/tresize/addon/content/Profiler.js
+++ b/talos/startup_test/tresize/addon/content/Profiler.js
@@ -1,12 +1,15 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+Components.utils.import("resource://gre/modules/Task.jsm");
+Components.utils.import("resource://gre/modules/osfile.jsm");
+
 // - NOTE: This file is duplicated verbatim at:
 //         - talos/scripts/Profiler.js
 //         - talos/pageloader/chrome/Profiler.js
 //         - talos/page_load_test/devtools/addon/content/Profiler.js
 //         - talos/page_load_test/tart/addon/content/Profiler.js
 //         - talos/startup_test/tresize/addon/content/Profiler.js
 //
 //  - Please keep these copies in sync.
@@ -93,20 +96,33 @@ var Profiler;
         _profiler.StartProfiler(profiler_entries, profiler_interval,
                                 ["js", "leaf", "stackwalk", "threads"], 4,
                                 profiler_threadsArray, profiler_threadsArray.length);
         if (_profiler.PauseSampling) {
           _profiler.PauseSampling();
         }
       }
     },
+
+    writeToDisk: function Profiler__writeToDisk(filename, profile) {
+      let encoder = new TextEncoder();
+      let array = encoder.encode(JSON.stringify(profile));
+      return OS.File.writeAtomic(filename, array, {
+        tmpPath: filename + ".tmp",
+      });
+    },
+
     finishTest: function Profiler__finishTest () {
+      let self = this;
       if (_profiler && enabled) {
-        _profiler.dumpProfileToFile(profiler_dir + "/" + currentTest + ".sps");
-        _profiler.StopProfiler();
+        return Task.spawn(function*() {
+          let profile = yield _profiler.getProfileDataAsync();
+          yield self.writeToDisk(profiler_dir + "/" + currentTest + ".sps", profile);
+          _profiler.StopProfiler();
+        });
       }
     },
     finishStartupProfiling: function Profiler__finishStartupProfiling () {
       if (_profiler && enabled) {
         _profiler.dumpProfileToFile(profiler_dir + "/startup.sps");
         _profiler.StopProfiler();
       }
     },
--- a/talos/ttest.py
+++ b/talos/ttest.py
@@ -617,16 +617,17 @@ class TTest(object):
                                      counter_results=self.counter_results)
                 except Exception as e:
                     # Log the exception, but continue. One way to get here
                     # is if the browser hangs, and we'd still like to get
                     # symbolicated profiles in that case.
                     mozlog.info(e)
 
                 if sps_profile:
+                    mozlog.info("Getting profile symbols")
                     symbolicator = symbolication.ProfileSymbolicator({
                         # Trace-level logging (verbose)
                         "enableTracing": 0,
                         # Fallback server if symbol is not found locally
                         "remoteSymbolServer":
                             "http://symbolapi.mozilla.org:80/",
                         # Maximum number of symbol files to keep in memory
                         "maxCacheEntries": 2000000,
@@ -663,16 +664,17 @@ class TTest(object):
                     missing_symbols_zip = os.path.join(upload_dir,
                                                        "missingsymbols.zip")
 
                     try:
                         mode = zipfile.ZIP_DEFLATED
                     except NameError:
                         mode = zipfile.ZIP_STORED
                     with zipfile.ZipFile(profile_arcname, 'a', mode) as arc:
+                        mozlog.info("Zipping up profiles")
                         # Collect all individual profiles that the test
                         # has put into sps_profile_dir.
                         for profile_filename in os.listdir(sps_profile_dir):
                             testname = profile_filename
                             if testname.endswith(".sps"):
                                 testname = testname[0:-4]
                             profile_path = os.path.join(sps_profile_dir,
                                                         profile_filename)