| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 import threading | 5 import threading |
| 6 import zlib | 6 import zlib |
| 7 | 7 |
| 8 from profile_chrome import controllers | 8 from profile_chrome import controllers |
| 9 from profile_chrome import util | 9 from profile_chrome import util |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 def PullTrace(self): | 49 def PullTrace(self): |
| 50 self._thread.join() | 50 self._thread.join() |
| 51 self._thread = None | 51 self._thread = None |
| 52 if self._trace_data: | 52 if self._trace_data: |
| 53 output_name = 'systrace-%s' % util.GetTraceTimestamp() | 53 output_name = 'systrace-%s' % util.GetTraceTimestamp() |
| 54 with open(output_name, 'w') as out: | 54 with open(output_name, 'w') as out: |
| 55 out.write(self._trace_data) | 55 out.write(self._trace_data) |
| 56 return output_name | 56 return output_name |
| 57 | 57 |
| 58 def _RunATraceCommand(self, command): | 58 def _RunATraceCommand(self, command): |
| 59 # TODO(jbudorick) can this be made work with DeviceUtils? | |
| 60 # We use a separate interface to adb because the one from AndroidCommands | 59 # We use a separate interface to adb because the one from AndroidCommands |
| 61 # isn't re-entrant. | 60 # isn't re-entrant. |
| 62 device_param = (['-s', self._device.old_interface.GetDevice()] | 61 # TODO(jbudorick) Look at providing a way to unhandroll this once the |
| 63 if self._device.old_interface.GetDevice() else []) | 62 # adb rewrite has fully landed. |
| 63 device_param = (['-s', str(self._device)] if str(self._device) else []) |
| 64 cmd = ['adb'] + device_param + ['shell', 'atrace', '--%s' % command] + \ | 64 cmd = ['adb'] + device_param + ['shell', 'atrace', '--%s' % command] + \ |
| 65 _SYSTRACE_OPTIONS + self._categories | 65 _SYSTRACE_OPTIONS + self._categories |
| 66 return cmd_helper.GetCmdOutput(cmd) | 66 return cmd_helper.GetCmdOutput(cmd) |
| 67 | 67 |
| 68 def _CollectData(self): | 68 def _CollectData(self): |
| 69 trace_data = [] | 69 trace_data = [] |
| 70 self._RunATraceCommand('async_start') | 70 self._RunATraceCommand('async_start') |
| 71 try: | 71 try: |
| 72 while not self._done.is_set(): | 72 while not self._done.is_set(): |
| 73 self._done.wait(_SYSTRACE_INTERVAL) | 73 self._done.wait(_SYSTRACE_INTERVAL) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 86 except ValueError: | 86 except ValueError: |
| 87 raise RuntimeError('Systrace start marker not found') | 87 raise RuntimeError('Systrace start marker not found') |
| 88 trace_data = trace_data[trace_start + 6:] | 88 trace_data = trace_data[trace_start + 6:] |
| 89 | 89 |
| 90 # Collapse CRLFs that are added by adb shell. | 90 # Collapse CRLFs that are added by adb shell. |
| 91 if trace_data.startswith('\r\n'): | 91 if trace_data.startswith('\r\n'): |
| 92 trace_data = trace_data.replace('\r\n', '\n') | 92 trace_data = trace_data.replace('\r\n', '\n') |
| 93 | 93 |
| 94 # Skip the initial newline. | 94 # Skip the initial newline. |
| 95 return trace_data[1:] | 95 return trace_data[1:] |
| OLD | NEW |