OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 import base64 | |
8 import gzip | 7 import gzip |
9 import logging | 8 import logging |
10 import optparse | 9 import optparse |
11 import os | 10 import os |
12 import re | 11 import re |
13 import select | 12 import select |
14 import shutil | 13 import shutil |
15 import sys | 14 import sys |
16 import threading | 15 import threading |
17 import time | 16 import time |
18 import webbrowser | 17 import webbrowser |
19 import zipfile | 18 import zipfile |
20 import zlib | 19 import zlib |
21 | 20 |
22 from pylib import android_commands | 21 from pylib import android_commands |
23 from pylib import cmd_helper | 22 from pylib import cmd_helper |
24 from pylib import constants | 23 from pylib import constants |
25 from pylib import pexpect | 24 from pylib import pexpect |
26 | 25 |
27 _TRACE_VIEWER_ROOT = os.path.join(constants.DIR_SOURCE_ROOT, | 26 _TRACE_VIEWER_ROOT = os.path.join(constants.DIR_SOURCE_ROOT, |
28 'third_party', 'trace-viewer') | 27 'third_party', 'trace-viewer') |
29 sys.path.append(_TRACE_VIEWER_ROOT) | 28 sys.path.append(_TRACE_VIEWER_ROOT) |
30 from trace_viewer.build import trace2html | 29 from trace_viewer.build import trace2html # pylint: disable=F0401 |
31 | 30 |
32 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' | 31 _DEFAULT_CHROME_CATEGORIES = '_DEFAULT_CHROME_CATEGORIES' |
33 | 32 |
34 | 33 |
35 def _GetTraceTimestamp(): | 34 def _GetTraceTimestamp(): |
36 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) | 35 return time.strftime('%Y-%m-%d-%H%M%S', time.localtime()) |
37 | 36 |
38 | 37 |
39 class ChromeTracingController(object): | 38 class ChromeTracingController(object): |
40 def __init__(self, adb, package_info, categories, ring_buffer): | 39 def __init__(self, adb, package_info, categories, ring_buffer): |
41 self._adb = adb | 40 self._adb = adb |
42 self._package_info = package_info | 41 self._package_info = package_info |
43 self._categories = categories | 42 self._categories = categories |
44 self._ring_buffer = ring_buffer | 43 self._ring_buffer = ring_buffer |
45 self._trace_file = None | 44 self._trace_file = None |
46 self._trace_interval = None | 45 self._trace_interval = None |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 self._thread = None | 109 self._thread = None |
111 self._trace_data = None | 110 self._trace_data = None |
112 | 111 |
113 def __str__(self): | 112 def __str__(self): |
114 return 'systrace' | 113 return 'systrace' |
115 | 114 |
116 @staticmethod | 115 @staticmethod |
117 def GetCategories(adb): | 116 def GetCategories(adb): |
118 return adb.RunShellCommand('atrace --list_categories') | 117 return adb.RunShellCommand('atrace --list_categories') |
119 | 118 |
120 def StartTracing(self, interval): | 119 def StartTracing(self, _): |
121 self._thread = threading.Thread(target=self._CollectData) | 120 self._thread = threading.Thread(target=self._CollectData) |
122 self._thread.start() | 121 self._thread.start() |
123 | 122 |
124 def StopTracing(self): | 123 def StopTracing(self): |
125 self._done.set() | 124 self._done.set() |
126 | 125 |
127 def PullTrace(self): | 126 def PullTrace(self): |
128 self._thread.join() | 127 self._thread.join() |
129 self._thread = None | 128 self._thread = None |
130 if self._trace_data: | 129 if self._trace_data: |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 355 |
357 browsers = sorted(_GetSupportedBrowsers().keys()) | 356 browsers = sorted(_GetSupportedBrowsers().keys()) |
358 parser.add_option('-b', '--browser', help='Select among installed browsers. ' | 357 parser.add_option('-b', '--browser', help='Select among installed browsers. ' |
359 'One of ' + ', '.join(browsers) + ', "stable" is used by ' | 358 'One of ' + ', '.join(browsers) + ', "stable" is used by ' |
360 'default.', type='choice', choices=browsers, | 359 'default.', type='choice', choices=browsers, |
361 default='stable') | 360 default='stable') |
362 parser.add_option('-v', '--verbose', help='Verbose logging.', | 361 parser.add_option('-v', '--verbose', help='Verbose logging.', |
363 action='store_true') | 362 action='store_true') |
364 parser.add_option('-z', '--compress', help='Compress the resulting trace ' | 363 parser.add_option('-z', '--compress', help='Compress the resulting trace ' |
365 'with gzip. ', action='store_true') | 364 'with gzip. ', action='store_true') |
366 options, args = parser.parse_args() | 365 options, _args = parser.parse_args() |
367 if options.trace_cc: | 366 if options.trace_cc: |
368 parser.parse_error("""--trace-cc is deprecated. | 367 parser.parse_error("""--trace-cc is deprecated. |
369 | 368 |
370 For basic jank busting uses, use --trace-frame-viewer | 369 For basic jank busting uses, use --trace-frame-viewer |
371 For detailed study of ubercompositor, pass --trace-ubercompositor. | 370 For detailed study of ubercompositor, pass --trace-ubercompositor. |
372 | 371 |
373 When in doubt, just try out --trace-frame-viewer. | 372 When in doubt, just try out --trace-frame-viewer. |
374 """) | 373 """) |
375 | 374 |
376 if options.verbose: | 375 if options.verbose: |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 options.json) | 416 options.json) |
418 if options.view: | 417 if options.view: |
419 if sys.platform == 'darwin': | 418 if sys.platform == 'darwin': |
420 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 419 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
421 else: | 420 else: |
422 webbrowser.open(result) | 421 webbrowser.open(result) |
423 | 422 |
424 | 423 |
425 if __name__ == '__main__': | 424 if __name__ == '__main__': |
426 sys.exit(main()) | 425 sys.exit(main()) |
OLD | NEW |