def CollectProfile(self): if ('renderer' in self._output_file and not self._is_android and not self._platform_backend.GetCommandLine(self._pid)): logging.warning('Renderer was swapped out during profiling. ' 'To collect a full profile rerun with ' '"--extra-browser-args=--single-process"') if self._is_android: device = self._browser_backend.device try: binary_name = os.path.basename(self._perf_binary) device.KillAll(binary_name, signum=signal.SIGINT, blocking=True, quiet=True) except device_errors.CommandFailedError: logging.warning( 'The perf process could not be killed on the device.') self._proc.send_signal(signal.SIGINT) exit_code = self._proc.wait() try: if exit_code == 128: raise Exception("""perf failed with exit code 128. Try rerunning this script under sudo or setting /proc/sys/kernel/perf_event_paranoid to "-1".\nOutput:\n%s""" % self._GetStdOut()) elif exit_code not in (0, -2): raise Exception('perf failed with exit code %d. Output:\n%s' % (exit_code, self._GetStdOut())) finally: self._tmp_output_file.close() cmd = '%s report -n -i %s' % (_NicePath( self._perfhost_binary), self._output_file) if self._is_android: device = self._browser_backend.device device.PullFile(self._device_output_file, self._output_file) required_libs = \ android_profiling_helper.GetRequiredLibrariesForPerfProfile( self._output_file) symfs_root = os.path.join(os.path.dirname(self._output_file), 'symfs') if not os.path.exists(symfs_root): os.makedirs(symfs_root) kallsyms = android_profiling_helper.CreateSymFs(device, symfs_root, required_libs, use_symlinks=True) cmd += ' --symfs %s --kallsyms %s' % (symfs_root, kallsyms) for lib in required_libs: lib = os.path.join(symfs_root, lib[1:]) if not os.path.exists(lib): continue objdump_path = android_profiling_helper.GetToolchainBinaryPath( lib, 'objdump') if objdump_path: cmd += ' --objdump %s' % _NicePath(objdump_path) break print 'To view the profile, run:' print ' ', cmd return self._output_file
def _GetInteractivePerfCommand(perfhost_path, perf_profile, symfs_dir, required_libs, kallsyms): cmd = '%s report -n -i %s --symfs %s --kallsyms %s' % (os.path.relpath( perfhost_path, '.'), perf_profile, symfs_dir, kallsyms) for lib in required_libs: lib = os.path.join(symfs_dir, lib[1:]) if not os.path.exists(lib): continue objdump_path = android_profiling_helper.GetToolchainBinaryPath( lib, 'objdump') if objdump_path: cmd += ' --objdump %s' % os.path.relpath(objdump_path, '.') break return cmd
def testGetToolchainBinaryPath(self): with tempfile.NamedTemporaryFile() as libc: self._device.PullFile('/system/lib/libc.so', libc.name) path = android_profiling_helper.GetToolchainBinaryPath( libc.name, 'objdump') assert path and os.path.exists(path)