Chromium Code Reviews| 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..9186d8e55affdde7e1ea01331a8f3d1ae31edb52 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,42 @@ 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) |
|
mattcary
2016/01/19 15:24:47
two blank lines?
Benoit L
2016/01/19 15:54:50
Done.
|
| if __name__ == '__main__': |
| - DoIt(sys.argv[1]) |
| + main() |