Bug 1425308 - Automatically view local talos gecko profile in perf-html.io (wip) draft
authorRob Wood <rwood@mozilla.com>
Mon, 28 May 2018 11:51:02 -0400
changeset 800609 2919533323b3f78a79d06487c87042d107d25cea
parent 800535 1d53c55e96dfbcd965b8a722539ea049bb45fffe
push id111426
push userrwood@mozilla.com
push dateMon, 28 May 2018 17:37:26 +0000
bugs1425308
milestone62.0a1
Bug 1425308 - Automatically view local talos gecko profile in perf-html.io (wip) When running talos locally with --geckoProfile set, the latest gecko-profile archive will automatically be loaded in perf-html.io using the view-gecko-profile tool. To disable this automatic perf-html.io launching, set TALOS_DISABLE_PERFHTMLIO_LAUNCH=1. MozReview-Commit-ID: 8tpLnsPAXD9
testing/talos/talos/cmdline.py
testing/talos/talos/gecko_profile.py
testing/talos/talos/run_tests.py
--- a/testing/talos/talos/cmdline.py
+++ b/testing/talos/talos/cmdline.py
@@ -86,17 +86,20 @@ def create_parser(mach_interface=False):
                  "run and output the results in $MOZ_UPLOAD_DIR.")
     add_arg('--spsProfileInterval', dest='gecko_profile_interval', type=float,
             help="(Deprecated - Use --geckoProfileInterval instead.) How "
                  "frequently to take samples (ms)")
     add_arg('--spsProfileEntries', dest="gecko_profile_entries", type=int,
             help="(Deprecated - Use --geckoProfileEntries instead.) How "
                  "many samples to take with the profiler")
     add_arg('--geckoProfile', action="store_true", dest="gecko_profile",
-            help="Profile the run and output the results in $MOZ_UPLOAD_DIR.")
+            help="Profile the run and output the results in $MOZ_UPLOAD_DIR. "
+                 "After talos is finished, perf-html.io will be launched in Firefox so you "
+                 "can analyze the local profiles. To disable auto-launching of perf-html.io "
+                 "set the TALOS_DISABLE_PERFHTMLIO_LAUNCH=1 env var.")
     add_arg('--geckoProfileInterval', dest='gecko_profile_interval', type=float,
             help="How frequently to take samples (ms)")
     add_arg('--geckoProfileEntries', dest="gecko_profile_entries", type=int,
             help="How many samples to take with the profiler")
     add_arg('--extension', dest='extensions', action='append',
             default=['${talos}/talos-powers'],
             help="Extension to install while running")
     add_arg('--fast', action='store_true',
--- a/testing/talos/talos/gecko_profile.py
+++ b/testing/talos/talos/gecko_profile.py
@@ -199,16 +199,20 @@ class GeckoProfile(object):
                     arc.write(profile_path, path_in_zip)
                 except Exception:
                     LOG.exception(
                         "Failed to copy profile {0} as {1} to"
                         " archive {2}".format(profile_path,
                                               path_in_zip,
                                               self.profile_arcname)
                     )
+            # write latest gecko profie archive name to env var so
+            # later we can use the view-gecko-profile tool and view it
+            os.environ['TALOS_LATEST_GECKO_PROFILE_ARCHIVE'] = self.profile_arcname
+            LOG.info("set TALOS_LATEST_GECKO_PROFILE_ARCHIVE to %s" % self.profile_arcname)
 
     def clean(self):
         """
         Clean up temp folders created with the instance creation.
         """
         mozfile.remove(self.option('dir'))
         if self.cleanup:
             for symbol_path in self.symbol_paths.values():
--- a/testing/talos/talos/run_tests.py
+++ b/testing/talos/talos/run_tests.py
@@ -323,21 +323,39 @@ def run_tests(config, browser_config):
 
     # output results
     if results_urls and not browser_config['no_upload_results']:
         talos_results.output(results_urls)
         if browser_config['develop'] or config['gecko_profile']:
             print("Thanks for running Talos locally. Results are in %s"
                   % (results_urls['output_urls']))
 
+    # if gecko profiling was turned on, use the view-gecko-profile tool
+    # to automatically load the latest gecko profile in perf-html.io
+    if config['gecko_profile']:
+        # unless TALOS_DISABLE_PERFHTMLIO_LAUNCH is set
+        if os.environ.get('TALOS_DISABLE_PERFHTMLIO_LAUNCH', '0') == '1':
+            LOG.info("Not launching perf-html.io because TALOS_DISABLE_PERFHTMLIO_LAUNCH=1")
+        else:
+            auto_view_gecko_profile()
+
     # we will stop running tests on a failed test, or we will return 0 for
     # green
     return 0
 
 
+def auto_view_gecko_profile():
+    profile_zip = os.environ.get('TALOS_LATEST_GECKO_PROFILE_ARCHIVE', 0)
+    if profile_zip is not None:
+        LOG.info('Auto-loading this profile in perfhtml.io: %s' % profile_zip)
+        # DO IT!
+    else:
+        LOG.info("No local gecko profiles were found so not launching perf-html.io")
+
+
 def make_comparison_result(base_and_reference_results):
     ''' Receive a test result object meant to be used as a base vs reference test. The result
     object will have one test with two subtests; instead of traditional subtests we want to
     treat them as separate tests, comparing them together and reporting the comparison results.
 
     Results with multiple pages used as subtests would look like this normally, with the overall
     result value being the mean of the pages/subtests: