Chromium Code Reviews| Index: tools/android/loading/analyze.py |
| diff --git a/tools/android/loading/analyze.py b/tools/android/loading/analyze.py |
| index 3bb58900dffb90800bda834e743f388687e36764..8374faa56558f68cdae81816fde521c54212b143 100755 |
| --- a/tools/android/loading/analyze.py |
| +++ b/tools/android/loading/analyze.py |
| @@ -24,31 +24,21 @@ sys.path.append(os.path.join(_SRC_DIR, 'build', 'android')) |
| import devil_chromium |
| from pylib import constants |
| -import log_parser |
| -import log_requests |
| +import device_setup |
| import loading_model |
| +import loading_trace |
| +import trace_recorder |
| -# TODO(mattcary): logging.info isn't that useful; we need something finer |
| -# grained. For now we just do logging.warning. |
| +# TODO(mattcary): logging.info isn't that useful, as the whole (tools) world |
| +# uses logging info; we need to introduce logging modules to get finer-grained |
| +# output. For now we just do logging.warning. |
| # TODO(mattcary): probably we want this piped in through a flag. |
| CHROME = constants.PACKAGE_INFO['chrome'] |
| -def _SetupAndGetDevice(): |
| - """Gets an android device, set up the way we like it. |
| - |
| - Returns: |
| - An instance of DeviceUtils for the first device found. |
| - """ |
| - device = device_utils.DeviceUtils.HealthyDevices()[0] |
| - device.EnableRoot() |
| - device.KillAll(CHROME.package, quiet=True) |
| - return device |
| - |
| - |
| def _LoadPage(device, url): |
| """Load a page on chrome on our device. |
| @@ -99,31 +89,27 @@ def _GetPrefetchHtml(graph, name=None): |
| <body>%s</body> |
| </html> |
| """ % title) |
| - |
| return '\n'.join(output) |
| def _LogRequests(url, clear_cache=True, local=False): |
|
Benoit L
2016/01/21 14:14:38
Can this move into trace_recorder?
mattcary
2016/01/21 16:11:35
I think I already essentially did that by breaking
Benoit L
2016/01/21 16:20:03
Acknowledged.
|
| """Log requests for a web page. |
| - TODO(mattcary): loading.log_requests probably needs to be refactored as we're |
| - using private methods, also there's ugliness like _ResponseDataToJson return a |
| - json.dumps that we immediately json.loads. |
| - |
| Args: |
| url: url to log as string. |
| clear_cache: optional flag to clear the cache. |
| local: log from local (desktop) chrome session. |
| Returns: |
| - JSON of logged information (ie, a dict that describes JSON). |
| + JSON dict of logged information (ie, a dict that describes JSON). |
| """ |
| - device = _SetupAndGetDevice() if not local else None |
| - request_logger = log_requests.AndroidRequestsLogger(device) |
| - logging.warning('Logging %scached %s' % ('un' if clear_cache else '', url)) |
| - response_data = request_logger.LogPageLoad( |
| - url, clear_cache, 'chrome') |
| - return json.loads(log_requests._ResponseDataToJson(response_data)) |
| + device = device_setup.GetFirstDevice() if not local else None |
| + with device_setup.DeviceConnection(device) as connection: |
| + logging.warning('Logging %scached %s' % ('un' if clear_cache else '', url)) |
| + if clear_cache: |
| + connection.ClearCache() |
| + trace = trace_recorder.MonitorUrl(connection, url) |
| + return trace.ToJsonDict() |
| def _FullFetch(url, json_output, prefetch, local, prefetch_delay_seconds): |
| @@ -142,7 +128,7 @@ def _FullFetch(url, json_output, prefetch, local, prefetch_delay_seconds): |
| tmp.flush() |
| # We hope that the tmpfile name is unique enough for the device. |
| target = os.path.join('/sdcard/Download', os.path.basename(tmp.name)) |
| - device = _SetupAndGetDevice() |
| + device = device_setup.GetFirstDevice() |
| device.adb.Push(tmp.name, target) |
| logging.warning('Pushed prefetch %s to device at %s' % (tmp.name, target)) |
| _LoadPage(device, 'file://' + target) |
| @@ -164,14 +150,15 @@ def _FullFetch(url, json_output, prefetch, local, prefetch_delay_seconds): |
| # TODO(mattcary): it would be nice to refactor so the --noads flag gets dealt |
| # with here. |
| def _ProcessRequests(filename): |
| - requests = log_parser.FilterRequests(log_parser.ParseJsonFile(filename)) |
| - return loading_model.ResourceGraph(requests) |
| + with open(filename) as f: |
| + return loading_model.ResourceGraph( |
|
blundell
2016/01/21 14:11:38
these two lines are:
return _ProcessJson(json.l
mattcary
2016/01/21 16:11:35
All simplified by change to allow the ResourceGrap
|
| + loading_trace.LoadingTrace.FromJsonDict(json.load(f))) |
| def _ProcessJson(json_data): |
| assert json_data |
| - return loading_model.ResourceGraph(log_parser.FilterRequests( |
| - [log_parser.RequestData.FromDict(r) for r in json_data])) |
| + return loading_model.ResourceGraph( |
| + loading_trace.LoadingTrace.FromJsonDict(json_data)) |
| def InvalidCommand(cmd): |
| @@ -255,7 +242,7 @@ def DoPrefetchSetup(arg_str): |
| html.write(_GetPrefetchHtml( |
| graph, name=os.path.basename(args.request_json))) |
| if args.upload: |
| - device = _SetupAndGetDevice() |
| + device = device_setup.GetFirstDevice() |
| destination = os.path.join('/sdcard/Download', |
| os.path.basename(args.target_html)) |
| device.adb.Push(args.target_html, destination) |
| @@ -302,20 +289,6 @@ def DoFetch(arg_str): |
| local=False) |
| -def DoTracing(arg_str): |
| - parser = argparse.ArgumentParser( |
| - usage='tracing URL JSON_OUTPUT') |
| - parser.add_argument('url') |
| - parser.add_argument('json_output') |
| - args = parser.parse_args(arg_str) |
| - device = _SetupAndGetDevice() |
| - request_logger = log_requests.AndroidRequestsLogger(device) |
| - tracing = request_logger.LogTracing(args.url) |
| - with open(args.json_output, 'w') as f: |
| - _WriteJson(f, tracing) |
| - logging.warning('Wrote ' + args.json_output) |
| - |
| - |
| def DoLongPole(arg_str): |
| parser = argparse.ArgumentParser(usage='longpole [--noads] REQUEST_JSON') |
| parser.add_argument('request_json') |
| @@ -346,7 +319,6 @@ COMMAND_MAP = { |
| 'compare': DoCompare, |
| 'prefetch_setup': DoPrefetchSetup, |
| 'log_requests': DoLogRequests, |
| - 'tracing': DoTracing, |
| 'longpole': DoLongPole, |
| 'nodecost': DoNodeCost, |
| 'fetch': DoFetch, |