def CreatePageSet(self, options): indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test', 'data', 'indexeddb') ps = page_set.PageSet(file_path=indexeddb_dir) ps.AddUserStory(page_module.Page('file://perf_test.html', ps, ps.base_dir)) return ps
def ParseAndroidEmulatorOptions(self): """Parses Android emulator args, and if necessary, starts an emulator. No-ops if --avd-config is not specified or if an emulator is already started. Performing this setup during argument parsing isn't ideal, but we need to set up the emulator sometime between arg parsing and browser finding. """ if not self.avd_config: return if BrowserFinderOptions.emulator_environment: return build_android_dir = os.path.join(util.GetChromiumSrcDir(), 'build', 'android') if not os.path.exists(build_android_dir): raise RuntimeError( '--avd-config specified, but Chromium //build/android directory not ' 'available') # Everything after this point only works if //build/android is actually # available, which we can't rely on, so use this to exit early in unittests. self._NoOpFunctionForTesting() sys.path.append(build_android_dir) # pylint: disable=import-error from pylib import constants as pylib_constants from pylib.local.emulator import local_emulator_environment # pylint: enable=import-error # We need to call this so that the Chromium output directory is set if it # is not explicitly specified via the command line argument/environment # variable. pylib_constants.CheckOutputDirectory() class AvdArgs(object): """A class to stand in for the AVD argparse.ArgumentParser object. Chromium's Android emulator code expects quite a few arguments from //build/android/test_runner.py, but the only one we actually care about here is avd_config. So, use a stand-in class with some sane defaults. """ def __init__(self, avd_config): self.avd_config = avd_config self.emulator_count = 1 self.emulator_window = False self.use_webview_provider = False self.replace_system_package = False self.denylist_file = None self.test_devices = [] self.enable_concurrent_adb = False self.logcat_output_dir = None self.logcat_output_file = None self.num_retries = 1 self.recover_devices = False self.skip_clear_data = True self.tool = None self.adb_path = None self.enable_device_cache = True avd_args = AvdArgs(self.avd_config) BrowserFinderOptions.emulator_environment =\ local_emulator_environment.LocalEmulatorEnvironment( avd_args, None, None) BrowserFinderOptions.emulator_environment.SetUp() atexit.register(BrowserFinderOptions.emulator_environment.TearDown)
def _DownloadGeneratedProfileArchive(self, options): """Download and extract profile directory archive if one exists.""" archive_name = getattr(self, 'generated_profile_archive', None) # If attribute not specified, nothing to do. if not archive_name: return # If profile dir specified on command line, nothing to do. if options.browser_options.profile_dir: logging.warning("Profile directory specified on command line: %s, this" "overrides the benchmark's default profile directory.", options.browser_options.profile_dir) return # Download profile directory from cloud storage. found_browser = browser_finder.FindBrowser(options) test_data_dir = os.path.join(util.GetChromiumSrcDir(), 'tools', 'perf', 'generated_profiles', found_browser.target_os) generated_profile_archive_path = os.path.normpath( os.path.join(test_data_dir, archive_name)) try: cloud_storage.GetIfChanged(generated_profile_archive_path, cloud_storage.PUBLIC_BUCKET) except (cloud_storage.CredentialsError, cloud_storage.PermissionError) as e: if os.path.exists(generated_profile_archive_path): # If the profile directory archive exists, assume the user has their # own local copy simply warn. logging.warning('Could not download Profile archive: %s', generated_profile_archive_path) else: # If the archive profile directory doesn't exist, this is fatal. logging.error('Can not run without required profile archive: %s. ' 'If you believe you have credentials, follow the ' 'instructions below.', generated_profile_archive_path) logging.error(e) sys.exit(-1) # Unzip profile directory. extracted_profile_dir_path = ( os.path.splitext(generated_profile_archive_path)[0]) if not os.path.isfile(generated_profile_archive_path): raise Exception("Profile directory archive not downloaded: ", generated_profile_archive_path) with zipfile.ZipFile(generated_profile_archive_path) as f: try: f.extractall(os.path.dirname(generated_profile_archive_path)) except e: # Cleanup any leftovers from unzipping. if os.path.exists(extracted_profile_dir_path): shutil.rmtree(extracted_profile_dir_path) logging.error("Error extracting profile directory zip file: %s", e) sys.exit(-1) # Run with freshly extracted profile directory. logging.info("Using profile archive directory: %s", extracted_profile_dir_path) options.browser_options.profile_dir = extracted_profile_dir_path
def CreatePageSet(self, options): indexeddb_dir = os.path.join(util.GetChromiumSrcDir(), 'chrome', 'test', 'data', 'indexeddb') ps = page_set.PageSet(file_path=indexeddb_dir) ps.AddPageWithDefaultRunNavigate('file://perf_test.html') return ps
# Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os import screenshot_sync_expectations as expectations from telemetry import test from telemetry.core import util from telemetry.page import page from telemetry.page import page_set from telemetry.page import page_test # pylint: disable=W0401,W0614 from telemetry.page.actions.all_page_actions import * data_path = os.path.join( util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') class _ScreenshotSyncValidator(page_test.PageTest): def CustomizeBrowserOptions(self, options): options.AppendExtraBrowserArgs('--enable-gpu-benchmarking') def ValidatePage(self, page, tab, results): test_success = tab.EvaluateJavaScript('window.__testSuccess') if not test_success: message = tab.EvaluateJavaScript('window.__testMessage') raise page_test.Failure(message) class ScreenshotSyncPage(page.Page): def __init__(self, page_set, base_dir): super(ScreenshotSyncPage, self).__init__(
def _GetStackFromMinidump(self, minidump): os_name = self.browser.platform.GetOSName() if os_name == 'win': cdb = self._GetCdbPath() if not cdb: logging.warning('cdb.exe not found.') return None output = subprocess.check_output([ cdb, '-y', self._browser_directory, '-c', '.ecxr;k30;q', '-z', minidump ]) # cdb output can start the stack with "ChildEBP", "Child-SP", and possibly # other things we haven't seen yet. If we can't find the start of the # stack, include output from the beginning. stack_start = 0 stack_start_match = re.search("^Child(?:EBP|-SP)", output, re.MULTILINE) if stack_start_match: stack_start = stack_start_match.start() stack_end = output.find('quit:') return output[stack_start:stack_end] arch_name = self.browser.platform.GetArchName() stackwalk = binary_manager.FetchPath('minidump_stackwalk', arch_name, os_name) if not stackwalk: logging.warning('minidump_stackwalk binary not found.') return None with open(minidump, 'rb') as infile: minidump += '.stripped' with open(minidump, 'wb') as outfile: outfile.write(''.join(infile.read().partition('MDMP')[1:])) symbols_path = os.path.join(self._tmp_minidump_dir, 'symbols') symbols = glob.glob( os.path.join(self._browser_directory, '*.breakpad*')) if symbols: for symbol in sorted(symbols, key=os.path.getmtime, reverse=True): if not os.path.isfile(symbol): continue with open(symbol, 'r') as f: fields = f.readline().split() if not fields: continue sha = fields[3] binary = ' '.join(fields[4:]) symbol_path = os.path.join(symbols_path, binary, sha) if os.path.exists(symbol_path): continue os.makedirs(symbol_path) shutil.copyfile(symbol, os.path.join(symbol_path, binary + '.sym')) else: # On some platforms generating the symbol table can be very time # consuming, skip it if there's nothing to dump. if self._IsExecutableStripped(): logging.info( '%s appears to be stripped, skipping symbol dump.' % (self._executable)) return logging.info('Dumping breakpad symbols.') generate_breakpad_symbols_path = os.path.join( util.GetChromiumSrcDir(), "components", "crash", "tools", "generate_breakpad_symbols.py") cmd = [ sys.executable, generate_breakpad_symbols_path, '--binary=%s' % self._executable, '--symbols-dir=%s' % symbols_path, '--build-dir=%s' % self._browser_directory, ] try: subprocess.check_output(cmd, stderr=open(os.devnull, 'w')) except subprocess.CalledProcessError: logging.warning('Failed to execute "%s"' % ' '.join(cmd)) return None return subprocess.check_output([stackwalk, minidump, symbols_path], stderr=open(os.devnull, 'w'))
def CreatePageSet(self, options): path = os.path.join(util.GetChromiumSrcDir(), 'third_party', 'WebKit', 'PerformanceTests', 'Animation') return _CreatePageSetFromPath(path)
def FindAllAvailableBrowsers(finder_options): """Finds all the desktop browsers available on this machine.""" browsers = [] if not CanFindAvailableBrowsers(): return [] has_display = True if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None): has_display = False # Look for a browser in the standard chrome build locations. if finder_options.chrome_root: chrome_root = finder_options.chrome_root else: chrome_root = util.GetChromiumSrcDir() flash_bin_dir = os.path.join(chrome_root, 'third_party', 'adobe', 'flash', 'binaries', 'ppapi') chromium_app_names = [] if sys.platform == 'darwin': chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium') chromium_app_names.append( 'Google Chrome.app/Contents/MacOS/Google Chrome') content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell' flash_bin = 'PepperFlashPlayer.plugin' flash_path = os.path.join(flash_bin_dir, 'mac', flash_bin) flash_path_64 = os.path.join(flash_bin_dir, 'mac_64', flash_bin) elif sys.platform.startswith('linux'): chromium_app_names.append('chrome') content_shell_app_name = 'content_shell' flash_bin = 'libpepflashplayer.so' flash_path = os.path.join(flash_bin_dir, 'linux', flash_bin) flash_path_64 = os.path.join(flash_bin_dir, 'linux_x64', flash_bin) elif sys.platform.startswith('win'): chromium_app_names.append('chrome.exe') content_shell_app_name = 'content_shell.exe' flash_bin = 'pepflashplayer.dll' flash_path = os.path.join(flash_bin_dir, 'win', flash_bin) flash_path_64 = os.path.join(flash_bin_dir, 'win_x64', flash_bin) else: raise Exception('Platform not recognized') def IsExecutable(path): return os.path.isfile(path) and os.access(path, os.X_OK) # Add the explicit browser executable if given. if finder_options.browser_executable: normalized_executable = os.path.expanduser( finder_options.browser_executable) if IsExecutable(normalized_executable): browser_directory = os.path.dirname( finder_options.browser_executable) browsers.append( PossibleDesktopBrowser('exact', finder_options, normalized_executable, flash_path, False, browser_directory)) else: logging.warning( '%s specified by browser_executable does not exist', normalized_executable) def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell): browser_directory = os.path.join(chrome_root, build_dir, type_dir) app = os.path.join(browser_directory, app_name) if IsExecutable(app): is_64 = browser_type.endswith('_x64') browsers.append( PossibleDesktopBrowser(browser_type, finder_options, app, flash_path_64 if is_64 else flash_path, content_shell, browser_directory, is_local_build=True)) return True return False # Add local builds for build_dir, build_type in util.GetBuildDirectories(): for chromium_app_name in chromium_app_names: AddIfFound(build_type.lower(), build_dir, build_type, chromium_app_name, False) AddIfFound('content-shell-' + build_type.lower(), build_dir, build_type, content_shell_app_name, True) # Mac-specific options. if sys.platform == 'darwin': mac_canary_root = '/Applications/Google Chrome Canary.app/' mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary' mac_system_root = '/Applications/Google Chrome.app' mac_system = mac_system_root + '/Contents/MacOS/Google Chrome' if IsExecutable(mac_canary): browsers.append( PossibleDesktopBrowser('canary', finder_options, mac_canary, None, False, mac_canary_root)) if IsExecutable(mac_system): browsers.append( PossibleDesktopBrowser('system', finder_options, mac_system, None, False, mac_system_root)) # Linux specific options. if sys.platform.startswith('linux'): # Look for a google-chrome instance. found = False try: with open(os.devnull, 'w') as devnull: found = subprocess.call(['google-chrome', '--version'], stdout=devnull, stderr=devnull) == 0 except OSError: pass if found: browsers.append( PossibleDesktopBrowser('system', finder_options, 'google-chrome', None, False, '/opt/google/chrome')) # Win32-specific options. if sys.platform.startswith('win'): system_path = os.path.join('Google', 'Chrome', 'Application') canary_path = os.path.join('Google', 'Chrome SxS', 'Application') win_search_paths = [ os.getenv('PROGRAMFILES(X86)'), os.getenv('PROGRAMFILES'), os.getenv('LOCALAPPDATA') ] def AddIfFoundWin(browser_name, app_path): browser_directory = os.path.join(path, app_path) for chromium_app_name in chromium_app_names: app = os.path.join(browser_directory, chromium_app_name) if IsExecutable(app): browsers.append( PossibleDesktopBrowser(browser_name, finder_options, app, None, False, browser_directory)) return True return False for path in win_search_paths: if not path: continue if AddIfFoundWin('canary', canary_path): break for path in win_search_paths: if not path: continue if AddIfFoundWin('system', system_path): break if len(browsers) and not has_display: logging.warning( 'Found (%s), but you do not have a DISPLAY environment set.' % ','.join([b.browser_type for b in browsers])) return [] return browsers
import logging import optparse import os import shlex import sys from telemetry.core import browser_finder from telemetry.core import browser_finder_exceptions from telemetry.core import platform from telemetry.core import profile_types from telemetry.core import util from telemetry.core import wpr_modes from telemetry.core.platform.profiler import profiler_finder util.AddDirToPythonPath( util.GetChromiumSrcDir(), 'third_party', 'webpagereplay') import net_configs # pylint: disable=F0401 class BrowserFinderOptions(optparse.Values): """Options to be used for discovering a browser.""" def __init__(self, browser_type=None): optparse.Values.__init__(self) self.browser_type = browser_type self.browser_executable = None self.chrome_root = None self.android_device = None self.cros_ssh_identity = None
import os import random import shutil import StringIO import sys import tempfile from catapult_base import cloud_storage from telemetry.core import util from telemetry.internal.util import file_handle from telemetry.timeline import trace_data as trace_data_module from telemetry import value as value_module # Bring in tv module for transforming raw trace to html form. util.AddDirToPythonPath( util.GetChromiumSrcDir(), 'third_party', 'catapult') from tracing.build import trace2html class TraceValue(value_module.Value): def __init__(self, page, trace_data, important=False, description=None): """A value that contains a TraceData object and knows how to output it. Adding TraceValues and outputting as JSON will produce a directory full of HTML files called trace_files. Outputting as chart JSON will also produce an index, files.html, linking to each of these files. """ super(TraceValue, self).__init__( page, name='trace', units='', important=important,
def _GetUnitJson(self): with open(os.path.join(util.GetChromiumSrcDir(), *_UNIT_JSON)) as f: return f.read()
def _GetPlugins(self): plugins = '' for p in _PLUGINS: with open(os.path.join(util.GetChromiumSrcDir(), *p)) as f: plugins += f.read() return plugins
def ZipDependencies(paths, dependencies, options): base_dir = os.path.dirname(os.path.realpath(util.GetChromiumSrcDir())) with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file: # Add dependencies to archive. for path in dependencies: path_in_archive = os.path.join('telemetry', os.path.relpath(path, base_dir)) zip_file.write(path, path_in_archive) # Add symlinks to executable paths, for ease of use. for path in paths: link_info = zipfile.ZipInfo( os.path.join('telemetry', os.path.basename(path))) link_info.create_system = 3 # Unix attributes. # 010 is regular file, 0111 is the permission bits rwxrwxrwx. link_info.external_attr = 0100777 << 16 # Octal. relative_path = os.path.relpath(path, base_dir) link_script = ( '#!/usr/bin/env python\n\n' 'import os\n' 'import sys\n\n\n' 'script = os.path.join(os.path.dirname(__file__), \'%s\')\n' 'os.execv(sys.executable, [sys.executable, script] + sys.argv[1:])' % relative_path) zip_file.writestr(link_info, link_script) # Add gsutil to the archive, if it's available. The gsutil in # depot_tools is modified to allow authentication using prodaccess. # TODO: If there's a gsutil in telemetry/third_party/, bootstrap_deps # will include it. Then there will be two copies of gsutil at the same # location in the archive. This can be confusing for users. gsutil_path = os.path.realpath(cloud_storage.FindGsutil()) if cloud_storage.SupportsProdaccess(gsutil_path): gsutil_base_dir = os.path.join(os.path.dirname(gsutil_path), os.pardir) gsutil_dependencies = path_set.PathSet() gsutil_dependencies.add(os.path.dirname(gsutil_path)) # Also add modules from depot_tools that are needed by gsutil. gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'boto')) gsutil_dependencies.add( os.path.join(gsutil_base_dir, 'fancy_urllib')) gsutil_dependencies.add( os.path.join(gsutil_base_dir, 'retry_decorator')) gsutil_dependencies -= FindExcludedFiles(set(gsutil_dependencies), options) # Also add upload.py to the archive from depot_tools, if it is available. # This allows us to post patches without requiring a full depot_tools # install. There's no real point in including upload.py if we do not # also have gsutil, which is why this is inside the gsutil block. gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'upload.py')) for path in gsutil_dependencies: path_in_archive = os.path.join( 'telemetry', os.path.relpath(util.GetTelemetryDir(), base_dir), 'third_party', os.path.relpath(path, gsutil_base_dir)) zip_file.write(path, path_in_archive)
import logging import os import random import shutil import StringIO import sys import tempfile from catapult_base import cloud_storage from telemetry.core import util from telemetry.internal.util import file_handle from telemetry.timeline import trace_data as trace_data_module from telemetry import value as value_module # Bring in tv module for transforming raw trace to html form. util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'third_party', 'trace-viewer') from trace_viewer.build import trace2html # pylint:disable=import-error class TraceValue(value_module.Value): def __init__(self, page, trace_data, important=False, description=None): """A value that contains a TraceData object and knows how to output it. Adding TraceValues and outputting as JSON will produce a directory full of HTML files called trace_files. Outputting as chart JSON will also produce an index, files.html, linking to each of these files. """ super(TraceValue, self).__init__(page,
def CreateParser(self, *args, **kwargs): parser = optparse.OptionParser(*args, **kwargs) # Selection group group = optparse.OptionGroup(parser, 'Which browser to use') group.add_option('--browser', dest='browser_type', default=None, help='Browser type to run, ' 'in order of priority. Supported values: list,%s' % ','.join(browser_finder.ALL_BROWSER_TYPES)) group.add_option('--browser-executable', dest='browser_executable', help='The exact browser to run.') group.add_option('--chrome-root', dest='chrome_root', help='Where to look for chrome builds.' 'Defaults to searching parent dirs by default.') group.add_option( '--device', dest='android_device', help='The android device ID to use' 'If not specified, only 0 or 1 connected devcies are supported.') group.add_option( '--remote', dest='cros_remote', help='The IP address of a remote ChromeOS device to use.') identity = None testing_rsa = os.path.join(util.GetChromiumSrcDir(), 'third_party', 'chromite', 'ssh_keys', 'testing_rsa') if os.path.exists(testing_rsa): identity = testing_rsa group.add_option( '--identity', dest='cros_ssh_identity', default=identity, help= 'The identity file to use when ssh\'ing into the ChromeOS device') parser.add_option_group(group) # Debugging options group = optparse.OptionGroup(parser, 'When things go wrong') profiler_choices = profiler_finder.GetAllAvailableProfilers() group.add_option( '--profiler', default=None, type='choice', choices=profiler_choices, help='Record profiling data using this tool. Supported values: ' + ', '.join(profiler_choices)) group.add_option( '--interactive', dest='interactive', action='store_true', help= 'Let the user interact with the page; the actions specified for ' 'the page are not run.') group.add_option('-v', '--verbose', action='count', dest='verbosity', help='Increase verbosity level (repeat as needed)') group.add_option('--print-bootstrap-deps', action='store_true', help='Output bootstrap deps list.') parser.add_option_group(group) # Platform options group = optparse.OptionGroup(parser, 'Platform options') group.add_option( '--no-performance-mode', action='store_true', help='Some platforms run on "full performance mode" where the ' 'test is executed at maximum CPU speed in order to minimize noise ' '(specially important for dashboards / continuous builds). ' 'This option prevents Telemetry from tweaking such platform settings.' ) group.add_option( '--report-root-metrics', action='store_true', dest='report_root_metrics', help='Enable metrics that require root access to record.') group.add_option('--android-rndis', dest='android_rndis', default=False, action='store_true', help='Use RNDIS forwarding on Android.') group.add_option('--no-android-rndis', dest='android_rndis', action='store_false', help='Do not use RNDIS forwarding on Android.' ' [default]') parser.add_option_group(group) # Browser options. self.browser_options.AddCommandLineArgs(parser) real_parse = parser.parse_args def ParseArgs(args=None): defaults = parser.get_default_values() for k, v in defaults.__dict__.items(): if k in self.__dict__ and self.__dict__[k] != None: continue self.__dict__[k] = v ret = real_parse(args, self) # pylint: disable=E1121 if self.verbosity >= 2: logging.getLogger().setLevel(logging.DEBUG) elif self.verbosity: logging.getLogger().setLevel(logging.INFO) else: logging.getLogger().setLevel(logging.WARNING) if self.browser_executable and not self.browser_type: self.browser_type = 'exact' if self.browser_type == 'list': try: types = browser_finder.GetAllAvailableBrowserTypes(self) except browser_finder.BrowserFinderException, ex: sys.stderr.write('ERROR: ' + str(ex)) sys.exit(1) sys.stdout.write('Available browsers:\n') sys.stdout.write(' %s\n' % '\n '.join(types)) sys.exit(0) # Parse browser options. self.browser_options.UpdateFromParseResults(self) return ret
# Copyright (c) 2013 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os from telemetry import test as test_module from telemetry.core import exceptions from telemetry.core import util from telemetry.page import page from telemetry.page import page_set # pylint: disable=W0401,W0614 from telemetry.page import page_test from telemetry.page.actions.all_page_actions import * data_path = os.path.join(util.GetChromiumSrcDir(), 'content', 'test', 'data', 'gpu') wait_timeout = 20 # seconds harness_script = r""" var domAutomationController = {}; domAutomationController._loaded = false; domAutomationController._succeeded = false; domAutomationController._finished = false; domAutomationController.setAutomationId = function(id) {} domAutomationController.send = function(msg) { msg = msg.toLowerCase() if (msg == "loaded") {
import logging import os import sys from telemetry.core.backends.webdriver import webdriver_ie_backend from telemetry.core import browser from telemetry.core import platform as platform_module from telemetry.core.platform import desktop_device from telemetry.core import possible_browser from telemetry.core import util from telemetry.util import support_binaries # Try to import the selenium python lib which may be not available. util.AddDirToPythonPath( util.GetChromiumSrcDir(), 'third_party', 'webdriver', 'pylib') try: from selenium import webdriver # pylint: disable=F0401 except ImportError: webdriver = None class PossibleWebDriverBrowser(possible_browser.PossibleBrowser): """A browser that can be controlled through webdriver API.""" def __init__(self, browser_type, finder_options): target_os = sys.platform.lower() super(PossibleWebDriverBrowser, self).__init__(browser_type, target_os, supports_tab_control=False) assert browser_type in FindAllBrowserTypes(finder_options), \ ('Please add %s to webdriver_desktop_browser_finder.FindAllBrowserTypes'
def GetStackTrace(self): """Returns a recent stack trace from a crash. The stack trace consists of raw logcat dump, logcat dump with symbols, and stack info from tombstone files, all concatenated into one string. """ def Decorate(title, content): if not content or content.isspace(): content = ('**EMPTY** - could be explained by log messages ' 'preceding the previous python Traceback - best wishes') return "%s\n%s\n%s\n" % (title, content, '*' * 80) # Get the UI nodes that can be found on the screen ret = Decorate('UI dump', '\n'.join(self.GetSystemUi().ScreenDump())) # Get the last lines of logcat (large enough to contain stacktrace) logcat = self.GetLogCat() ret += Decorate('Logcat', logcat) # Determine the build directory. build_path = '.' for b in util.GetBuildDirectories(): if os.path.exists(b): build_path = b break # Try to symbolize logcat. chromium_src_dir = util.GetChromiumSrcDir() stack = os.path.join(chromium_src_dir, 'third_party', 'android_platform', 'development', 'scripts', 'stack') if _ExecutableExists(stack): cmd = [stack] arch = self.GetArchName() arch = _ARCH_TO_STACK_TOOL_ARCH.get(arch, arch) cmd.append('--arch=%s' % arch) cmd.append('--output-directory=%s' % build_path) p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) ret += Decorate('Stack from Logcat', p.communicate(input=logcat)[0]) # Try to get tombstones. tombstones = os.path.join(chromium_src_dir, 'build', 'android', 'tombstones.py') if _ExecutableExists(tombstones): tombstones_cmd = [ tombstones, '-w', '--device', self._device.adb.GetDeviceSerial(), '--adb-path', self._device.adb.GetAdbPath(), ] ret += Decorate('Tombstones', subprocess.Popen(tombstones_cmd, stdout=subprocess.PIPE).communicate()[0]) # Attempt to get detailed stack traces with Crashpad. stackwalker_path = os.path.join(chromium_src_dir, 'build', 'android', 'stacktrace', 'crashpad_stackwalker.py') minidump_stackwalk_path = os.path.join(build_path, 'minidump_stackwalk') if (_ExecutableExists(stackwalker_path) and _ExecutableExists(minidump_stackwalk_path)): crashpad_cmd = [ stackwalker_path, '--device', self._device.adb.GetDeviceSerial(), '--adb-path', self._device.adb.GetAdbPath(), '--build-path', build_path, '--chrome-cache-path', os.path.join( self.GetProfileDir( self._ExtractLastNativeCrashPackageFromLogcat(logcat)), 'cache'), ] ret += Decorate('Crashpad stackwalk', subprocess.Popen(crashpad_cmd, stdout=subprocess.PIPE).communicate()[0]) return (True, ret)
# Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import datetime import json import logging import os import re import sys from telemetry.core import util from telemetry.page import buildbot_page_measurement_results # Get build/util scripts into our path. sys.path.append( os.path.abspath(os.path.join(util.GetChromiumSrcDir(), 'build', 'util'))) import lastchange # pylint: disable=F0401 _TEMPLATE_HTML_PATH = os.path.join(util.GetTelemetryDir(), 'support', 'html_output', 'results-template.html') _PLUGINS = [('third_party', 'flot', 'jquery.flot.min.js'), ('third_party', 'WebKit', 'PerformanceTests', 'resources', 'jquery.tablesorter.min.js'), ('third_party', 'WebKit', 'PerformanceTests', 'resources', 'statistics.js')] _UNIT_JSON = ('tools', 'perf', 'unit-info.json') class HtmlPageMeasurementResults( buildbot_page_measurement_results.BuildbotPageMeasurementResults): def __init__(self,
# found in the LICENSE file. """Start and stop Web Page Replay.""" import logging import os import re import signal import subprocess import sys import urllib from telemetry.core import util _REPLAY_DIR = os.path.join( util.GetChromiumSrcDir(), 'third_party', 'webpagereplay') _LOG_FILE_PATH = os.path.join( util.GetChromiumSrcDir(), 'webpagereplay_logs', 'logs.txt') class ReplayError(Exception): """Catch-all exception for the module.""" pass class ReplayNotFoundError(ReplayError): def __init__(self, label, path): super(ReplayNotFoundError, self).__init__() self.args = (label, path) def __str__(self):
def _GetPlugins(self): plugins = '' for p in _PLUGINS: plugins += open(os.path.join(util.GetChromiumSrcDir(), *p), 'r').read() return plugins
def _PrepareAndroidSymfs(self): """Create a symfs directory using an Android device. Create a symfs directory by pulling the necessary files from an Android device. Returns: List of arguments to be passed to perf to point it to the created symfs. """ assert self._is_android device = self._browser_backend.adb.device() device.old_interface.Adb().Pull(self._device_output_file, self._output_file) symfs_dir = os.path.dirname(self._output_file) host_app_symfs = os.path.join(symfs_dir, 'data', 'app-lib') if not os.path.exists(host_app_symfs): os.makedirs(host_app_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), device.old_interface.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_app_symfs, device_dir[0])) # Also pull copies of common system libraries from the device so perf can # resolve their symbols. Only copy a subset of libraries to make this # faster. # TODO(skyostil): Find a way to pull in all system libraries without being # too slow. host_system_symfs = os.path.join(symfs_dir, 'system', 'lib') if not os.path.exists(host_system_symfs): os.makedirs(host_system_symfs) common_system_libs = [ 'libandroid*.so', 'libart.so', 'libc.so', 'libdvm.so', 'libEGL*.so', 'libGL*.so', 'libm.so', 'libRS.so', 'libskia.so', 'libstdc++.so', 'libstlport.so', 'libz.so', ] for lib in common_system_libs: device.old_interface.Adb().Pull('/system/lib/%s' % lib, host_system_symfs) # Pull a copy of the kernel symbols. host_kallsyms = os.path.join(symfs_dir, 'kallsyms') if not os.path.exists(host_kallsyms): device.old_interface.Adb().Pull('/proc/kallsyms', host_kallsyms) return ['--kallsyms', host_kallsyms, '--symfs', symfs_dir]
def _GetUnitJson(self): return open(os.path.join(util.GetChromiumSrcDir(), *_UNIT_JSON), 'r').read()
# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import os from telemetry.core import util from telemetry.core.backends.chrome import android_browser_finder from telemetry.core.platform import profiler util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') try: from pylib.device import device_errors # pylint: disable=F0401 except ImportError: device_errors = None class AndroidTraceviewProfiler(profiler.Profiler): """Collects a Traceview on Android.""" _DEFAULT_DEVICE_DIR = '/data/local/tmp/traceview' def __init__(self, browser_backend, platform_backend, output_path, state): super(AndroidTraceviewProfiler, self).__init__(browser_backend, platform_backend, output_path, state) if self._browser_backend.adb.device().FileExists( self._DEFAULT_DEVICE_DIR): self._browser_backend.adb.RunShellCommand( 'rm ' + os.path.join(self._DEFAULT_DEVICE_DIR, '*'))
# found in the LICENSE file. """Start and stop Web Page Replay.""" import logging import os import re import signal import subprocess import sys import tempfile import urllib from telemetry.core import exceptions from telemetry.core import util _REPLAY_DIR = os.path.join(util.GetChromiumSrcDir(), 'third_party', 'webpagereplay') class ReplayError(Exception): """Catch-all exception for the module.""" pass class ReplayNotFoundError(ReplayError): def __init__(self, label, path): super(ReplayNotFoundError, self).__init__() self.args = (label, path) def __str__(self): label, path = self.args