OLD | NEW |
| (Empty) |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import os | |
6 | |
7 from chrome_profiler import trace_packager | |
8 from chrome_profiler import ui | |
9 | |
10 from pylib import constants | |
11 | |
12 | |
13 def _StartTracing(controllers, interval): | |
14 for controller in controllers: | |
15 controller.StartTracing(interval) | |
16 | |
17 | |
18 def _StopTracing(controllers): | |
19 for controller in controllers: | |
20 controller.StopTracing() | |
21 | |
22 | |
23 def _PullTraces(controllers, output, compress, write_json): | |
24 ui.PrintMessage('Downloading...', eol='') | |
25 trace_files = [controller.PullTrace() for controller in controllers] | |
26 result = trace_packager.PackageTraces(trace_files, | |
27 output=output, | |
28 compress=compress, | |
29 write_json=write_json) | |
30 ui.PrintMessage('done') | |
31 ui.PrintMessage('Trace written to file://%s' % os.path.abspath(result)) | |
32 return result | |
33 | |
34 | |
35 def GetSupportedBrowsers(): | |
36 """Returns the package names of all supported browsers.""" | |
37 # Add aliases for backwards compatibility. | |
38 supported_browsers = { | |
39 'stable': constants.PACKAGE_INFO['chrome_stable'], | |
40 'beta': constants.PACKAGE_INFO['chrome_beta'], | |
41 'dev': constants.PACKAGE_INFO['chrome_dev'], | |
42 'build': constants.PACKAGE_INFO['chrome'], | |
43 } | |
44 supported_browsers.update(constants.PACKAGE_INFO) | |
45 unsupported_browsers = ['content_browsertests', 'gtest', 'legacy_browser'] | |
46 for browser in unsupported_browsers: | |
47 del supported_browsers[browser] | |
48 return supported_browsers | |
49 | |
50 | |
51 def CaptureProfile(controllers, interval, output=None, compress=False, | |
52 write_json=False): | |
53 """Records a profiling trace saves the result to a file. | |
54 | |
55 Args: | |
56 controllers: List of tracing controllers. | |
57 interval: Time interval to capture in seconds. An interval of None (or 0) | |
58 continues tracing until stopped by the user. | |
59 output: Output file name or None to use an automatically generated name. | |
60 compress: If True, the result will be compressed either with gzip or zip | |
61 depending on the number of captured subtraces. | |
62 write_json: If True, prefer JSON output over HTML. | |
63 | |
64 Returns: | |
65 Path to saved profile. | |
66 """ | |
67 trace_type = ' + '.join(map(str, controllers)) | |
68 try: | |
69 _StartTracing(controllers, interval) | |
70 if interval: | |
71 ui.PrintMessage('Capturing %d-second %s. Press Enter to stop early...' % \ | |
72 (interval, trace_type), eol='') | |
73 ui.WaitForEnter(interval) | |
74 else: | |
75 ui.PrintMessage('Capturing %s. Press Enter to stop...' % \ | |
76 trace_type, eol='') | |
77 raw_input() | |
78 finally: | |
79 _StopTracing(controllers) | |
80 if interval: | |
81 ui.PrintMessage('done') | |
82 | |
83 return _PullTraces(controllers, output, compress, write_json) | |
OLD | NEW |