Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(179)

Unified Diff: tools/telemetry/telemetry/page/profile_generator.py

Issue 23604005: [Telemetry] Implement dirty profile generation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@generate_profile
Patch Set: Rebase against trunk Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/telemetry/telemetry/page/profile_generator.py
diff --git a/tools/telemetry/telemetry/page/profile_generator.py b/tools/telemetry/telemetry/page/profile_generator.py
index b31d2e20c8938ee9b1afd5f4d41492b3d79c8345..fee2cd6a760f433899bfc4508c611d0114ab95b6 100644
--- a/tools/telemetry/telemetry/page/profile_generator.py
+++ b/tools/telemetry/telemetry/page/profile_generator.py
@@ -4,48 +4,88 @@
"""Handles generating profiles and transferring them to/from mobile devices."""
+import logging
+import os
+import shutil
+import sys
+import tempfile
+
from telemetry.core import browser_options
+from telemetry.core import discover
+from telemetry.core import util
from telemetry.page import page_runner
+from telemetry.page import profile_creator
+from telemetry.page import test_expectations
+
+
+def _DiscoverProfileCreatorClasses():
+ profile_creators_dir = os.path.abspath(os.path.join(util.GetBaseDir(),
+ os.pardir, 'perf', 'profile_creators'))
+ base_dir = os.path.abspath(os.path.join(profile_creators_dir, os.pardir))
+
+ profile_creators_unfiltered = discover.DiscoverClasses(
+ profile_creators_dir, base_dir, profile_creator.ProfileCreator)
-def GenerateProfiles():
+ # Remove '_creator' suffix from keys.
+ profile_creators = {}
+ for test_name, test_class in profile_creators_unfiltered.iteritems():
+ assert test_name.endswith('_creator')
+ test_name = test_name[:-len('_creator')]
+ profile_creators[test_name] = test_class
+ return profile_creators
+
+def GenerateProfiles(profile_creator_class, profile_creator_name, options):
"""Generate a profile"""
- raise Exception("create command unimplemented.")
+ expectations = test_expectations.TestExpectations()
+ test = profile_creator_class()
-def UploadProfiles():
- """Upload stored generated profiles to a mobile device for use by telemetry
- tests.
- """
- raise Exception("upload command unimplemented.")
+ temp_output_directory = tempfile.mkdtemp()
+ options.output_profile_path = temp_output_directory
-def DownloadProfiles():
- """Download generated profiles from a mobile device for future use."""
- raise Exception("download command unimplemented.")
+ results = page_runner.Run(test, test.page_set, expectations, options)
-def Main():
- COMMANDS = [
- ('create', GenerateProfiles),
- ('upload', UploadProfiles),
- ('download', DownloadProfiles)
- ]
+ if results.errors or results.failures:
+ logging.warning('Some pages failed.')
+ if results.errors or results.failures:
+ logging.warning('Failed pages:\n%s',
+ '\n'.join(zip(*results.errors + results.failures)[0]))
+ return 1
- LEGAL_COMMANDS = '|'.join([x[0] for x in COMMANDS])
+ # Everything is a-ok, move results to final destination.
+ generated_profiles_dir = os.path.abspath(os.path.join(util.GetBaseDir(),
+ os.pardir, os.pardir, 'out', 'Release', 'generated_profiles'))
+ if not os.path.exists(generated_profiles_dir):
+ os.makedirs(generated_profiles_dir)
+ out_path = os.path.join(generated_profiles_dir, profile_creator_name)
+ shutil.move(temp_output_directory, out_path)
+ sys.stderr.write("SUCCESS: Generated profile copied to: '%s'.\n" % out_path)
- options = browser_options.BrowserOptions()
- parser = options.CreateParser("%%prog <%s> <--browser=...>" % LEGAL_COMMANDS)
- page_runner.AddCommandLineOptions(parser)
+ return 0
+
+def Main():
+ profile_creators = _DiscoverProfileCreatorClasses()
+ options = browser_options.BrowserFinderOptions()
+ parser = options.CreateParser("%%prog <profile_type> <--browser=...>")
+ page_runner.AddCommandLineOptions(parser)
_, args = parser.parse_args()
- if len(args) < 1:
- raise Exception("Must specify one of <%s>" % LEGAL_COMMANDS)
+ # Sanity check arguments.
+ legal_profile_creators = '|'.join(profile_creators.keys())
+ if len(args) != 1:
+ raise Exception("No profile type argument specified legal values are: %s" %
+ legal_profile_creators)
+
+ if args[0] not in profile_creators.keys():
+ raise Exception("Invalid profile type, legal values are: %s" %
+ legal_profile_creators)
if not options.browser_type:
raise Exception("Must specify --browser option.")
- commands_dict = dict(COMMANDS)
- if args[0] not in commands_dict.keys():
- raise Exception("Unsupported command '%s', Valid options are "
- "%s" % (args[0], LEGAL_COMMANDS))
- commands_dict[args[0]]()
+ if options.dont_override_profile:
+ raise Exception("Can't use existing profile when generating profile.")
- return 0
+ # Generate profile.
+ profile_creator_class = profile_creators[args[0]]
+ return GenerateProfiles(profile_creator_class, args[0], options)

Powered by Google App Engine
This is Rietveld 408576698