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

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

Issue 1633813005: tools/android/loading: Add support for multiple redirects. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 10 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 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Gathers and infers dependencies between requests. 5 """Gathers and infers dependencies between requests.
6 6
7 When executed as a script, loads a trace and outputs the dependencies. 7 When executed as a script, loads a trace and outputs the dependencies.
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 Args: 58 Args:
59 request: (Request) the request we wish to get the initiator of. 59 request: (Request) the request we wish to get the initiator of.
60 60
61 Returns: 61 Returns:
62 None if no dependency is found from this request, or 62 None if no dependency is found from this request, or
63 (initiator (Request), blocked_request (Request), reason (str)). 63 (initiator (Request), blocked_request (Request), reason (str)).
64 """ 64 """
65 reason = request.initiator['type'] 65 reason = request.initiator['type']
66 assert reason in request_track.Request.INITIATORS 66 assert reason in request_track.Request.INITIATORS
67 # Redirect suffixes are added in RequestTrack. 67 # Redirect suffixes are added in RequestTrack.
blundell 2016/01/26 13:23:44 Is this comment still relevant?
Benoit L 2016/01/26 13:40:47 Done.
68 if request.request_id.endswith(request_track.RequestTrack.REDIRECT_SUFFIX): 68 if reason == 'redirect':
69 return self._GetInitiatingRequestRedirect(request) 69 return self._GetInitiatingRequestRedirect(request)
70 elif reason == 'parser': 70 elif reason == 'parser':
71 return self._GetInitiatingRequestParser(request) 71 return self._GetInitiatingRequestParser(request)
72 elif reason == 'script': 72 elif reason == 'script':
73 return self._GetInitiatingRequestScript(request) 73 return self._GetInitiatingRequestScript(request)
74 else: 74 else:
75 assert reason == 'other' 75 assert reason == 'other'
76 return self._GetInitiatingRequestOther(request) 76 return self._GetInitiatingRequestOther(request)
77 77
78 def _GetInitiatingRequestRedirect(self, request): 78 def _GetInitiatingRequestRedirect(self, request):
79 request_id = request.request_id[:request.request_id.index( 79 assert request_track.Request.INITIATING_REQUEST in request.initiator
80 request_track.RequestTrack.REDIRECT_SUFFIX)] 80 initiating_request_id = request.initiator[
81 assert request_id in self._requests_by_id 81 request_track.Request.INITIATING_REQUEST]
82 dependent_request = self._requests_by_id[request_id] 82 assert initiating_request_id in self._requests_by_id
83 assert request.timing.request_time < \ 83 return (self._requests_by_id[initiating_request_id], request, 'redirect')
84 dependent_request.timing.request_time, '.\n'.join(
85 [str(request), str(dependent_request)])
86 return (request, dependent_request, 'redirect')
87 84
88 def _GetInitiatingRequestParser(self, request): 85 def _GetInitiatingRequestParser(self, request):
89 url = request.initiator['url'] 86 url = request.initiator['url']
90 candidates = self._FindMatchingRequests(url, request.timing.request_time) 87 candidates = self._FindMatchingRequests(url, request.timing.request_time)
91 if not candidates: 88 if not candidates:
92 return None 89 return None
93 initiating_request = self._FindBestMatchingInitiator(request, candidates) 90 initiating_request = self._FindBestMatchingInitiator(request, candidates)
94 return (initiating_request, request, 'parser') 91 return (initiating_request, request, 'parser')
95 92
96 def _GetInitiatingRequestScript(self, request): 93 def _GetInitiatingRequestScript(self, request):
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if __name__ == '__main__': 185 if __name__ == '__main__':
189 import json 186 import json
190 import sys 187 import sys
191 trace_filename = sys.argv[1] 188 trace_filename = sys.argv[1]
192 json_dict = json.load(open(trace_filename, 'r')) 189 json_dict = json.load(open(trace_filename, 'r'))
193 lens = RequestDependencyLens( 190 lens = RequestDependencyLens(
194 loading_trace.LoadingTrace.FromJsonDict(json_dict)) 191 loading_trace.LoadingTrace.FromJsonDict(json_dict))
195 depedencies = lens.GetRequestDependencies() 192 depedencies = lens.GetRequestDependencies()
196 for (first, second, dep_reason) in depedencies: 193 for (first, second, dep_reason) in depedencies:
197 print '%s -> %s\t(%s)' % (first.request_id, second.request_id, dep_reason) 194 print '%s -> %s\t(%s)' % (first.request_id, second.request_id, dep_reason)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698