| OLD | NEW | 
|---|
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import base64 | 5 import base64 | 
| 6 import gzip | 6 import gzip | 
| 7 import hashlib | 7 import hashlib | 
| 8 import io | 8 import io | 
| 9 import logging | 9 import logging | 
| 10 import zlib | 10 import zlib | 
| 11 | 11 | 
| 12 from metrics import Metric | 12 from metrics import Metric | 
| 13 from telemetry.page import page_test | 13 from telemetry.page import page_test | 
| 14 # All network metrics are Chrome only for now. | 14 # All network metrics are Chrome only for now. | 
| 15 from telemetry.core.backends.chrome_inspector import inspector_network | 15 from telemetry.core.backends.chrome_inspector import inspector_network | 
| 16 from telemetry.timeline import recording_options | 16 from telemetry.timeline import recording_options | 
| 17 from telemetry.value import scalar | 17 from telemetry.value import scalar | 
| 18 | 18 | 
| 19 | 19 | 
| 20 class NetworkMetricException(page_test.MeasurementFailure): | 20 class NetworkMetricException(page_test.MeasurementFailure): | 
| 21   pass | 21   pass | 
| 22 | 22 | 
| 23 | 23 | 
| 24 class HTTPResponse(object): | 24 class HTTPResponse(object): | 
| 25   """ Represents an HTTP response from a timeline event.""" | 25   """ Represents an HTTP response from a timeline event.""" | 
| 26   def __init__(self, event): | 26   def __init__(self, event): | 
| 27     self._response = ( | 27     self._response = ( | 
| 28         inspector_network.InspectorNetworkResponseData.FromTimelineEvent(event)) | 28         inspector_network.InspectorNetworkResponseData.FromTimelineEvent(event)) | 
|  | 29     self._remote_port = None | 
|  | 30     if 'response' in event.args and 'remotePort' in event.args['response']: | 
|  | 31       self._remote_port = event.args['response']['remotePort'] | 
| 29     self._content_length = None | 32     self._content_length = None | 
| 30 | 33 | 
| 31   @property | 34   @property | 
| 32   def response(self): | 35   def response(self): | 
| 33     return self._response | 36     return self._response | 
| 34 | 37 | 
| 35   @property | 38   @property | 
|  | 39   def remote_port(self): | 
|  | 40     return self._remote_port | 
|  | 41 | 
|  | 42   @property | 
| 36   def url_signature(self): | 43   def url_signature(self): | 
| 37     return hashlib.md5(self.response.url).hexdigest() | 44     return hashlib.md5(self.response.url).hexdigest() | 
| 38 | 45 | 
| 39   @property | 46   @property | 
| 40   def content_length(self): | 47   def content_length(self): | 
| 41     if self._content_length is None: | 48     if self._content_length is None: | 
| 42       self._content_length = self.GetContentLength() | 49       self._content_length = self.GetContentLength() | 
| 43     return self._content_length | 50     return self._content_length | 
| 44 | 51 | 
| 45   @property | 52   @property | 
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 193     if self.compute_data_saving: | 200     if self.compute_data_saving: | 
| 194       if (original_content_length > 0 and | 201       if (original_content_length > 0 and | 
| 195           original_content_length >= content_length): | 202           original_content_length >= content_length): | 
| 196         saving = (float(original_content_length-content_length) * 100 / | 203         saving = (float(original_content_length-content_length) * 100 / | 
| 197                   original_content_length) | 204                   original_content_length) | 
| 198         results.AddValue(scalar.ScalarValue( | 205         results.AddValue(scalar.ScalarValue( | 
| 199             results.current_page, 'data_saving', 'percent', saving)) | 206             results.current_page, 'data_saving', 'percent', saving)) | 
| 200       else: | 207       else: | 
| 201         results.AddValue(scalar.ScalarValue( | 208         results.AddValue(scalar.ScalarValue( | 
| 202             results.current_page, 'data_saving', 'percent', 0.0)) | 209             results.current_page, 'data_saving', 'percent', 0.0)) | 
| OLD | NEW | 
|---|