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

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

Issue 1619713002: Upgrade analyze.py and related scripts to new world order. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments Created 4 years, 11 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/request_track.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/python 1 #! /usr/bin/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 """Loading trace recorder.""" 6 """Loading trace recorder."""
7 7
8 import argparse 8 import argparse
9 import datetime 9 import datetime
10 import json 10 import json
(...skipping 12 matching lines...) Expand all
23 import devil_chromium 23 import devil_chromium
24 24
25 import device_setup 25 import device_setup
26 import devtools_monitor 26 import devtools_monitor
27 import loading_trace 27 import loading_trace
28 import page_track 28 import page_track
29 import request_track 29 import request_track
30 import tracing 30 import tracing
31 31
32 32
33 def MonitorUrl(connection, url, clear_cache=False):
34 """Monitor a URL via a trace recorder.
35
36 Args:
37 connection: A device_monitor.DevToolsConnection instance.
38 url: url to navigate to as string.
39 clear_cache: boolean indicating if cache should be cleared before loading.
40
41 Returns:
42 loading_trace.LoadingTrace.
43 """
44 logging.warning('Logging %scached %s' % ('un' if clear_cache else '', url))
45 page = page_track.PageTrack(connection)
46 request = request_track.RequestTrack(connection)
47 trace = tracing.TracingTrack(connection)
48 connection.SetUpMonitoring()
49 if clear_cache:
50 connection.ClearCache()
51 connection.SendAndIgnoreResponse('Page.navigate', {'url': url})
52 connection.StartMonitoring()
53 metadata = {'date': datetime.datetime.utcnow().isoformat(),
54 'seconds_since_epoch': time.time()}
55 return loading_trace.LoadingTrace(url, metadata, page, request, trace)
56
33 def RecordAndDumpTrace(device, url, output_filename): 57 def RecordAndDumpTrace(device, url, output_filename):
34 with file(output_filename, 'w') as output,\ 58 with file(output_filename, 'w') as output,\
35 device_setup.DeviceConnection(device) as connection: 59 device_setup.DeviceConnection(device) as connection:
36 page = page_track.PageTrack(connection) 60 trace = MonitorUrl(connection, url)
37 request = request_track.RequestTrack(connection)
38 tracing_track = tracing.TracingTrack(connection)
39 connection.SetUpMonitoring()
40 connection.SendAndIgnoreResponse('Network.clearBrowserCache', {})
41 connection.SendAndIgnoreResponse('Page.navigate', {'url': url})
42 connection.StartMonitoring()
43 metadata = {'date': datetime.datetime.utcnow().isoformat(),
44 'seconds_since_epoch': time.time()}
45 trace = loading_trace.LoadingTrace(url, metadata, page, request,
46 tracing_track)
47 json.dump(trace.ToJsonDict(), output) 61 json.dump(trace.ToJsonDict(), output)
48 62
49 63
50 def main(): 64 def main():
51 logging.basicConfig(level=logging.INFO) 65 logging.basicConfig(level=logging.INFO)
52 devil_chromium.Initialize() 66 devil_chromium.Initialize()
53 67
54 parser = argparse.ArgumentParser() 68 parser = argparse.ArgumentParser()
55 parser.add_argument('--url', required=True) 69 parser.add_argument('--url', required=True)
56 parser.add_argument('--output', required=True) 70 parser.add_argument('--output', required=True)
57 args = parser.parse_args() 71 args = parser.parse_args()
58 url = args.url 72 url = args.url
59 if not url.startswith('http'): 73 if not url.startswith('http'):
60 url = 'http://' + url 74 url = 'http://' + url
61 device = device_utils.DeviceUtils.HealthyDevices()[0] 75 device = device_utils.DeviceUtils.HealthyDevices()[0]
62 RecordAndDumpTrace(device, url, args.output) 76 RecordAndDumpTrace(device, url, args.output)
63 77
64 78
65 if __name__ == '__main__': 79 if __name__ == '__main__':
66 main() 80 main()
OLDNEW
« no previous file with comments | « tools/android/loading/request_track.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698