| 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 gzip | 7 import gzip |
| 8 import logging | 8 import logging |
| 9 import optparse | 9 import optparse |
| 10 import os | 10 import os |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 | 38 |
| 39 class ChromeTracingController(object): | 39 class ChromeTracingController(object): |
| 40 def __init__(self, device, package_info, categories, ring_buffer): | 40 def __init__(self, device, package_info, categories, ring_buffer): |
| 41 self._device = device | 41 self._device = device |
| 42 self._package_info = package_info | 42 self._package_info = package_info |
| 43 self._categories = categories | 43 self._categories = categories |
| 44 self._ring_buffer = ring_buffer | 44 self._ring_buffer = ring_buffer |
| 45 self._trace_file = None | 45 self._trace_file = None |
| 46 self._trace_interval = None | 46 self._trace_interval = None |
| 47 self._trace_start_re = \ | 47 self._trace_start_re = \ |
| 48 re.compile(r'Logging performance trace to file: (.*)') | 48 re.compile(r'Logging performance trace to file') |
| 49 self._trace_finish_re = \ | 49 self._trace_finish_re = \ |
| 50 re.compile(r'Profiler finished[.] Results are in (.*)[.]') | 50 re.compile(r'Profiler finished[.] Results are in (.*)[.]') |
| 51 self._device.old_interface.StartMonitoringLogcat(clear=False) | 51 self._device.old_interface.StartMonitoringLogcat(clear=False) |
| 52 | 52 |
| 53 def __str__(self): | 53 def __str__(self): |
| 54 return 'chrome trace' | 54 return 'chrome trace' |
| 55 | 55 |
| 56 def StartTracing(self, interval): | 56 def StartTracing(self, interval): |
| 57 self._trace_interval = interval | 57 self._trace_interval = interval |
| 58 self._device.old_interface.SyncLogCat() | 58 self._device.old_interface.SyncLogCat() |
| 59 self._device.old_interface.BroadcastIntent( | 59 self._device.old_interface.BroadcastIntent( |
| 60 self._package_info.package, 'GPU_PROFILER_START', | 60 self._package_info.package, 'GPU_PROFILER_START', |
| 61 '-e categories "%s"' % ','.join(self._categories), | 61 '-e categories "%s"' % ','.join(self._categories), |
| 62 '-e continuous' if self._ring_buffer else '') | 62 '-e continuous' if self._ring_buffer else '') |
| 63 # Chrome logs two different messages related to tracing: | 63 # Chrome logs two different messages related to tracing: |
| 64 # | 64 # |
| 65 # 1. "Logging performance trace to file [...]" | 65 # 1. "Logging performance trace to file" |
| 66 # 2. "Profiler finished. Results are in [...]" | 66 # 2. "Profiler finished. Results are in [...]" |
| 67 # | 67 # |
| 68 # The first one is printed when tracing starts and the second one indicates | 68 # The first one is printed when tracing starts and the second one indicates |
| 69 # that the trace file is ready to be pulled. | 69 # that the trace file is ready to be pulled. |
| 70 try: | 70 try: |
| 71 self._trace_file = self._device.old_interface.WaitForLogMatch( | 71 self._device.old_interface.WaitForLogMatch( |
| 72 self._trace_start_re, None, timeout=5).group(1) | 72 self._trace_start_re, None, timeout=5) |
| 73 except pexpect.TIMEOUT: | 73 except pexpect.TIMEOUT: |
| 74 raise RuntimeError('Trace start marker not found. Is the correct version ' | 74 raise RuntimeError('Trace start marker not found. Is the correct version ' |
| 75 'of the browser running?') | 75 'of the browser running?') |
| 76 | 76 |
| 77 def StopTracing(self): | 77 def StopTracing(self): |
| 78 if not self._trace_file: | 78 self._device.old_interface.BroadcastIntent( |
| 79 return | 79 self._package_info.package, |
| 80 self._device.old_interface.BroadcastIntent(self._package_info.package, | 80 'GPU_PROFILER_STOP') |
| 81 'GPU_PROFILER_STOP') | 81 self._trace_file = self._device.old_interface.WaitForLogMatch( |
| 82 self._device.old_interface.WaitForLogMatch(self._trace_finish_re, None, | 82 self._trace_finish_re, None, timeout=120).group(1) |
| 83 timeout=120) | |
| 84 | 83 |
| 85 def PullTrace(self): | 84 def PullTrace(self): |
| 86 # Wait a bit for the browser to finish writing the trace file. | 85 # Wait a bit for the browser to finish writing the trace file. |
| 87 time.sleep(self._trace_interval / 4 + 1) | 86 time.sleep(self._trace_interval / 4 + 1) |
| 88 | 87 |
| 89 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') | 88 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') |
| 90 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) | 89 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) |
| 91 self._device.old_interface.PullFileFromDevice(trace_file, host_file) | 90 self._device.old_interface.PullFileFromDevice(trace_file, host_file) |
| 92 return host_file | 91 return host_file |
| 93 | 92 |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 options.json) | 424 options.json) |
| 426 if options.view: | 425 if options.view: |
| 427 if sys.platform == 'darwin': | 426 if sys.platform == 'darwin': |
| 428 os.system('/usr/bin/open %s' % os.path.abspath(result)) | 427 os.system('/usr/bin/open %s' % os.path.abspath(result)) |
| 429 else: | 428 else: |
| 430 webbrowser.open(result) | 429 webbrowser.open(result) |
| 431 | 430 |
| 432 | 431 |
| 433 if __name__ == '__main__': | 432 if __name__ == '__main__': |
| 434 sys.exit(main()) | 433 sys.exit(main()) |
| OLD | NEW |