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

Side by Side 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: Fix unit tests Created 7 years, 3 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 unified diff | Download patch
OLDNEW
1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Handles generating profiles and transferring them to/from mobile devices.""" 5 """Handles generating profiles and transferring them to/from mobile devices."""
6 6
7 import logging
8 import os
9 import shutil
10 import sys
11 import tempfile
12
7 from telemetry.core import browser_options 13 from telemetry.core import browser_options
14 from telemetry.core import discover
15 from telemetry.core import util
8 from telemetry.page import page_runner 16 from telemetry.page import page_runner
17 from telemetry.page import profile_creator
18 from telemetry.page import test_expectations
9 19
10 def GenerateProfiles(): 20
21 def _DiscoverProfileCreatorClasses():
22 parent_dir = os.path.abspath(os.path.dirname(__file__))
23 profile_creators_dir = os.path.abspath(os.path.join(parent_dir,
24 os.pardir, os.pardir, os.pardir, 'perf', 'profile_creators'))
tonyg 2013/08/28 00:09:58 Is this another good case for util.GetBaseDir()?
25 base_dir = os.path.abspath(os.path.join(profile_creators_dir, os.pardir))
26
27 profile_creators_unfiltered = discover.DiscoverClasses(
28 profile_creators_dir, base_dir, profile_creator.ProfileCreator)
29
30 # Remove '_creator' suffix from keys.
31 profile_creators = {}
32 for test_name, test_class in profile_creators_unfiltered.iteritems():
33 assert test_name.endswith('_creator')
34 test_name = test_name[:-len('_creator')]
35 profile_creators[test_name] = test_class
36 return profile_creators
37
38 def GenerateProfiles(profile_creator_class, profile_creator_name, options):
11 """Generate a profile""" 39 """Generate a profile"""
12 raise Exception("create command unimplemented.") 40 expectations = test_expectations.TestExpectations()
41 test = profile_creator_class()
13 42
14 def UploadProfiles(): 43 temp_output_directory = tempfile.mkdtemp()
15 """Upload stored generated profiles to a mobile device for use by telemetry 44 options.output_profile_path = temp_output_directory
16 tests.
17 """
18 raise Exception("upload command unimplemented.")
19 45
20 def DownloadProfiles(): 46 results = page_runner.Run(test, test.page_set, expectations, options)
21 """Download generated profiles from a mobile device for future use.""" 47
22 raise Exception("download command unimplemented.") 48 if results.errors or results.failures or results.skipped:
49 logging.warning('Some pages failed or were skipped')
50 if results.errors or results.failures:
51 logging.warning('Failed pages:\n%s',
52 '\n'.join(zip(*results.errors + results.failures)[0]))
53 if results.skipped:
54 logging.warning('Skipped pages:\n%s', '\n'.join(zip(*results.skipped)[0]))
55 return 1
56
57 # Everything is a-ok, move results to final destination.
58 generated_profiles_dir = os.path.abspath(os.path.join(util.GetBaseDir(),
59 os.pardir, os.pardir, 'out', 'Release', 'generated_profiles'))
60 if not os.path.exists(generated_profiles_dir):
61 os.makedirs(generated_profiles_dir)
62 out_path = os.path.join(generated_profiles_dir, profile_creator_name)
63 shutil.move(temp_output_directory, out_path)
64 sys.stderr.write("Generated profile copied to: '%s'." % out_path)
tonyg 2013/08/28 00:09:58 Since this is going to stderr, let's make it clear
65
66 return 0
23 67
24 def Main(): 68 def Main():
25 COMMANDS = [ 69 profile_creators = _DiscoverProfileCreatorClasses()
26 ('create', GenerateProfiles),
27 ('upload', UploadProfiles),
28 ('download', DownloadProfiles)
29 ]
30
31 LEGAL_COMMANDS = '|'.join([x[0] for x in COMMANDS])
32 70
33 options = browser_options.BrowserOptions() 71 options = browser_options.BrowserOptions()
34 parser = options.CreateParser("%%prog <%s> <--browser=...>" % LEGAL_COMMANDS) 72 parser = options.CreateParser("%%prog <profile_type> <--browser=...>")
35 page_runner.AddCommandLineOptions(parser) 73 page_runner.AddCommandLineOptions(parser)
36
37 _, args = parser.parse_args() 74 _, args = parser.parse_args()
38 75
39 if len(args) < 1: 76 # Sanity check arguments.
40 raise Exception("Must specify one of <%s>" % LEGAL_COMMANDS) 77 legal_profile_creators = '|'.join(profile_creators.keys())
78 if len(args) != 1:
79 raise Exception("No profile type argument specified legal values are: %s" %
80 legal_profile_creators)
81
82 if args[0] not in profile_creators.keys():
83 raise Exception("Invalid profile type, legal values are: %s" %
84 legal_profile_creators)
41 85
42 if not options.browser_type: 86 if not options.browser_type:
43 raise Exception("Must specify --browser option.") 87 raise Exception("Must specify --browser option.")
44 88
45 commands_dict = dict(COMMANDS) 89 if options.dont_override_profile:
46 if args[0] not in commands_dict.keys(): 90 raise Exception("Can't use existing profile when generating profile.")
47 raise Exception("Unsupported command '%s', Valid options are "
48 "%s" % (args[0], LEGAL_COMMANDS))
49 commands_dict[args[0]]()
50 91
51 return 0 92 # Generate profile.
93 profile_creator_class = profile_creators[args[0]]
94 return GenerateProfiles(profile_creator_class, args[0], options)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698