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

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: 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
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):
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
40 Returns:
41 loading_trace.LoadingTrace.
42 """
43 page = page_track.PageTrack(connection)
44 request = request_track.RequestTrack(connection)
45 tracing_track = tracing.TracingTrack(connection)
blundell 2016/01/21 14:11:38 nit: either call this |trace| (which you can do no
mattcary 2016/01/21 16:11:35 Done.
46 connection.SetUpMonitoring()
47 connection.SendAndIgnoreResponse('Network.clearBrowserCache', {})
Benoit L 2016/01/21 14:14:38 Use the ClearCache() function introduced in devtoo
mattcary 2016/01/21 16:11:35 Done.
48 connection.SendAndIgnoreResponse('Page.navigate', {'url': url})
49 connection.StartMonitoring()
50 metadata = {'date': datetime.datetime.utcnow().isoformat(),
51 'seconds_since_epoch': time.time()}
52 return loading_trace.LoadingTrace(url, metadata, page, request,
53 tracing_track)
54
33 def RecordAndDumpTrace(device, url, output_filename): 55 def RecordAndDumpTrace(device, url, output_filename):
34 with file(output_filename, 'w') as output,\ 56 with file(output_filename, 'w') as output,\
35 device_setup.DeviceConnection(device) as connection: 57 device_setup.DeviceConnection(device) as connection:
36 page = page_track.PageTrack(connection) 58 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) 59 json.dump(trace.ToJsonDict(), output)
48 60
49 61
50 def main(): 62 def main():
51 logging.basicConfig(level=logging.INFO) 63 logging.basicConfig(level=logging.INFO)
52 devil_chromium.Initialize() 64 devil_chromium.Initialize()
53 65
54 parser = argparse.ArgumentParser() 66 parser = argparse.ArgumentParser()
55 parser.add_argument('--url', required=True) 67 parser.add_argument('--url', required=True)
56 parser.add_argument('--output', required=True) 68 parser.add_argument('--output', required=True)
57 args = parser.parse_args() 69 args = parser.parse_args()
58 url = args.url 70 url = args.url
59 if not url.startswith('http'): 71 if not url.startswith('http'):
60 url = 'http://' + url 72 url = 'http://' + url
61 device = device_utils.DeviceUtils.HealthyDevices()[0] 73 device = device_utils.DeviceUtils.HealthyDevices()[0]
62 RecordAndDumpTrace(device, url, args.output) 74 RecordAndDumpTrace(device, url, args.output)
63 75
64 76
65 if __name__ == '__main__': 77 if __name__ == '__main__':
66 main() 78 main()
OLDNEW
« tools/android/loading/processing.py ('K') | « tools/android/loading/request_dependencies_lens.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698