コード例 #1
0
ファイル: snap_page_util.py プロジェクト: zhaojunmin/catapult
def SnapPage(finder_options, url, interactive, snapshot_file):
    """ Save the HTML snapshot of the page whose address is |url| to
  |snapshot_file|.
  """
    possible_browser = browser_finder.FindBrowser(finder_options)
    browser = possible_browser.Create(finder_options)
    try:
        tab = browser.tabs[0]
        tab.Navigate(url)
        tab.WaitForDocumentReadyStateToBeComplete()
        if interactive:
            raw_input(
                'Activating interactive mode. Press enter after you finish '
                "interacting with the page to snapshot the page's DOM content."
            )
        with open(
                os.path.join(util.GetTelemetryThirdPartyDir(), 'snap-it',
                             'HTMLSerializer.js')) as f:
            snapit_script = f.read()
        tab.ExecuteJavaScript(snapit_script)
        tab.ExecuteJavaScript('''
        var serializedDomArray;
        var htmlSerializer = new HTMLSerializer();
        htmlSerializer.processDocument(document);
        htmlSerializer.fillHolesAsync(document, function(s) {
          serializedDomArray = s.html;
        });
        ''')
        print 'Snapshotting content of %s. This could take a while...' % url
        tab.WaitForJavaScriptCondition('serializedDomArray !== undefined')
        serialized_dom = ''.join(tab.EvaluateJavaScript('serializedDomArray'))
        snapshot_file.write(serialized_dom)
    finally:
        browser.Close()
コード例 #2
0
    def CreateParser(self, *args, **kwargs):
        parser = optparse.OptionParser(*args, **kwargs)

        # Options to interact with a potential external results processor.
        parser.set_defaults(
            external_results_processor=False,
            intermediate_dir=None,
            # TODO(crbug.com/928275): Remove these when Telemetry is no longer
            # involved in any results processing.
            output_dir=None,
            output_formats=[],
            legacy_output_formats=[],
            reset_results=True,
            results_label='telemetry_run',
            upload_results=False,
            upload_bucket=None)

        # 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.FindAllBrowserTypes()))
        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(
            '--chromium-output-directory',
            dest='chromium_output_dir',
            help='Where to look for build artifacts. '
            'Can also be specified by setting environment variable '
            'CHROMIUM_OUTPUT_DIR.')
        group.add_option(
            '--remote',
            dest='cros_remote',
            help='The hostname of a remote ChromeOS device to use.')
        group.add_option(
            '--remote-ssh-port',
            type=int,
            default=socket.getservbyname('ssh'),
            dest='cros_remote_ssh_port',
            help=
            'The SSH port of the remote ChromeOS device (requires --remote).')
        compat_mode_options_list = [
            compat_mode_options.NO_FIELD_TRIALS,
            compat_mode_options.IGNORE_CERTIFICATE_ERROR,
            compat_mode_options.LEGACY_COMMAND_LINE_PATH,
            compat_mode_options.GPU_BENCHMARKING_FALLBACKS,
            compat_mode_options.DONT_REQUIRE_ROOTED_DEVICE
        ]
        parser.add_option(
            '--compatibility-mode',
            action='append',
            dest='compatibility_mode',
            choices=compat_mode_options_list,
            default=[],
            help='Select the compatibility change that you want to enforce when '
            'running benchmarks. The options are: %s' %
            ', '.join(compat_mode_options_list))
        parser.add_option(
            '--experimental-proto-trace-format',
            action='store_true',
            help='Request traces from Chrome in protobuf file format.')
        identity = None
        testing_rsa = os.path.join(util.GetTelemetryThirdPartyDir(),
                                   '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')
        group.add_option('--print-bootstrap-deps',
                         action='store_true',
                         help='Output bootstrap deps list.')
        group.add_option(
            '--extra-chrome-categories',
            dest='extra_chrome_categories',
            type=str,
            help=
            'Filter string to enable additional chrome tracing categories. See'
            ' documentation here: https://cs.chromium.org/chromium/src/base/'
            'trace_event/trace_config.h?rcl='
            'c8db6c6371ca047c24d41f3972d5819bc83d83ae&l=125')
        group.add_option(
            '--extra-atrace-categories',
            dest='extra_atrace_categories',
            type=str,
            help='Comma-separated list of extra atrace categories. Use atrace'
            ' --list_categories to get full list.')
        group.add_option(
            '--enable-systrace',
            dest='enable_systrace',
            action='store_true',
            help='Enable collection of systrace. (Useful on ChromeOS where'
            ' atrace is not supported; collects scheduling information.)')
        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.'
        )
        # TODO(crbug.com/1025207): Rename this to --support-apk
        group.add_option(
            '--webview-embedder-apk',
            action="append",
            default=[],
            help=
            'When running tests on android webview, more than one apk needs to'
            ' be installed. The apk running the test is said to embed webview. More'
            ' than one apk may be specified if needed.')
        parser.add_option_group(group)

        # Remote platform options
        group = optparse.OptionGroup(parser, 'Remote platform options')
        group.add_option('--android-blacklist-file',
                         help='Device blacklist JSON file.')
        group.add_option(
            '--device',
            help='The device ID to use. '
            'If not specified, only 0 or 1 connected devices are supported. '
            'If specified as "android", all available Android devices are '
            'used.')
        group.add_option(
            '--install-bundle-module',
            dest='modules_to_install',
            action='append',
            default=[],
            help=
            'Specify Android App Bundle modules to install in addition to the '
            'base module. Ignored on Non-Android platforms.')
        parser.add_option_group(group)

        group = optparse.OptionGroup(parser, 'Fuchsia platform options')
        group.add_option(
            '--fuchsia-output-dir',
            default='out/Release',
            help='Specify the build directory for the Fuchsia OS installed on '
            'the device.')
        parser.add_option_group(group)

        # CPU profiling on Android/Linux/ChromeOS.
        group = optparse.OptionGroup(
            parser, ('CPU profiling over intervals of interest, '
                     'Android, Linux, and ChromeOS only'))
        group.add_option(
            '--interval-profiling-target',
            dest='interval_profiling_target',
            default='renderer:main',
            metavar='PROCESS_NAME[:THREAD_NAME]|"system_wide"',
            help=
            'Run the CPU profiler on this process/thread (default=%default), '
            'which is supported only on Linux and Android, or system-wide, which '
            'is supported only on ChromeOS.')
        group.add_option(
            '--interval-profiling-period',
            dest='interval_profiling_periods',
            type='choice',
            choices=('navigation', 'interactions', 'story_run'),
            action='append',
            default=[],
            metavar='PERIOD',
            help='Run the CPU profiler during this test period. '
            'May be specified multiple times except when the story_run period is '
            'used; available choices are ["navigation", "interactions", '
            '"story_run"]. Profile data will be written to '
            'artifacts/*.perf.data (Android/ChromeOS) or '
            'artifacts/*.profile.pb (Linux) files in the output directory. See '
            'https://developer.android.com/ndk/guides/simpleperf for more info on '
            'Android profiling via simpleperf.')
        group.add_option(
            '--interval-profiling-frequency',
            default=1000,
            metavar='FREQUENCY',
            type=int,
            help='Frequency of CPU profiling samples, in samples per second '
            '(default=%default). This flag is used only on Android')
        group.add_option(
            '--interval-profiler-options',
            dest='interval_profiler_options',
            type=str,
            metavar='"--flag <options> ..."',
            help='Addtional arguments to pass to the CPU profiler. This is used '
            'only on ChromeOS. On ChromeOS, pass the linux perf\'s subcommand name '
            'followed by the options to pass to the perf tool. Supported perf '
            'subcommands are "record" and "stat". '
            'Eg: "record -e cycles -c 4000000 -g". Note: "-a" flag is added to the '
            'perf command by default. Do not pass options that are incompatible '
            'with the system-wide profile collection.')
        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.chromium_output_dir:
                os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir

            # Parse remote platform options.
            self.BuildRemotePlatformOptions()

            if self.remote_platform_options.device == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                print 'Available devices:'
                for device in devices:
                    print ' ', device.name
                sys.exit(0)

            if self.browser_executable and not self.browser_type:
                self.browser_type = 'exact'
            if self.browser_type == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                if not devices:
                    sys.exit(0)
                browser_types = {}
                for device in devices:
                    try:
                        possible_browsers = browser_finder.GetAllAvailableBrowsers(
                            self, device)
                        browser_types[device.name] = sorted([
                            browser.browser_type
                            for browser in possible_browsers
                        ])
                    except browser_finder_exceptions.BrowserFinderException as ex:
                        print >> sys.stderr, 'ERROR: ', ex
                        sys.exit(1)
                print 'Available browsers:'
                if len(browser_types) == 0:
                    print '  No devices were found.'
                for device_name in sorted(browser_types.keys()):
                    print '  ', device_name
                    for browser_type in browser_types[device_name]:
                        print '    ', browser_type
                    if len(browser_types[device_name]) == 0:
                        print '     No browsers found for this device'
                sys.exit(0)

            # Profiling other periods along with the story_run period leads to running
            # multiple profiling processes at the same time. The effects of performing
            # muliple CPU profiling at the same time is unclear and may generate
            # incorrect profiles so this will not be supported.
            if (len(self.interval_profiling_periods) > 1
                    and 'story_run' in self.interval_profiling_periods):
                print 'Cannot specify other periods along with the story_run period.'
                sys.exit(1)

            self.interval_profiler_options = shlex.split(
                self.interval_profiler_options)

            # Parse browser options.
            self.browser_options.UpdateFromParseResults(self)

            return ret

        parser.parse_args = ParseArgs
        return parser
コード例 #3
0
import time

try:
    import fcntl
except ImportError:
    fcntl = None

from telemetry.core import exceptions
from telemetry.core import util
from telemetry.internal.util import ps_util

import py_utils
from py_utils import retry_util
from py_utils import atexit_with_log

_TSPROXY_PATH = os.path.join(util.GetTelemetryThirdPartyDir(), 'tsproxy',
                             'tsproxy.py')


def ParseTsProxyPortFromOutput(output_line):
    port_re = re.compile(r'Started Socks5 proxy server on '
                         r'(?P<host>[^:]*):'
                         r'(?P<port>\d+)')
    m = port_re.match(output_line)
    if m:
        return int(m.group('port'))


class TsProxyServer(object):
    """Start and Stop Tsproxy.
コード例 #4
0
    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.FindAllBrowserTypes(self)))
        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(
            '--chromium-output-directory',
            dest='chromium_output_dir',
            help='Where to look for build artifacts. '
            'Can also be specified by setting environment variable '
            'CHROMIUM_OUTPUT_DIR.')
        group.add_option(
            '--remote',
            dest='cros_remote',
            help='The hostname of a remote ChromeOS device to use.')
        group.add_option(
            '--remote-ssh-port',
            type=int,
            default=socket.getservbyname('ssh'),
            dest='cros_remote_ssh_port',
            help=
            'The SSH port of the remote ChromeOS device (requires --remote).')
        identity = None
        testing_rsa = os.path.join(util.GetTelemetryThirdPartyDir(),
                                   '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: %s. '
            '(Notice: this flag cannot be used for Timeline Based Measurement '
            'benchmarks.)' % ', '.join(profiler_choices))
        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(
            '--webview-embedder-apk',
            help=
            'When running tests on android webview, more than one apk needs to'
            ' be installed. The apk running the test is said to embed webview.'
        )
        parser.add_option_group(group)

        # Remote platform options
        group = optparse.OptionGroup(parser, 'Remote platform options')
        group.add_option('--android-blacklist-file',
                         help='Device blacklist JSON file.')
        group.add_option(
            '--device',
            help='The device ID to use. '
            'If not specified, only 0 or 1 connected devices are supported. '
            'If specified as "android", all available Android devices are '
            'used.')
        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.chromium_output_dir:
                os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir

            # Parse remote platform options.
            self.BuildRemotePlatformOptions()

            if self.remote_platform_options.device == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                print 'Available devices:'
                for device in devices:
                    print ' ', device.name
                sys.exit(0)

            if self.browser_executable and not self.browser_type:
                self.browser_type = 'exact'
            if self.browser_type == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                if not devices:
                    sys.exit(0)
                browser_types = {}
                for device in devices:
                    try:
                        possible_browsers = browser_finder.GetAllAvailableBrowsers(
                            self, device)
                        browser_types[device.name] = sorted([
                            browser.browser_type
                            for browser in possible_browsers
                        ])
                    except browser_finder_exceptions.BrowserFinderException as ex:
                        print >> sys.stderr, 'ERROR: ', ex
                        sys.exit(1)
                print 'Available browsers:'
                if len(browser_types) == 0:
                    print '  No devices were found.'
                for device_name in sorted(browser_types.keys()):
                    print '  ', device_name
                    for browser_type in browser_types[device_name]:
                        print '    ', browser_type
                sys.exit(0)

            # Parse browser options.
            self.browser_options.UpdateFromParseResults(self)

            return ret

        parser.parse_args = ParseArgs
        return parser
コード例 #5
0
    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.FindAllBrowserTypes(self)))
        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(
            '--chromium-output-directory',
            dest='chromium_output_dir',
            help='Where to look for build artifacts. '
            'Can also be specified by setting environment variable '
            'CHROMIUM_OUTPUT_DIR.')
        group.add_option(
            '--remote',
            dest='cros_remote',
            help='The hostname of a remote ChromeOS device to use.')
        group.add_option(
            '--remote-ssh-port',
            type=int,
            default=socket.getservbyname('ssh'),
            dest='cros_remote_ssh_port',
            help=
            'The SSH port of the remote ChromeOS device (requires --remote).')
        parser.add_option(
            '--compatibility-mode',
            action='append',
            dest='compatibility_mode',
            choices=[
                compact_mode_options.NO_FIELD_TRIALS,
                compact_mode_options.IGNORE_CERTIFICATE_ERROR,
                compact_mode_options.LEGACY_COMMAND_LINE_PATH,
                compact_mode_options.GPU_BENCHMARKING_FALLBACKS
            ],
            default=[],
            help='Select the compatibility change that you want to enforce when '
            'running benchmarks')
        identity = None
        testing_rsa = os.path.join(util.GetTelemetryThirdPartyDir(),
                                   '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')
        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.')
        group.add_option(
            '--extra-chrome-categories',
            dest='extra_chrome_categories',
            type=str,
            help=
            'Filter string to enable additional chrome tracing categories. See'
            ' documentation here: https://cs.chromium.org/chromium/src/base/'
            'trace_event/trace_config.h?rcl='
            'c8db6c6371ca047c24d41f3972d5819bc83d83ae&l=125')
        group.add_option(
            '--extra-atrace-categories',
            dest='extra_atrace_categories',
            type=str,
            help='Comma-separated list of extra atrace categories. Use atrace'
            ' --list_categories to get full list.')
        group.add_option(
            '--enable-systrace',
            dest='enable_systrace',
            action='store_true',
            help='Enable collection of systrace. (Useful on ChromeOS where'
            ' atrace is not supported; collects scheduling information.)')
        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(
            '--webview-embedder-apk',
            help=
            'When running tests on android webview, more than one apk needs to'
            ' be installed. The apk running the test is said to embed webview.'
        )
        parser.add_option_group(group)

        # Remote platform options
        group = optparse.OptionGroup(parser, 'Remote platform options')
        group.add_option('--android-blacklist-file',
                         help='Device blacklist JSON file.')
        group.add_option(
            '--device',
            help='The device ID to use. '
            'If not specified, only 0 or 1 connected devices are supported. '
            'If specified as "android", all available Android devices are '
            'used.')
        parser.add_option_group(group)

        # CPU profiling on Android.
        group = optparse.OptionGroup(
            parser, ('CPU profiling over intervals of interest, '
                     'Android and Linux only'))
        group.add_option(
            '--interval-profiling-target',
            dest='interval_profiling_target',
            default='renderer:main',
            metavar='PROCESS_NAME[:THREAD_NAME]',
            help=
            'Run the CPU profiler on this process/thread (default=%default).')
        group.add_option(
            '--interval-profiling-period',
            dest='interval_profiling_periods',
            type='choice',
            choices=('navigation', 'interactions'),
            action='append',
            default=[],
            metavar='PERIOD',
            help='Run the CPU profiler during this test period. '
            'May be specified multiple times; available choices '
            'are ["navigation", "interactions"]. Profile data will be written to'
            'artifacts/*.perf.data (Android) or artifacts/*.profile.pb (Linux) '
            'files in the output directory. See '
            'https://developer.android.com/ndk/guides/simpleperf for more info on '
            'Android profiling via simpleperf.')
        group.add_option(
            '--interval-profiling-frequency',
            default=1000,
            metavar='FREQUENCY',
            type=int,
            help='Frequency of CPU profiling samples, in samples per second '
            '(default=%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:
                global_hooks.InstallSpyOnPopenArgs()
                logging.getLogger().setLevel(logging.DEBUG)
            elif self.verbosity:
                logging.getLogger().setLevel(logging.INFO)
            else:
                logging.getLogger().setLevel(logging.WARNING)

            if self.chromium_output_dir:
                os.environ['CHROMIUM_OUTPUT_DIR'] = self.chromium_output_dir

            # Parse remote platform options.
            self.BuildRemotePlatformOptions()

            if self.remote_platform_options.device == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                print 'Available devices:'
                for device in devices:
                    print ' ', device.name
                sys.exit(0)

            if self.browser_executable and not self.browser_type:
                self.browser_type = 'exact'
            if self.browser_type == 'list':
                if binary_manager.NeedsInit():
                    binary_manager.InitDependencyManager([])
                devices = device_finder.GetDevicesMatchingOptions(self)
                if not devices:
                    sys.exit(0)
                browser_types = {}
                for device in devices:
                    try:
                        possible_browsers = browser_finder.GetAllAvailableBrowsers(
                            self, device)
                        browser_types[device.name] = sorted([
                            browser.browser_type
                            for browser in possible_browsers
                        ])
                    except browser_finder_exceptions.BrowserFinderException as ex:
                        print >> sys.stderr, 'ERROR: ', ex
                        sys.exit(1)
                print 'Available browsers:'
                if len(browser_types) == 0:
                    print '  No devices were found.'
                for device_name in sorted(browser_types.keys()):
                    print '  ', device_name
                    for browser_type in browser_types[device_name]:
                        print '    ', browser_type
                    if len(browser_types[device_name]) == 0:
                        print '     No browsers found for this device'
                sys.exit(0)

            # Parse browser options.
            self.browser_options.UpdateFromParseResults(self)

            return ret

        parser.parse_args = ParseArgs
        return parser
コード例 #6
0
 def _GetPlugins(self):
     plugins = ''
     for p in _JS_PLUGINS:
         with open(os.path.join(util.GetTelemetryThirdPartyDir(), p)) as f:
             plugins += f.read()
     return plugins
コード例 #7
0
_AddDirToPythonPath(_CATAPULT_DIR, 'systrace')
_AddDirToPythonPath(_CATAPULT_DIR, 'tracing')
_AddDirToPythonPath(_CATAPULT_DIR, 'common', 'py_trace_event')
_AddDirToPythonPath(_CATAPULT_DIR, 'common', 'battor')
_AddDirToPythonPath(_CATAPULT_DIR, 'common', 'py_vulcanize')
_AddDirToPythonPath(_CATAPULT_DIR, 'tracing', 'tracing_build')

from telemetry.core import util
from telemetry.internal.util import global_hooks

# Add Catapult third party dependencies into our path.
_AddDirToPythonPath(util.GetCatapultThirdPartyDir(), 'typ')
# Required by websocket-client.
_AddDirToPythonPath(util.GetCatapultThirdPartyDir(), 'six')

# Add Telemetry third party dependencies into our path.
_TELEMETRY_3P = util.GetTelemetryThirdPartyDir()
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'altgraph')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mock')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'modulegraph')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mox3')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'png')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pyfakefs')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'web-page-replay')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'websocket-client')
_AddOptionalSingleGlobToPythonPath(_TELEMETRY_3P, 'cv2', 'lib', 'cv2_*')
_AddOptionalSingleGlobToPythonPath(_TELEMETRY_3P, 'numpy', 'lib', 'numpy_*')

# Install Telemtry global hooks.
global_hooks.InstallHooks()
コード例 #8
0
from telemetry.internal.util import atexit_with_log
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
from telemetry.internal import forwarders

_REPLAY_DIR = os.path.join(
    util.GetTelemetryThirdPartyDir(), 'web-page-replay')


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
    return 'Path does not exist for %s: %s' % (label, path)
コード例 #9
0
from telemetry.internal.util import atexit_with_log
import logging
import os
import re
import signal
import subprocess
import sys
import tempfile
import urllib

from telemetry.core import util
from telemetry.internal import forwarders

import py_utils

_REPLAY_DIR = os.path.join(util.GetTelemetryThirdPartyDir(), 'web-page-replay')


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
        return 'Path does not exist for %s: %s' % (label, path)
コード例 #10
0
_AddDirToPythonPath(_CATAPULT_DIR, 'catapult_base')
_AddDirToPythonPath(_CATAPULT_DIR, 'dependency_manager')
_AddDirToPythonPath(_CATAPULT_DIR, 'devil')
_AddDirToPythonPath(_CATAPULT_DIR, 'systrace')
_AddDirToPythonPath(_CATAPULT_DIR, 'tracing')
_AddDirToPythonPath(_CATAPULT_DIR, 'common', 'py_trace_event')
_AddDirToPythonPath(_CATAPULT_DIR, 'common', 'battor')
_AddDirToPythonPath(_CATAPULT_DIR, 'tracing', 'tracing_build')
_AddDirToPythonPath(_CATAPULT_DIR, 'third_party', 'py_vulcanize')

from telemetry.core import util
from telemetry.internal.util import global_hooks

# Add Catapult third party dependencies into our path.
_AddDirToPythonPath(util.GetCatapultThirdPartyDir(), 'typ')

# Add Telemetry third party dependencies into our path.
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'altgraph')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mock')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'modulegraph')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'mox3')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pexpect')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'png')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pyfakefs')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'pyserial')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'webpagereplay')
_AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'websocket-client')

# Install Telemtry global hooks.
global_hooks.InstallHooks()
コード例 #11
0
"""Start and stop tsproxy."""

import logging
import os
import re
import subprocess
import sys

from telemetry.core import exceptions
from telemetry.core import util
from telemetry.internal.util import atexit_with_log


_TSPROXY_PATH = os.path.join(
    util.GetTelemetryThirdPartyDir(), 'tsproxy', 'tsproxy.py')


def ParseTsProxyPortFromOutput(output_line):
  port_re = re.compile(
      r'Started Socks5 proxy server on '
      r'(?P<host>[^:]*):'
      r'(?P<port>\d+)')
  m = port_re.match(output_line.strip())
  if m:
    return int(m.group('port'))


class TsProxyServer(object):
  """Start and Stop Tsproxy.
コード例 #12
0
# Copyright 2012 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 sys

from telemetry.core import util
from telemetry import decorators
from telemetry.internal.browser import browser_finder
from telemetry.internal.browser import browser_finder_exceptions
from telemetry.internal.browser import browser_options
from telemetry.internal.platform import device_finder
from telemetry.internal.util import command_line
from telemetry.testing import browser_test_case
from telemetry.testing import options_for_unittests

util.AddDirToPythonPath(util.GetTelemetryThirdPartyDir(), 'typ')

import typ


class RunTestsCommand(command_line.OptparseCommand):
    """Run unit tests"""

    usage = '[test_name ...] [<options>]'

    def __init__(self):
        super(RunTestsCommand, self).__init__()
        self.stream = sys.stdout

    @classmethod
    def CreateParser(cls):
コード例 #13
0
def SnapPage(finder_options, url, interactive, snapshot_file):
    """ Save the HTML snapshot of the page whose address is |url| to
  |snapshot_file|.
  """
    possible_browser = browser_finder.FindBrowser(finder_options)
    browser = possible_browser.Create(finder_options)
    try:
        tab = browser.tabs[0]
        tab.Navigate(url)
        if interactive:
            raw_input(
                'Activating interactive mode. Press enter after you finish '
                "interacting with the page to snapshot the page's DOM content."
            )

        sys.stdout.write(
            'Snapshotting content of %s. This could take a while...\n' % url)
        tab.WaitForDocumentReadyStateToBeComplete()
        tab.action_runner.WaitForNetworkQuiescence()

        with open(
                os.path.join(util.GetTelemetryThirdPartyDir(), 'snap-it',
                             'HTMLSerializer.js')) as f:
            snapit_script = f.read()

        with open(
                os.path.join(util.GetTelemetryThirdPartyDir(), 'snap-it',
                             'popup.js')) as f:
            dom_combining_script = f.read()

        serialized_doms = []

        # Serialize the dom in each frame.
        for context_id in tab.EnableAllContexts():
            tab.ExecuteJavaScript(snapit_script, context_id=context_id)
            tab.ExecuteJavaScript('''
          var serializedDom;
          var htmlSerializer = new HTMLSerializer();
          htmlSerializer.processDocument(document);
          htmlSerializer.fillHolesAsync(document, function(s) {
            serializedDom = s.asDict();
          });
          ''',
                                  context_id=context_id)
            tab.WaitForJavaScriptCondition('serializedDom !== undefined',
                                           context_id=context_id)
            serialized_doms.append(
                tab.EvaluateJavaScript('serializedDom', context_id=context_id))

        # Execute doms combining code in blank page to minimize the chance of V8
        # OOM.
        tab.Navigate('about:blank')
        tab.WaitForDocumentReadyStateToBeComplete()

        # Sending all the serialized doms back to tab execution context.
        tab.ExecuteJavaScript('var serializedDoms = [];')
        for i in xrange(len(serialized_doms)):
            sys.stdout.write('Processing dom of frame #%i / %i\r' %
                             (i, len(serialized_doms)))
            sys.stdout.flush()
            _TransmitLargeJSONToTab(tab, serialized_doms[i], 'sub_dom')
            tab.ExecuteJavaScript('serializedDoms.push(sub_dom);')

        # Combine all the doms to one HTML string.
        tab.EvaluateJavaScript(dom_combining_script)
        page_snapshot = tab.EvaluateJavaScript(
            'outputHTMLString(serializedDoms);')

        snapshot_file.write(page_snapshot)
    finally:
        browser.Close()