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

Side by Side Diff: tools/resource_prefetch_predictor/generate_database.py

Issue 2561353002: tools: WPR support for testing speculative_prefetch_predictor. (Closed)
Patch Set: . Created 4 years 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
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 set of web pages several times on a device, and extracts the
8 predictor database.
9 """
10
11 import argparse
12 import logging
13 import os
14 import sys
15 import time
16
17 _SRC_PATH = os.path.abspath(os.path.join(
18 os.path.dirname(__file__), os.pardir, os.pardir))
19 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil'))
20
21 from devil.android import device_utils
22
23 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android'))
24 import devil_chromium
25
26 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading'))
27 from options import OPTIONS
28 import page_track
29
30 import prefetch_predictor_common
31
32
33 _PAGE_LOAD_TIMEOUT = 20
34
35
36 def _CreateArgumentParser():
37 """Creates and returns the argument parser."""
38 parser = argparse.ArgumentParser(
39 ('Loads a set of web pages several times on a device, and extracts the '
40 'predictor database.'), parents=[OPTIONS.GetParentParser()])
41 parser.add_argument('--device', help='Device ID')
42 parser.add_argument('--urls_filename', help='File containing a list of URLs '
43 '(one per line). URLs can be repeated.')
44 parser.add_argument('--output_filename',
45 help='File to store the database in.')
46 parser.add_argument('--url_repeat',
47 help=('Number of times each URL in the input '
48 'file is loaded.'),
49 default=3)
50 return parser
51
52
53 def _Go(chrome_controller, urls_filename, output_filename, repeats):
54 urls = []
55 with open(urls_filename) as f:
56 urls = [line.strip() for line in f.readlines()]
57
58 with chrome_controller.Open() as connection:
59 for repeat in range(repeats):
60 logging.info('Repeat #%d', repeat)
61 for url in urls:
62 logging.info('\tLoading %s', url)
63 page_track.PageTrack(connection) # Registers the listeners.
64 connection.MonitorUrl(url, timeout_seconds=_PAGE_LOAD_TIMEOUT,
65 stop_delay_multiplier=1.5)
66 time.sleep(2) # Reduces flakiness.
67
68 device = chrome_controller.GetDevice()
69 device.ForceStop(OPTIONS.ChromePackage().package)
70 device.PullFile(prefetch_predictor_common.DatabaseDevicePath(),
71 output_filename)
72
73
74 def main():
75 devil_chromium.Initialize()
76 logging.basicConfig(level=logging.INFO)
77
78 parser = _CreateArgumentParser()
79 args = parser.parse_args()
80 OPTIONS.SetParsedArgs(args)
81
82 device = prefetch_predictor_common.FindDevice(args.device)
83 if device is None:
84 logging.error('Could not find device: %s.', args.device)
85 sys.exit(1)
86
87 chrome_controller = prefetch_predictor_common.Setup(
88 device, ['--speculative-resource-prefetching=learning'])
89 _Go(chrome_controller, args.urls_filename, args.output_filename,
90 int(args.url_repeat))
91
92
93 if __name__ == '__main__':
94 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698