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 logging | 5 import logging |
6 import os | 6 import os |
7 import subprocess | 7 import subprocess |
8 import sys | 8 import sys |
9 import tempfile | 9 import tempfile |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 ] | 43 ] |
44 | 44 |
45 | 45 |
46 class _PerfProfiler(object): | 46 class _PerfProfiler(object): |
47 def __init__(self, device, perf_binary, categories): | 47 def __init__(self, device, perf_binary, categories): |
48 self._device = device | 48 self._device = device |
49 self._output_file = android_commands.DeviceTempFile( | 49 self._output_file = android_commands.DeviceTempFile( |
50 self._device.old_interface, prefix='perf_output') | 50 self._device.old_interface, prefix='perf_output') |
51 self._log_file = tempfile.TemporaryFile() | 51 self._log_file = tempfile.TemporaryFile() |
52 | 52 |
53 device_param = (['-s', self._device.old_interface.GetDevice()] | 53 # TODO(jbudorick) Look at providing a way to unhandroll this once the |
54 if self._device.old_interface.GetDevice() else []) | 54 # adb rewrite has fully landed. |
| 55 device_param = (['-s', str(self._device)] if str(self._device) else []) |
55 cmd = ['adb'] + device_param + \ | 56 cmd = ['adb'] + device_param + \ |
56 ['shell', perf_binary, 'record', | 57 ['shell', perf_binary, 'record', |
57 '--output', self._output_file.name] + _PERF_OPTIONS | 58 '--output', self._output_file.name] + _PERF_OPTIONS |
58 if categories: | 59 if categories: |
59 cmd += ['--event', ','.join(categories)] | 60 cmd += ['--event', ','.join(categories)] |
60 self._perf_control = perf_control.PerfControl(self._device) | 61 self._perf_control = perf_control.PerfControl(self._device) |
61 self._perf_control.SetPerfProfilingMode() | 62 self._perf_control.SetPerfProfilingMode() |
62 self._perf_process = subprocess.Popen(cmd, | 63 self._perf_process = subprocess.Popen(cmd, |
63 stdout=self._log_file, | 64 stdout=self._log_file, |
64 stderr=subprocess.STDOUT) | 65 stderr=subprocess.STDOUT) |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 open(json_file_name, 'w') as json_file: | 179 open(json_file_name, 'w') as json_file: |
179 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', | 180 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', |
180 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] | 181 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] |
181 if subprocess.call(cmd, stdout=json_file, stderr=dev_null): | 182 if subprocess.call(cmd, stdout=json_file, stderr=dev_null): |
182 logging.warning('Perf data to JSON conversion failed. The result will ' | 183 logging.warning('Perf data to JSON conversion failed. The result will ' |
183 'not contain any perf samples. You can still view the ' | 184 'not contain any perf samples. You can still view the ' |
184 'perf data manually as shown above.') | 185 'perf data manually as shown above.') |
185 return None | 186 return None |
186 | 187 |
187 return json_file_name | 188 return json_file_name |
OLD | NEW |