Chromium Code Reviews| 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 |
| 11 from chrome_profiler import controllers | 11 from chrome_profiler import controllers |
| 12 from chrome_profiler import ui | |
| 12 | 13 |
| 13 from pylib import android_commands | 14 from pylib import android_commands |
| 14 from pylib import constants | 15 from pylib import constants |
| 15 from pylib.perf import perf_control | 16 from pylib.perf import perf_control |
| 16 | 17 |
| 17 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 18 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
| 18 'tools', | 19 'tools', |
| 19 'telemetry')) | 20 'telemetry')) |
| 20 try: | 21 try: |
| 21 # pylint: disable=F0401 | 22 # pylint: disable=F0401 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 121 def StartTracing(self, _): | 122 def StartTracing(self, _): |
| 122 self._perf_instance = _PerfProfiler(self._device, | 123 self._perf_instance = _PerfProfiler(self._device, |
| 123 self._perf_binary, | 124 self._perf_binary, |
| 124 self._categories) | 125 self._categories) |
| 125 | 126 |
| 126 def StopTracing(self): | 127 def StopTracing(self): |
| 127 if not self._perf_instance: | 128 if not self._perf_instance: |
| 128 return | 129 return |
| 129 self._perf_instance.SignalAndWait() | 130 self._perf_instance.SignalAndWait() |
| 130 | 131 |
| 132 @staticmethod | |
| 133 def _GetInteractivePerfCommand(perfhost_path, perf_profile, symfs_dir, | |
| 134 required_libs, kallsyms): | |
| 135 cmd = '%s report -n -i %s --symfs %s --kallsyms %s' % ( | |
| 136 os.path.relpath(perfhost_path, '.'), perf_profile, symfs_dir, kallsyms) | |
| 137 for lib in required_libs: | |
| 138 lib = os.path.join(symfs_dir, lib[1:]) | |
| 139 if not os.path.exists(lib): | |
| 140 continue | |
| 141 objdump_path = android_profiling_helper.GetToolchainBinaryPath( | |
|
Dominik Grewe
2014/06/10 16:48:17
I can't find this method anywhere? Did you mean to
| |
| 142 lib, 'objdump') | |
| 143 if objdump_path: | |
| 144 cmd += ' --objdump %s' % os.path.relpath(objdump_path, '.') | |
| 145 break | |
| 146 return cmd | |
| 147 | |
| 131 def PullTrace(self): | 148 def PullTrace(self): |
| 132 symfs_dir = os.path.join(tempfile.gettempdir(), | 149 symfs_dir = os.path.join(tempfile.gettempdir(), |
| 133 os.path.expandvars('$USER-perf-symfs')) | 150 os.path.expandvars('$USER-perf-symfs')) |
| 134 if not os.path.exists(symfs_dir): | 151 if not os.path.exists(symfs_dir): |
| 135 os.makedirs(symfs_dir) | 152 os.makedirs(symfs_dir) |
| 136 required_libs = set() | 153 required_libs = set() |
| 137 | 154 |
| 138 # Download the recorded perf profile. | 155 # Download the recorded perf profile. |
| 139 perf_profile = self._perf_instance.PullResult(symfs_dir) | 156 perf_profile = self._perf_instance.PullResult(symfs_dir) |
| 140 required_libs = \ | 157 required_libs = \ |
| 141 android_profiling_helper.GetRequiredLibrariesForPerfProfile( | 158 android_profiling_helper.GetRequiredLibrariesForPerfProfile( |
| 142 perf_profile) | 159 perf_profile) |
| 143 if not required_libs: | 160 if not required_libs: |
| 144 logging.warning('No libraries required by perf trace. Most likely there ' | 161 logging.warning('No libraries required by perf trace. Most likely there ' |
| 145 'are no samples in the trace.') | 162 'are no samples in the trace.') |
| 146 | 163 |
| 147 # Build a symfs with all the necessary libraries. | 164 # Build a symfs with all the necessary libraries. |
| 148 kallsyms = android_profiling_helper.CreateSymFs(self._device, | 165 kallsyms = android_profiling_helper.CreateSymFs(self._device, |
| 149 symfs_dir, | 166 symfs_dir, |
| 150 required_libs, | 167 required_libs, |
| 151 use_symlinks=False) | 168 use_symlinks=False) |
| 152 # Convert the perf profile into JSON. | |
| 153 perfhost_path = os.path.abspath(support_binaries.FindPath( | 169 perfhost_path = os.path.abspath(support_binaries.FindPath( |
| 154 'perfhost', 'linux')) | 170 'perfhost', 'linux')) |
| 171 | |
| 172 ui.PrintMessage('\nNote: to view the profile in perf, run:') | |
| 173 ui.PrintMessage(' ' + self._GetInteractivePerfCommand(perfhost_path, | |
| 174 perf_profile, symfs_dir, required_libs, kallsyms)) | |
| 175 | |
| 176 # Convert the perf profile into JSON. | |
| 155 perf_script_path = os.path.join(constants.DIR_SOURCE_ROOT, | 177 perf_script_path = os.path.join(constants.DIR_SOURCE_ROOT, |
| 156 'tools', 'telemetry', 'telemetry', 'core', 'platform', 'profiler', | 178 'tools', 'telemetry', 'telemetry', 'core', 'platform', 'profiler', |
| 157 'perf_vis', 'perf_to_tracing.py') | 179 'perf_vis', 'perf_to_tracing.py') |
| 158 json_file_name = os.path.basename(perf_profile) | 180 json_file_name = os.path.basename(perf_profile) |
| 159 with open(os.devnull, 'w') as dev_null, \ | 181 with open(os.devnull, 'w') as dev_null, \ |
| 160 open(json_file_name, 'w') as json_file: | 182 open(json_file_name, 'w') as json_file: |
| 161 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', | 183 cmd = [perfhost_path, 'script', '-s', perf_script_path, '-i', |
| 162 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] | 184 perf_profile, '--symfs', symfs_dir, '--kallsyms', kallsyms] |
| 163 subprocess.call(cmd, stdout=json_file, stderr=dev_null) | 185 subprocess.call(cmd, stdout=json_file, stderr=dev_null) |
| 164 return json_file_name | 186 return json_file_name |
| OLD | NEW |