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

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

Issue 2138713002: sandwich: Fix some trivial failures on SWR benchmark runs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | tools/android/loading/sandwich_swr.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 return self.status is not None 334 return self.status is not None
335 335
336 def GetCacheControlDirective(self, directive_name): 336 def GetCacheControlDirective(self, directive_name):
337 """Returns the value of a Cache-Control directive, or None.""" 337 """Returns the value of a Cache-Control directive, or None."""
338 cache_control_str = self.GetHTTPResponseHeader('Cache-Control') 338 cache_control_str = self.GetHTTPResponseHeader('Cache-Control')
339 if cache_control_str is None: 339 if cache_control_str is None:
340 return None 340 return None
341 directives = [s.strip() for s in cache_control_str.split(',')] 341 directives = [s.strip() for s in cache_control_str.split(',')]
342 for directive in directives: 342 for directive in directives:
343 parts = directive.split('=') 343 parts = directive.split('=')
344 if len(parts) == 1: 344 if len(parts) != 2:
pasko 2016/07/11 11:26:50 was it an empty directive or more than one '='? Is
gabadie 2016/07/11 12:14:35 I had a Cache-Control: max-age=stuff1 max-age=stuf
345 continue 345 continue
346 (name, value) = parts 346 (name, value) = parts
347 if name == directive_name: 347 if name == directive_name:
348 return value 348 return value
349 return None 349 return None
350 350
351 def MaxAge(self): 351 def MaxAge(self):
352 """Returns the max-age of a resource, or -1.""" 352 """Returns the max-age of a resource, or -1."""
353 # TODO(lizeb): Handle the "Expires" header as well. 353 # TODO(lizeb): Handle the "Expires" header as well.
354 cache_control = {} 354 cache_control = {}
(...skipping 23 matching lines...) Expand all
378 request_time and the latest timing event. 378 request_time and the latest timing event.
379 """ 379 """
380 # All fields in timing are millis relative to request_time. 380 # All fields in timing are millis relative to request_time.
381 return self.timing.LargestOffset() 381 return self.timing.LargestOffset()
382 382
383 def GetRawResponseHeaders(self): 383 def GetRawResponseHeaders(self):
384 """Gets the request's raw response headers compatible with 384 """Gets the request's raw response headers compatible with
385 net::HttpResponseHeaders's constructor. 385 net::HttpResponseHeaders's constructor.
386 """ 386 """
387 assert not self.IsDataRequest() 387 assert not self.IsDataRequest()
388 assert self.HasReceivedResponse()
388 headers = '{} {} {}\x00'.format( 389 headers = '{} {} {}\x00'.format(
389 self.protocol.upper(), self.status, self.status_text) 390 self.protocol.upper(), self.status, self.status_text)
390 for key in sorted(self.response_headers.keys()): 391 for key in sorted(self.response_headers.keys()):
391 headers += '{}: {}\x00'.format(key, self.response_headers[key]) 392 try:
393 headers += '{}: {}\x00'.format(
pasko 2016/07/11 11:26:50 response headers do not have to be valid unicode,
gabadie 2016/07/11 12:14:35 Good point. Done.
394 str(key), str(self.response_headers[key]))
395 except UnicodeEncodeError:
396 logging.exception('failure when encoding one of the following: %s, %s',
397 repr(key), repr(self.response_headers[key]))
392 return headers 398 return headers
393 399
394 def __eq__(self, o): 400 def __eq__(self, o):
395 return self.__dict__ == o.__dict__ 401 return self.__dict__ == o.__dict__
396 402
397 def __hash__(self): 403 def __hash__(self):
398 return hash(self.request_id) 404 return hash(self.request_id)
399 405
400 def __str__(self): 406 def __str__(self):
401 return json.dumps(self.ToJsonDict(), sort_keys=True, indent=2) 407 return json.dumps(self.ToJsonDict(), sort_keys=True, indent=2)
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 868
863 869
864 if __name__ == '__main__': 870 if __name__ == '__main__':
865 import json 871 import json
866 import sys 872 import sys
867 events = json.load(open(sys.argv[1], 'r')) 873 events = json.load(open(sys.argv[1], 'r'))
868 request_track = RequestTrack(None) 874 request_track = RequestTrack(None)
869 for event in events: 875 for event in events:
870 event_method = event['method'] 876 event_method = event['method']
871 request_track.Handle(event_method, event) 877 request_track.Handle(event_method, event)
OLDNEW
« no previous file with comments | « no previous file | tools/android/loading/sandwich_swr.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698