| Index: tools/android/loading/trace_recorder.py
|
| diff --git a/tools/android/loading/trace_recorder.py b/tools/android/loading/trace_recorder.py
|
| index 0b962253ab595029834bb2dee0e52d074b258175..fdf6cc6c93ac39bcb3dbfc9e651da7c5d97c1835 100755
|
| --- a/tools/android/loading/trace_recorder.py
|
| +++ b/tools/android/loading/trace_recorder.py
|
| @@ -5,8 +5,13 @@
|
|
|
| """Loading trace recorder."""
|
|
|
| +import argparse
|
| +import datetime
|
| +import json
|
| +import logging
|
| import os
|
| import sys
|
| +import time
|
|
|
| _SRC_DIR = os.path.abspath(os.path.join(
|
| os.path.dirname(__file__), '..', '..', '..'))
|
| @@ -19,32 +24,43 @@ import devil_chromium
|
|
|
| import device_setup
|
| import devtools_monitor
|
| +import loading_trace
|
| import page_track
|
| +import request_track
|
| +import tracing
|
|
|
| -class AndroidTraceRecorder(object):
|
| - """Records a loading trace."""
|
| - def __init__(self, url):
|
| - self.url = url
|
| - self.devtools_connection = None
|
| - self.page_track = None
|
|
|
| - def Go(self, connection):
|
| - self.devtools_connection = connection
|
| - self.page_track = page_track.PageTrack(self.devtools_connection)
|
| - self.devtools_connection.SetUpMonitoring()
|
| - self.devtools_connection.SendAndIgnoreResponse(
|
| - 'Page.navigate', {'url': self.url})
|
| - self.devtools_connection.StartMonitoring()
|
| - print self.page_track.GetEvents()
|
| +def RecordAndDumpTrace(device, url, output_filename):
|
| + with file(output_filename, 'w') as output,\
|
| + device_setup.DeviceConnection(device) as connection:
|
| + page = page_track.PageTrack(connection)
|
| + request = request_track.RequestTrack(connection)
|
| + tracing_track = tracing.TracingTrack(connection)
|
| + connection.SetUpMonitoring()
|
| + connection.SendAndIgnoreResponse('Network.clearBrowserCache', {})
|
| + connection.SendAndIgnoreResponse('Page.navigate', {'url': url})
|
| + connection.StartMonitoring()
|
| + metadata = {'date': datetime.datetime.utcnow().isoformat(),
|
| + 'seconds_since_epoch': time.time()}
|
| + trace = loading_trace.LoadingTrace(url, metadata, page, request,
|
| + tracing_track)
|
| + json.dump(trace.ToJsonDict(), output)
|
|
|
|
|
| -def DoIt(url):
|
| +def main():
|
| + logging.basicConfig(level=logging.INFO)
|
| devil_chromium.Initialize()
|
| - devices = device_utils.DeviceUtils.HealthyDevices()
|
| - device = devices[0]
|
| - trace_recorder = AndroidTraceRecorder(url)
|
| - device_setup.SetUpAndExecute(device, 'chrome', trace_recorder.Go)
|
| +
|
| + parser = argparse.ArgumentParser()
|
| + parser.add_argument('--url', required=True)
|
| + parser.add_argument('--output', required=True)
|
| + args = parser.parse_args()
|
| + url = args.url
|
| + if not url.startswith('http'):
|
| + url = 'http://' + url
|
| + device = device_utils.DeviceUtils.HealthyDevices()[0]
|
| + RecordAndDumpTrace(device, url, args.output)
|
|
|
|
|
| if __name__ == '__main__':
|
| - DoIt(sys.argv[1])
|
| + main()
|
|
|