Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Unified Diff: tools/resource_prefetch_predictor/prefetch_benchmark.py

Issue 2508933002: tools: Local tests for the speculative prefetch predictor. (Closed)
Patch Set: . Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/resource_prefetch_predictor/prefetch_benchmark.py
diff --git a/tools/resource_prefetch_predictor/prefetch_benchmark.py b/tools/resource_prefetch_predictor/prefetch_benchmark.py
new file mode 100755
index 0000000000000000000000000000000000000000..88917e9092dc6b43e811320abddfe1b57fa474fe
--- /dev/null
+++ b/tools/resource_prefetch_predictor/prefetch_benchmark.py
@@ -0,0 +1,98 @@
+#!/usr/bin/python
pasko 2016/11/17 15:59:04 every time I get a review in tools/resource_prefet
Benoit L 2016/11/21 13:40:32 Acknowledged.
+#
+# Copyright 2016 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.
+
+"""Loads a web page with speculative prefetch, and collects loading metrics."""
+
+import argparse
+import logging
+import os
+import sys
+import time
+
+_SRC_PATH = os.path.abspath(os.path.join(
+ os.path.dirname(__file__), os.pardir, os.pardir))
+
+sys.path.append(os.path.join(
+ _SRC_PATH, 'tools', 'android', 'customtabs_benchmark', 'scripts'))
+import customtabs_benchmark
+
+sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading'))
+from options import OPTIONS
+
+sys.path.append(os.path.join(_SRC_PATH, 'build', 'android'))
+import devil_chromium
+
+sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil'))
+from devil.android.sdk import intent
+
+import common
+
+
+def _CreateArgumentParser():
+ """Creates and returns the argument parser."""
+ parser = common.CreateBaseArgumentParser(
+ 'Loads a URL with prefetch and prints loading metrics.')
pasko 2016/11/17 15:59:04 s/prefetch/resource_prefetch_predictor/ would be b
Benoit L 2016/11/21 13:40:32 Done.
+ parser.add_argument('--device', help='Device ID')
+ parser.add_argument('--database',
+ help=('File containing the predictor database, as '
+ 'obtained from generate_database.py.'))
+ parser.add_argument('--url', help='URL to load.')
+ parser.add_argument('--prefetch_delay_ms',
+ help='Prefetch delay in ms. -1 to disable prefetch.')
+ return parser
+
+
+def _Setup(device, database_filename):
+ """Sets up a device and returns an instance of RemoteChromeController."""
+ chrome_controller = common.Setup(device, [''])
+ chrome_package = OPTIONS.ChromePackage()
+ device.ForceStop(chrome_package.package)
+ chrome_controller.ResetBrowserState()
+ # Launch Chrome a first time to recreate the local state.
pasko 2016/11/17 15:59:04 nit: s/a/for the/
Benoit L 2016/11/21 13:40:32 Done.
+ launch_intent = intent.Intent(
+ action='android.intent.action.MAIN',
+ package=chrome_package.package,
+ activity=chrome_package.activity)
+ device.StartActivity(launch_intent, blocking=True)
+ time.sleep(5)
+ device.ForceStop(chrome_package.package)
+ # Now push the database. Needs to be done after the first launch, otherwise
+ # the profile directory is owned by root.
pasko 2016/11/17 15:59:04 What ensures that Chrome creates the database? I a
Benoit L 2016/11/21 13:40:32 Good catch, thanks! Done.
+ database_content = open(database_filename, 'r').read()
+ device.WriteFile(common.DatabaseDevicePath(), database_content,
+ force_push=True)
+
+
+def _Go(device, url, prefetch_delay_ms):
+ disable_prefetch = prefetch_delay_ms == -1
+ chrome_args = (customtabs_benchmark.CHROME_ARGS
+ + ['--trace-startup', '--trace-startup-duration=20'])
+ if not disable_prefetch:
+ chrome_args.append('--speculative-resource-prefetching=enabled')
+ prefetch_mode = 'disabled' if disable_prefetch else 'speculative_prefetch'
+ result = customtabs_benchmark.RunOnce(
+ device, url, True, prefetch_mode, 2000, max(0, prefetch_delay_ms), False,
+ chrome_args, False)
pasko 2016/11/17 15:59:04 this function has quite a few parameters, maintain
Benoit L 2016/11/21 13:40:32 Done.
+ print customtabs_benchmark.ParseResult(result)
+
+
+def main():
+ devil_chromium.Initialize()
+ logging.basicConfig(level=logging.INFO)
pasko 2016/11/17 15:59:04 setting up logging before initialization of an ext
Benoit L 2016/11/21 13:40:32 Done.
+
+ parser = _CreateArgumentParser()
+ args = common.ParseAndReturnArgs(parser)
+ device = common.FindDevice(args.device)
+ if device is None:
+ logging.error('Could not find device: %s.', args.device)
+ sys.exit(1)
+
+ _Setup(device, args.database)
+ _Go(device, args.url, int(args.prefetch_delay_ms))
+
+
+if __name__ == '__main__':
+ main()

Powered by Google App Engine
This is Rietveld 408576698