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

Side by Side Diff: tools/android/loading/run_sandwich.py

Issue 1690813003: sandwich: Builds a script to pull the metrics from the traces (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@d01
Patch Set: Addresses all review concerns Created 4 years, 10 months 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
« no previous file with comments | « tools/android/loading/pull_sandwich_metrics_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #! /usr/bin/env python 1 #! /usr/bin/env python
2 # Copyright 2016 The Chromium Authors. All rights reserved. 2 # Copyright 2016 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Instructs Chrome to load series of web pages and reports results. 6 """Instructs Chrome to load series of web pages and reports results.
7 7
8 When running Chrome is sandwiched between preprocessed disk caches and 8 When running Chrome is sandwiched between preprocessed disk caches and
9 WepPageReplay serving all connections. 9 WepPageReplay serving all connections.
10 10
(...skipping 13 matching lines...) Expand all
24 from devil.android import device_utils 24 from devil.android import device_utils
25 25
26 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) 26 sys.path.append(os.path.join(_SRC_DIR, 'build', 'android'))
27 from pylib import constants 27 from pylib import constants
28 import devil_chromium 28 import devil_chromium
29 29
30 import device_setup 30 import device_setup
31 import devtools_monitor 31 import devtools_monitor
32 import json 32 import json
33 import page_track 33 import page_track
34 import pull_sandwich_metrics
34 import tracing 35 import tracing
35 36
36 37
37 _JOB_SEARCH_PATH = 'sandwich_jobs' 38 _JOB_SEARCH_PATH = 'sandwich_jobs'
38 39
39 # Directory name under --output to save the cache from the device. 40 # Directory name under --output to save the cache from the device.
40 _CACHE_DIRECTORY_NAME = 'cache' 41 _CACHE_DIRECTORY_NAME = 'cache'
41 42
42 # Name of cache subdirectory on the device where the cache index is stored. 43 # Name of cache subdirectory on the device where the cache index is stored.
43 _INDEX_DIRECTORY_NAME = 'index-dir' 44 _INDEX_DIRECTORY_NAME = 'index-dir'
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 Args: 83 Args:
83 events: a dict as returned by TracingTrack.ToJsonDict() 84 events: a dict as returned by TracingTrack.ToJsonDict()
84 directory: directory name contining all traces 85 directory: directory name contining all traces
85 subdirectory: directory name to create this particular trace in 86 subdirectory: directory name to create this particular trace in
86 """ 87 """
87 target_directory = os.path.join(directory, subdirectory) 88 target_directory = os.path.join(directory, subdirectory)
88 filename = os.path.join(target_directory, 'trace.json') 89 filename = os.path.join(target_directory, 'trace.json')
89 try: 90 try:
90 os.makedirs(target_directory) 91 os.makedirs(target_directory)
91 with open(filename, 'w') as f: 92 with open(filename, 'w') as f:
92 json.dump({'traceEvents': events['events'], 'metadata': {}}, f) 93 json.dump({'traceEvents': events['events'], 'metadata': {}}, f, indent=2)
93 except IOError: 94 except IOError:
94 logging.warning('Could not save a trace: %s' % filename) 95 logging.warning('Could not save a trace: %s' % filename)
95 # Swallow the exception. 96 # Swallow the exception.
96 97
97 98
98 def _UpdateTimestampFromAdbStat(filename, stat): 99 def _UpdateTimestampFromAdbStat(filename, stat):
99 os.utime(filename, (stat.st_time, stat.st_time)) 100 os.utime(filename, (stat.st_time, stat.st_time))
100 101
101 102
102 def _SaveBrowserCache(device, output_directory): 103 def _SaveBrowserCache(device, output_directory):
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 pages_loaded = 0 182 pages_loaded = 0
182 for iteration in xrange(args.repeat): 183 for iteration in xrange(args.repeat):
183 for url in job_urls: 184 for url in job_urls:
184 with device_setup.DeviceConnection( 185 with device_setup.DeviceConnection(
185 device=device, 186 device=device,
186 additional_flags=additional_flags) as connection: 187 additional_flags=additional_flags) as connection:
187 if iteration == 0 and pages_loaded == 0 and args.save_cache: 188 if iteration == 0 and pages_loaded == 0 and args.save_cache:
188 connection.ClearCache() 189 connection.ClearCache()
189 page_track.PageTrack(connection) 190 page_track.PageTrack(connection)
190 tracing_track = tracing.TracingTrack(connection, 191 tracing_track = tracing.TracingTrack(connection,
191 categories='blink,cc,netlog,renderer.scheduler,toplevel,v8') 192 categories=pull_sandwich_metrics.CATEGORIES)
192 connection.SetUpMonitoring() 193 connection.SetUpMonitoring()
193 connection.SendAndIgnoreResponse('Page.navigate', {'url': url}) 194 connection.SendAndIgnoreResponse('Page.navigate', {'url': url})
194 connection.StartMonitoring() 195 connection.StartMonitoring()
195 pages_loaded += 1 196 pages_loaded += 1
196 _SaveChromeTrace(tracing_track.ToJsonDict(), args.output, 197 _SaveChromeTrace(tracing_track.ToJsonDict(), args.output,
197 str(pages_loaded)) 198 str(pages_loaded))
198 199
199 if args.save_cache: 200 if args.save_cache:
200 # Move Chrome to background to allow it to flush the index. 201 # Move Chrome to background to allow it to flush the index.
201 device.adb.Shell('am start com.google.android.launcher') 202 device.adb.Shell('am start com.google.android.launcher')
202 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) 203 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS)
203 device.KillAll(_CHROME_PACKAGE, quiet=True) 204 device.KillAll(_CHROME_PACKAGE, quiet=True)
204 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS) 205 time.sleep(_TIME_TO_DEVICE_IDLE_SECONDS)
205 _SaveBrowserCache(device, args.output) 206 _SaveBrowserCache(device, args.output)
206 207
207 208
208 if __name__ == '__main__': 209 if __name__ == '__main__':
209 sys.exit(main()) 210 sys.exit(main())
OLDNEW
« no previous file with comments | « tools/android/loading/pull_sandwich_metrics_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698