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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 #!/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.
2 #
3 # Copyright 2016 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """Loads a web page with speculative prefetch, and collects loading metrics."""
8
9 import argparse
10 import logging
11 import os
12 import sys
13 import time
14
15 _SRC_PATH = os.path.abspath(os.path.join(
16 os.path.dirname(__file__), os.pardir, os.pardir))
17
18 sys.path.append(os.path.join(
19 _SRC_PATH, 'tools', 'android', 'customtabs_benchmark', 'scripts'))
20 import customtabs_benchmark
21
22 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading'))
23 from options import OPTIONS
24
25 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android'))
26 import devil_chromium
27
28 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil'))
29 from devil.android.sdk import intent
30
31 import common
32
33
34 def _CreateArgumentParser():
35 """Creates and returns the argument parser."""
36 parser = common.CreateBaseArgumentParser(
37 '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.
38 parser.add_argument('--device', help='Device ID')
39 parser.add_argument('--database',
40 help=('File containing the predictor database, as '
41 'obtained from generate_database.py.'))
42 parser.add_argument('--url', help='URL to load.')
43 parser.add_argument('--prefetch_delay_ms',
44 help='Prefetch delay in ms. -1 to disable prefetch.')
45 return parser
46
47
48 def _Setup(device, database_filename):
49 """Sets up a device and returns an instance of RemoteChromeController."""
50 chrome_controller = common.Setup(device, [''])
51 chrome_package = OPTIONS.ChromePackage()
52 device.ForceStop(chrome_package.package)
53 chrome_controller.ResetBrowserState()
54 # 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.
55 launch_intent = intent.Intent(
56 action='android.intent.action.MAIN',
57 package=chrome_package.package,
58 activity=chrome_package.activity)
59 device.StartActivity(launch_intent, blocking=True)
60 time.sleep(5)
61 device.ForceStop(chrome_package.package)
62 # Now push the database. Needs to be done after the first launch, otherwise
63 # 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.
64 database_content = open(database_filename, 'r').read()
65 device.WriteFile(common.DatabaseDevicePath(), database_content,
66 force_push=True)
67
68
69 def _Go(device, url, prefetch_delay_ms):
70 disable_prefetch = prefetch_delay_ms == -1
71 chrome_args = (customtabs_benchmark.CHROME_ARGS
72 + ['--trace-startup', '--trace-startup-duration=20'])
73 if not disable_prefetch:
74 chrome_args.append('--speculative-resource-prefetching=enabled')
75 prefetch_mode = 'disabled' if disable_prefetch else 'speculative_prefetch'
76 result = customtabs_benchmark.RunOnce(
77 device, url, True, prefetch_mode, 2000, max(0, prefetch_delay_ms), False,
78 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.
79 print customtabs_benchmark.ParseResult(result)
80
81
82 def main():
83 devil_chromium.Initialize()
84 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.
85
86 parser = _CreateArgumentParser()
87 args = common.ParseAndReturnArgs(parser)
88 device = common.FindDevice(args.device)
89 if device is None:
90 logging.error('Could not find device: %s.', args.device)
91 sys.exit(1)
92
93 _Setup(device, args.database)
94 _Go(device, args.url, int(args.prefetch_delay_ms))
95
96
97 if __name__ == '__main__':
98 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698