OLD | NEW |
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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 Args: | 119 Args: |
120 url: (str) URL to match in requests. | 120 url: (str) URL to match in requests. |
121 before_timestamp: (int) Only keep requests submitted before a given | 121 before_timestamp: (int) Only keep requests submitted before a given |
122 timestamp. | 122 timestamp. |
123 | 123 |
124 Returns: | 124 Returns: |
125 A list of candidates, ordered by timestamp. | 125 A list of candidates, ordered by timestamp. |
126 """ | 126 """ |
127 candidates = self._requests_by_url.get(url, []) | 127 candidates = self._requests_by_url.get(url, []) |
128 candidates = [r for r in candidates if ( | 128 candidates = [r for r in candidates if ( |
129 r.timestamp + max(0, r.timing.receive_headers_end) <= before_timestamp)] | 129 r.timestamp + max( |
| 130 0, r.timing.receive_headers_end / 1000) <= before_timestamp)] |
130 candidates.sort(key=operator.attrgetter('timestamp')) | 131 candidates.sort(key=operator.attrgetter('timestamp')) |
131 return candidates | 132 return candidates |
132 | 133 |
133 def _FindBestMatchingInitiator(self, request, matches): | 134 def _FindBestMatchingInitiator(self, request, matches): |
134 """Returns the best matching request within a list of matches. | 135 """Returns the best matching request within a list of matches. |
135 | 136 |
136 Iteratively removes candidates until one is left: | 137 Iteratively removes candidates until one is left: |
137 - With the same parent frame. | 138 - With the same parent frame. |
138 - From the same frame. | 139 - From the same frame. |
139 | 140 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 if __name__ == '__main__': | 178 if __name__ == '__main__': |
178 import json | 179 import json |
179 import sys | 180 import sys |
180 trace_filename = sys.argv[1] | 181 trace_filename = sys.argv[1] |
181 json_dict = json.load(open(trace_filename, 'r')) | 182 json_dict = json.load(open(trace_filename, 'r')) |
182 lens = RequestDependencyLens( | 183 lens = RequestDependencyLens( |
183 loading_trace.LoadingTrace.FromJsonDict(json_dict)) | 184 loading_trace.LoadingTrace.FromJsonDict(json_dict)) |
184 depedencies = lens.GetRequestDependencies() | 185 depedencies = lens.GetRequestDependencies() |
185 for (first, second, dep_reason) in depedencies: | 186 for (first, second, dep_reason) in depedencies: |
186 print '%s -> %s\t(%s)' % (first.request_id, second.request_id, dep_reason) | 187 print '%s -> %s\t(%s)' % (first.request_id, second.request_id, dep_reason) |
OLD | NEW |