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.
7 from profile_chrome
import trace_packager
8 from profile_chrome
import ui
10 from pylib
import constants
13 def _StartTracing(controllers
, interval
):
14 for controller
in controllers
:
15 controller
.StartTracing(interval
)
18 def _StopTracing(controllers
):
19 for controller
in controllers
:
20 controller
.StopTracing()
23 def _PullTraces(controllers
, output
, compress
, write_json
):
24 ui
.PrintMessage('Downloading...', eol
='')
25 trace_files
= [controller
.PullTrace() for controller
in controllers
]
26 trace_files
= [trace
for trace
in trace_files
if trace
]
28 ui
.PrintMessage('No results')
30 result
= trace_packager
.PackageTraces(trace_files
,
33 write_json
=write_json
)
34 ui
.PrintMessage('done')
35 ui
.PrintMessage('Trace written to file://%s' % os
.path
.abspath(result
))
39 def GetSupportedBrowsers():
40 """Returns the package names of all supported browsers."""
41 # Add aliases for backwards compatibility.
42 supported_browsers
= {
43 'stable': constants
.PACKAGE_INFO
['chrome_stable'],
44 'beta': constants
.PACKAGE_INFO
['chrome_beta'],
45 'dev': constants
.PACKAGE_INFO
['chrome_dev'],
46 'build': constants
.PACKAGE_INFO
['chrome'],
48 supported_browsers
.update(constants
.PACKAGE_INFO
)
49 unsupported_browsers
= ['content_browsertests', 'gtest', 'legacy_browser']
50 for browser
in unsupported_browsers
:
51 del supported_browsers
[browser
]
52 return supported_browsers
55 def CaptureProfile(controllers
, interval
, output
=None, compress
=False,
57 """Records a profiling trace saves the result to a file.
60 controllers: List of tracing controllers.
61 interval: Time interval to capture in seconds. An interval of None (or 0)
62 continues tracing until stopped by the user.
63 output: Output file name or None to use an automatically generated name.
64 compress: If True, the result will be compressed either with gzip or zip
65 depending on the number of captured subtraces.
66 write_json: If True, prefer JSON output over HTML.
69 Path to saved profile.
71 trace_type
= ' + '.join(map(str, controllers
))
73 _StartTracing(controllers
, interval
)
75 ui
.PrintMessage('Capturing %d-second %s. Press Enter to stop early...' % \
76 (interval
, trace_type
), eol
='')
77 ui
.WaitForEnter(interval
)
79 ui
.PrintMessage('Capturing %s. Press Enter to stop...' % \
83 _StopTracing(controllers
)
85 ui
.PrintMessage('done')
87 return _PullTraces(controllers
, output
, compress
, write_json
)