| 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 | |
| 17 from telemetry.value import scalar | 16 from telemetry.value import scalar |
| 18 | 17 |
| 19 | 18 |
| 20 class NetworkMetricException(page_test.MeasurementFailure): | 19 class NetworkMetricException(page_test.MeasurementFailure): |
| 21 pass | 20 pass |
| 22 | 21 |
| 23 | 22 |
| 24 class HTTPResponse(object): | 23 class HTTPResponse(object): |
| 25 """ Represents an HTTP response from a timeline event.""" | 24 """ Represents an HTTP response from a timeline event.""" |
| 26 def __init__(self, event): | 25 def __init__(self, event): |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 def __init__(self): | 130 def __init__(self): |
| 132 super(NetworkMetric, self).__init__() | 131 super(NetworkMetric, self).__init__() |
| 133 | 132 |
| 134 # Whether to add detailed result for each sub-resource in a page. | 133 # Whether to add detailed result for each sub-resource in a page. |
| 135 self.add_result_for_resource = False | 134 self.add_result_for_resource = False |
| 136 self.compute_data_saving = False | 135 self.compute_data_saving = False |
| 137 self._events = None | 136 self._events = None |
| 138 | 137 |
| 139 def Start(self, page, tab): | 138 def Start(self, page, tab): |
| 140 self._events = None | 139 self._events = None |
| 141 opts = recording_options.TimelineRecordingOptions() | 140 tab.StartTimelineRecording() |
| 142 opts.record_network = True | |
| 143 tab.StartTimelineRecording(opts) | |
| 144 | 141 |
| 145 def Stop(self, page, tab): | 142 def Stop(self, page, tab): |
| 146 assert self._events is None | 143 assert self._events is None |
| 147 tab.StopTimelineRecording() | 144 tab.StopTimelineRecording() |
| 148 | 145 |
| 149 def IterResponses(self, tab): | 146 def IterResponses(self, tab): |
| 150 if self._events is None: | 147 if self._events is None: |
| 151 self._events = tab.timeline_model.GetAllEventsOfName('HTTPResponse') | 148 self._events = tab.timeline_model.GetAllEventsOfName('HTTPResponse') |
| 152 if len(self._events) == 0: | 149 if len(self._events) == 0: |
| 153 return | 150 return |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 if self.compute_data_saving: | 197 if self.compute_data_saving: |
| 201 if (original_content_length > 0 and | 198 if (original_content_length > 0 and |
| 202 original_content_length >= content_length): | 199 original_content_length >= content_length): |
| 203 saving = (float(original_content_length-content_length) * 100 / | 200 saving = (float(original_content_length-content_length) * 100 / |
| 204 original_content_length) | 201 original_content_length) |
| 205 results.AddValue(scalar.ScalarValue( | 202 results.AddValue(scalar.ScalarValue( |
| 206 results.current_page, 'data_saving', 'percent', saving)) | 203 results.current_page, 'data_saving', 'percent', saving)) |
| 207 else: | 204 else: |
| 208 results.AddValue(scalar.ScalarValue( | 205 results.AddValue(scalar.ScalarValue( |
| 209 results.current_page, 'data_saving', 'percent', 0.0)) | 206 results.current_page, 'data_saving', 'percent', 0.0)) |
| OLD | NEW |