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 |
11 import collections | 11 import collections |
12 import copy | 12 import copy |
13 import datetime | 13 import datetime |
14 import email.utils | 14 import email.utils |
| 15 import hashlib |
15 import json | 16 import json |
16 import logging | 17 import logging |
17 import re | 18 import re |
18 import urlparse | 19 import urlparse |
19 | 20 |
20 import devtools_monitor | 21 import devtools_monitor |
21 | 22 |
22 | 23 |
23 class Timing(object): | 24 class Timing(object): |
24 """Collects the timing data for a request.""" | 25 """Collects the timing data for a request.""" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 @property | 207 @property |
207 def start_msec(self): | 208 def start_msec(self): |
208 return self.timing.request_time * 1000 | 209 return self.timing.request_time * 1000 |
209 | 210 |
210 @property | 211 @property |
211 def end_msec(self): | 212 def end_msec(self): |
212 if self.start_msec is None: | 213 if self.start_msec is None: |
213 return None | 214 return None |
214 return self.start_msec + self.timing.LargestOffset() | 215 return self.start_msec + self.timing.LargestOffset() |
215 | 216 |
| 217 @property |
| 218 def fingerprint(self): |
| 219 h = hashlib.sha256() |
| 220 h.update(self.url) |
| 221 return h.hexdigest()[:10] |
| 222 |
216 def _TimestampOffsetFromStartMs(self, timestamp): | 223 def _TimestampOffsetFromStartMs(self, timestamp): |
217 assert self.timing.request_time != -1 | 224 assert self.timing.request_time != -1 |
218 request_time = self.timing.request_time | 225 request_time = self.timing.request_time |
219 return (timestamp - request_time) * 1000 | 226 return (timestamp - request_time) * 1000 |
220 | 227 |
221 def ToJsonDict(self): | 228 def ToJsonDict(self): |
222 result = copy.deepcopy(self.__dict__) | 229 result = copy.deepcopy(self.__dict__) |
223 result['timing'] = self.timing.ToJsonDict() if self.timing else {} | 230 result['timing'] = self.timing.ToJsonDict() if self.timing else {} |
224 return result | 231 return result |
225 | 232 |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
772 | 779 |
773 | 780 |
774 if __name__ == '__main__': | 781 if __name__ == '__main__': |
775 import json | 782 import json |
776 import sys | 783 import sys |
777 events = json.load(open(sys.argv[1], 'r')) | 784 events = json.load(open(sys.argv[1], 'r')) |
778 request_track = RequestTrack(None) | 785 request_track = RequestTrack(None) |
779 for event in events: | 786 for event in events: |
780 event_method = event['method'] | 787 event_method = event['method'] |
781 request_track.Handle(event_method, event) | 788 request_track.Handle(event_method, event) |
OLD | NEW |