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

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

Issue 2508933002: tools: Local tests for the speculative prefetch predictor. (Closed)
Patch Set: Rebase. 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 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 import device_setup
22
23 sys.path.append(os.path.join(_SRC_PATH, 'tools', 'android', 'loading'))
24 from options import OPTIONS
25
26 sys.path.append(os.path.join(_SRC_PATH, 'build', 'android'))
27 import devil_chromium
28
29 sys.path.append(os.path.join(_SRC_PATH, 'third_party', 'catapult', 'devil'))
30 from devil.android.sdk import intent
31
32 import prefetch_predictor_common
33
34
35 _EXTERNAL_PREFETCH_FLAG = (
36 '--speculative-resource-prefetching=enabled-external-only')
37
38
39 def _CreateArgumentParser():
40 """Creates and returns the argument parser."""
41 parser = argparse.ArgumentParser(
42 ('Loads a URL with the resource_prefetch_predictor and prints loading '
43 'metrics.'), parents=[OPTIONS.GetParentParser()])
44 parser.add_argument('--device', help='Device ID')
45 parser.add_argument('--database',
46 help=('File containing the predictor database, as '
47 'obtained from generate_database.py.'))
48 parser.add_argument('--url', help='URL to load.')
49 parser.add_argument('--prefetch_delay_ms',
50 help='Prefetch delay in ms. -1 to disable prefetch.')
51 return parser
52
53
54 def _Setup(device, database_filename):
55 """Sets up a device and returns an instance of RemoteChromeController."""
56 chrome_controller = prefetch_predictor_common.Setup(device, [''])
57 chrome_package = OPTIONS.ChromePackage()
58 device.ForceStop(chrome_package.package)
59 chrome_controller.ResetBrowserState()
60 device_database_filename = prefetch_predictor_common.DatabaseDevicePath()
61 owner = group = None
62
63 # Make sure that the speculative prefetch predictor is enabled to ensure
64 # that the disk database is re-created.
65 command_line_path = '/data/local/tmp/chrome-command-line'
66 with device_setup.FlagReplacer(
67 device, command_line_path, ['--disable-fre', _EXTERNAL_PREFETCH_FLAG]):
68 # Launch Chrome for the first time to recreate the local state.
69 launch_intent = intent.Intent(
70 action='android.intent.action.MAIN',
71 package=chrome_package.package,
72 activity=chrome_package.activity)
73 device.StartActivity(launch_intent, blocking=True)
74 time.sleep(5)
75 device.ForceStop(chrome_package.package)
76 assert device.FileExists(device_database_filename)
77 stats = device.StatPath(device_database_filename)
78 owner = stats['st_owner']
79 group = stats['st_group']
80 # Now push the database. Needs to be done after the first launch, otherwise
81 # the profile directory is owned by root. Also change the owner of the
82 # database, since adb push sets it to root.
83 database_content = open(database_filename, 'r').read()
84 device.WriteFile(device_database_filename, database_content, force_push=True)
85 command = 'chown %s:%s \'%s\'' % (owner, group, device_database_filename)
86 device.RunShellCommand(command, as_root=True)
87
88
89 def _Go(device, url, prefetch_delay_ms):
90 disable_prefetch = prefetch_delay_ms == -1
91 chrome_args = (customtabs_benchmark.CHROME_ARGS
92 + ['--trace-startup', '--trace-startup-duration=20'])
pasko 2016/11/30 12:53:46 what do we use from --trace-startup?
Benoit L 2016/11/30 15:25:50 Debugging. The trace is there, easy to look at it.
pasko 2016/11/30 15:32:30 no, not at all. I was wondering whether something
93 if not disable_prefetch:
94 chrome_args.append(_EXTERNAL_PREFETCH_FLAG)
95 prefetch_mode = 'disabled' if disable_prefetch else 'speculative_prefetch'
96 result = customtabs_benchmark.RunOnce(
97 device, url, warmup=True, speculation_mode=prefetch_mode,
98 delay_to_may_launch_url=2000,
99 delay_to_launch_url=max(0, prefetch_delay_ms), cold=False,
100 chrome_args=chrome_args, reset_chrome_state=False)
101 print customtabs_benchmark.ParseResult(result)
102
103
104 def main():
105 logging.basicConfig(level=logging.INFO)
106 devil_chromium.Initialize()
107
108 parser = _CreateArgumentParser()
109 args = parser.parse_args()
110 OPTIONS.SetParsedArgs(args)
111 device = prefetch_predictor_common.FindDevice(args.device)
112 if device is None:
113 logging.error('Could not find device: %s.', args.device)
114 sys.exit(1)
115
116 _Setup(device, args.database)
117 _Go(device, args.url, int(args.prefetch_delay_ms))
118
119
120 if __name__ == '__main__':
121 main()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698