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 signal | 7 import signal |
8 import subprocess | 8 import subprocess |
9 import sys | 9 import sys |
10 import tempfile | 10 import tempfile |
11 | 11 |
12 from profile_chrome import controllers | 12 from profile_chrome import controllers |
13 from profile_chrome import ui | 13 from profile_chrome import ui |
14 | 14 |
15 from pylib import android_commands | 15 from pylib import android_commands |
16 from pylib import constants | 16 from pylib import constants |
17 from pylib.perf import perf_control | 17 from pylib.perf import perf_control |
| 18 from pylib.utils import device_temp_file |
18 | 19 |
19 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 20 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
20 'tools', | 21 'tools', |
21 'telemetry')) | 22 'telemetry')) |
22 try: | 23 try: |
23 # pylint: disable=F0401 | 24 # pylint: disable=F0401 |
24 from telemetry.core.platform.profiler import android_profiling_helper | 25 from telemetry.core.platform.profiler import android_profiling_helper |
25 from telemetry.util import support_binaries | 26 from telemetry.util import support_binaries |
26 except ImportError: | 27 except ImportError: |
27 android_profiling_helper = None | 28 android_profiling_helper = None |
(...skipping 12 matching lines...) Expand all Loading... |
40 # Record raw samples to get CPU information. | 41 # Record raw samples to get CPU information. |
41 '--raw-samples', | 42 '--raw-samples', |
42 # Increase sampling frequency for better coverage. | 43 # Increase sampling frequency for better coverage. |
43 '--freq', '2000', | 44 '--freq', '2000', |
44 ] | 45 ] |
45 | 46 |
46 | 47 |
47 class _PerfProfiler(object): | 48 class _PerfProfiler(object): |
48 def __init__(self, device, perf_binary, categories): | 49 def __init__(self, device, perf_binary, categories): |
49 self._device = device | 50 self._device = device |
50 self._output_file = android_commands.DeviceTempFile( | 51 self._output_file = device_temp_file.DeviceTempFile( |
51 self._device.old_interface, prefix='perf_output') | 52 self._device.adb, prefix='perf_output') |
52 self._log_file = tempfile.TemporaryFile() | 53 self._log_file = tempfile.TemporaryFile() |
53 | 54 |
54 # TODO(jbudorick) Look at providing a way to unhandroll this once the | 55 # TODO(jbudorick) Look at providing a way to unhandroll this once the |
55 # adb rewrite has fully landed. | 56 # adb rewrite has fully landed. |
56 device_param = (['-s', str(self._device)] if str(self._device) else []) | 57 device_param = (['-s', str(self._device)] if str(self._device) else []) |
57 cmd = ['adb'] + device_param + \ | 58 cmd = ['adb'] + device_param + \ |
58 ['shell', perf_binary, 'record', | 59 ['shell', perf_binary, 'record', |
59 '--output', self._output_file.name] + _PERF_OPTIONS | 60 '--output', self._output_file.name] + _PERF_OPTIONS |
60 if categories: | 61 if categories: |
61 cmd += ['--event', ','.join(categories)] | 62 cmd += ['--event', ','.join(categories)] |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 open(json_file_name, 'w') as json_file: | 180 open(json_file_name, 'w') as json_file: |
180 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', | 181 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', |
181 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] | 182 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] |
182 if subprocess.call(cmd, stdout=json_file, stderr=dev_null): | 183 if subprocess.call(cmd, stdout=json_file, stderr=dev_null): |
183 logging.warning('Perf data to JSON conversion failed. The result will ' | 184 logging.warning('Perf data to JSON conversion failed. The result will ' |
184 'not contain any perf samples. You can still view the ' | 185 'not contain any perf samples. You can still view the ' |
185 'perf data manually as shown above.') | 186 'perf data manually as shown above.') |
186 return None | 187 return None |
187 | 188 |
188 return json_file_name | 189 return json_file_name |
OLD | NEW |