• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5"""
6This is a profiler class for copying Profile-Guided-Optimization (PGO) data
7files back to the host. When Chrome is built with -fprofile-generate, it dumps
8its PGO data in a directory that this test copies back to test.profdir.
9
10The PGO data is found where the build happens in the chroot, which is hardcoded
11as the source_dir below.
12"""
13
14import logging
15import os
16import shutil
17import tarfile
18
19from autotest_lib.client.bin import profiler
20from autotest_lib.client.common_lib import error
21from autotest_lib.client.cros import cros_ui
22
23
24class pgo(profiler.profiler):
25    """The pgo profiler collects PGO data for Chrome."""
26    version = 1
27
28    def initialize(self, source_dir='/tmp/pgo/chrome'):
29        self._source_dir = source_dir
30
31
32    def start(self, test):
33        # Remove the .gcda files first.
34        if os.path.exists(self._source_dir):
35            shutil.rmtree(self._source_dir)
36
37
38    def stop(self, test):
39        if not cros_ui.stop_and_wait_for_chrome_to_exit(timeout_secs=40):
40            raise error.TestError('Could not stop Chrome')
41        if os.path.isdir(self._source_dir):
42            tar = tarfile.open(name=os.path.join(test.profdir, 'pgo.tar.bz2'),
43                               mode='w:bz2')
44            tar.add(self._source_dir, arcname='chrome', recursive=True)
45            tar.close()
46            versionfile = '/opt/google/chrome/profilelocation'
47            if os.path.isfile(versionfile):
48               shutil.copyfile(versionfile,
49                               os.path.join(test.profdir, 'profiledestination'))
50        else:
51            logging.error('PGO dir: %s not found', self._source_dir)
52        cros_ui.start(wait_for_login_prompt=False)
53