Пример #1
0
def SetupPrebuiltTools(device):
    # TODO(bulach): build the host tools for mac, and the targets for x86/mips.
    # Prebuilt tools from r226197.
    has_prebuilt = sys.platform.startswith('linux')
    if has_prebuilt:
        adb = AdbCommands(device)
        abi = adb.RunShellCommand('getprop ro.product.cpu.abi')
        has_prebuilt = abi and abi[0].startswith('armeabi')
    if not has_prebuilt:
        logging.error('Prebuilt tools only available for ARM.')
        return False

    prebuilt_tools = [
        'forwarder_dist/device_forwarder',
        'host_forwarder',
        'md5sum_dist/md5sum_bin',
        'md5sum_bin_host',
    ]
    for t in prebuilt_tools:
        src = os.path.basename(t)
        android_prebuilt_profiler_helper.GetIfChanged(src)
        dest = os.path.join(constants.GetOutDirectory(), t)
        if not os.path.exists(dest):
            logging.warning('Setting up prebuilt %s', dest)
            if not os.path.exists(os.path.dirname(dest)):
                os.makedirs(os.path.dirname(dest))
            shutil.copyfile(android_prebuilt_profiler_helper.GetHostPath(src),
                            dest)
            os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
    return True
Пример #2
0
    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:
            perf_pids = self._browser_backend.adb.Adb().ExtractPid('perf')
            self._browser_backend.adb.Adb().RunShellCommand(
                'kill -SIGINT ' + ' '.join(perf_pids))
            util.WaitFor(
                lambda: not self._browser_backend.adb.Adb().ExtractPid('perf'),
                timeout=2)
        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 = 'perf report'
        if self._is_android:
            self._browser_backend.adb.Adb().Adb().Pull(
                self._device_output_file, self._output_file)
            host_symfs = os.path.join(os.path.dirname(self._output_file),
                                      'data', 'app-lib')
            if not os.path.exists(host_symfs):
                os.makedirs(host_symfs)
                # On Android, the --symfs parameter needs to map a directory structure
                # similar to the device, that is:
                # --symfs=/tmp/foobar and then inside foobar there'll be something like
                # /tmp/foobar/data/app-lib/$PACKAGE/libname.so
                # Assume the symbolized library under out/Release/lib is equivalent to
                # the one in the device, and symlink it in the host to match --symfs.
                device_dir = filter(
                    lambda app_lib: app_lib.startswith(self._browser_backend.
                                                       package),
                    self._browser_backend.adb.Adb().RunShellCommand(
                        'ls /data/app-lib'))
                os.symlink(
                    os.path.abspath(
                        os.path.join(util.GetChromiumSrcDir(),
                                     os.environ.get('CHROMIUM_OUT_DIR', 'out'),
                                     'Release', 'lib')),
                    os.path.join(host_symfs, device_dir[0]))
            print 'On Android, assuming $CHROMIUM_OUT_DIR/Release/lib has a fresh'
            print 'symbolized library matching the one on device.'
            cmd = (android_prebuilt_profiler_helper.GetHostPath('perfhost') +
                   ' report --symfs %s' % os.path.dirname(self._output_file))
        print 'To view the profile, run:'
        print '  %s -n -i %s' % (cmd, self._output_file)
        return self._output_file
Пример #3
0
 def __init__(self, browser_backend, platform_backend, output_path, state):
     super(PerfProfiler, self).__init__(browser_backend, platform_backend,
                                        output_path, state)
     process_output_file_map = self._GetProcessOutputFileMap()
     self._process_profilers = []
     if platform_backend.GetOSName() == 'android':
         android_prebuilt_profiler_helper.GetIfChanged('perfhost')
         os.chmod(android_prebuilt_profiler_helper.GetHostPath('perfhost'),
                  stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
         android_prebuilt_profiler_helper.InstallOnDevice(
             browser_backend.adb, 'perf')
     for pid, output_file in process_output_file_map.iteritems():
         if 'zygote' in output_file:
             continue
         self._process_profilers.append(
             _SingleProcessPerfProfiler(pid, output_file, browser_backend,
                                        platform_backend))
Пример #4
0
def SetupPrebuiltTools(adb):
    # TODO(bulach): build the host tools for mac, and the targets for x86/mips.
    # Prebuilt tools from r226197.
    has_prebuilt = sys.platform.startswith('linux')
    if has_prebuilt:
        abi = adb.system_properties['ro.product.cpu.abi']
        has_prebuilt = abi.startswith('armeabi')
    if not has_prebuilt:
        logging.error(
            'Prebuilt android tools only available for Linux host and ARM device.'
        )
        return False

    prebuilt_tools = [
        'bitmaptools',
        'file_poller',
        'forwarder_dist/device_forwarder',
        'host_forwarder',
        'md5sum_dist/md5sum_bin',
        'md5sum_bin_host',
        'purge_ashmem',
    ]
    build_type = None
    for t in prebuilt_tools:
        src = os.path.basename(t)
        android_prebuilt_profiler_helper.GetIfChanged(src)
        bin_path = util.FindSupportBinary(t)
        if not build_type:
            build_type = GetBuildTypeOfPath(bin_path) or 'Release'
            constants.SetBuildType(build_type)
        dest = os.path.join(constants.GetOutDirectory(), t)
        if not bin_path:
            logging.warning('Setting up prebuilt %s', dest)
            if not os.path.exists(os.path.dirname(dest)):
                os.makedirs(os.path.dirname(dest))
            prebuilt_path = android_prebuilt_profiler_helper.GetHostPath(src)
            if not os.path.exists(prebuilt_path):
                raise NotImplementedError("""
%s must be checked into cloud storage.
Instructions:
http://www.chromium.org/developers/telemetry/upload_to_cloud_storage
""" % t)
            shutil.copyfile(prebuilt_path, dest)
            os.chmod(dest, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
    return True