OLD | NEW |
1 # Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 """The request data track. | 5 """The request data track. |
6 | 6 |
7 When executed, parses a JSON dump of DevTools messages. | 7 When executed, parses a JSON dump of DevTools messages. |
8 """ | 8 """ |
9 | 9 |
10 import bisect | 10 import bisect |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 return None | 213 return None |
214 return self.start_msec + self.timing.LargestOffset() | 214 return self.start_msec + self.timing.LargestOffset() |
215 | 215 |
216 def _TimestampOffsetFromStartMs(self, timestamp): | 216 def _TimestampOffsetFromStartMs(self, timestamp): |
217 assert self.timing.request_time != -1 | 217 assert self.timing.request_time != -1 |
218 request_time = self.timing.request_time | 218 request_time = self.timing.request_time |
219 return (timestamp - request_time) * 1000 | 219 return (timestamp - request_time) * 1000 |
220 | 220 |
221 def ToJsonDict(self): | 221 def ToJsonDict(self): |
222 result = copy.deepcopy(self.__dict__) | 222 result = copy.deepcopy(self.__dict__) |
223 result['timing'] = self.timing.ToJsonDict() | 223 result['timing'] = self.timing.ToJsonDict() if self.timing else {} |
224 return result | 224 return result |
225 | 225 |
226 @classmethod | 226 @classmethod |
227 def FromJsonDict(cls, data_dict): | 227 def FromJsonDict(cls, data_dict): |
228 result = Request() | 228 result = Request() |
229 for (k, v) in data_dict.items(): | 229 for (k, v) in data_dict.items(): |
230 setattr(result, k, v) | 230 setattr(result, k, v) |
231 if not result.response_headers: | 231 if not result.response_headers: |
232 result.response_headers = {} | 232 result.response_headers = {} |
233 if result.timing: | 233 if result.timing: |
(...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 772 |
773 | 773 |
774 if __name__ == '__main__': | 774 if __name__ == '__main__': |
775 import json | 775 import json |
776 import sys | 776 import sys |
777 events = json.load(open(sys.argv[1], 'r')) | 777 events = json.load(open(sys.argv[1], 'r')) |
778 request_track = RequestTrack(None) | 778 request_track = RequestTrack(None) |
779 for event in events: | 779 for event in events: |
780 event_method = event['method'] | 780 event_method = event['method'] |
781 request_track.Handle(event_method, event) | 781 request_track.Handle(event_method, event) |
OLD | NEW |