| 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import time | 7 import time |
| 8 | 8 |
| 9 from common import chrome_proxy_metrics | 9 from common import chrome_proxy_metrics |
| 10 from common import network_metrics | 10 from common import network_metrics |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 raise ChromeProxyMetricException, ( | 255 raise ChromeProxyMetricException, ( |
| 256 'Expected at least one LoFi response, but zero such responses were ' | 256 'Expected at least one LoFi response, but zero such responses were ' |
| 257 'received.') | 257 'received.') |
| 258 | 258 |
| 259 results.AddValue(scalar.ScalarValue( | 259 results.AddValue(scalar.ScalarValue( |
| 260 results.current_page, 'lo_fi_request', 'count', lo_fi_request_count)) | 260 results.current_page, 'lo_fi_request', 'count', lo_fi_request_count)) |
| 261 results.AddValue(scalar.ScalarValue( | 261 results.AddValue(scalar.ScalarValue( |
| 262 results.current_page, 'lo_fi_response', 'count', lo_fi_response_count)) | 262 results.current_page, 'lo_fi_response', 'count', lo_fi_response_count)) |
| 263 super(ChromeProxyMetric, self).AddResults(tab, results) | 263 super(ChromeProxyMetric, self).AddResults(tab, results) |
| 264 | 264 |
| 265 def AddResultsForPassThrough(self, tab, results): |
| 266 compressed_count = 0 |
| 267 compressed_size = 0 |
| 268 pass_through_count = 0 |
| 269 pass_through_size = 0 |
| 270 |
| 271 for resp in self.IterResponses(tab): |
| 272 if 'favicon.ico' in resp.response.url: |
| 273 continue |
| 274 if not resp.HasChromeProxyViaHeader(): |
| 275 r = resp.response |
| 276 raise ChromeProxyMetricException, ( |
| 277 '%s: Should have Via header (%s) (refer=%s, status=%d)' % ( |
| 278 r.url, r.GetHeader('Via'), r.GetHeader('Referer'), r.status)) |
| 279 if resp.HasChromeProxyPassThroughRequest(): |
| 280 pass_through_count += 1 |
| 281 pass_through_size = resp.content_length |
| 282 else: |
| 283 compressed_count += 1 |
| 284 compressed_size = resp.content_length |
| 285 |
| 286 if pass_through_count != 1: |
| 287 raise ChromeProxyMetricException, ( |
| 288 'Expected exactly one Chrome-Proxy pass-through request, but %d ' |
| 289 'such requests were sent.' % (pass_through_count)) |
| 290 |
| 291 if compressed_count != 1: |
| 292 raise ChromeProxyMetricException, ( |
| 293 'Expected exactly one compressed request, but %d such requests were ' |
| 294 'received.' % (compressed_count)) |
| 295 |
| 296 if compressed_size >= pass_through_size: |
| 297 raise ChromeProxyMetricException, ( |
| 298 'Compressed image is %d bytes and pass-through image is %d. ' |
| 299 'Expecting compressed image size to be less than pass-through ' |
| 300 'image.' % (compressed_size, pass_through_size)) |
| 301 |
| 302 results.AddValue(scalar.ScalarValue( |
| 303 results.current_page, 'compressed', 'count', compressed_count)) |
| 304 results.AddValue(scalar.ScalarValue( |
| 305 results.current_page, 'compressed_size', 'bytes', compressed_size)) |
| 306 results.AddValue(scalar.ScalarValue( |
| 307 results.current_page, 'pass_through', 'count', pass_through_count)) |
| 308 results.AddValue(scalar.ScalarValue( |
| 309 results.current_page, 'pass_through_size', 'bytes', pass_through_size)) |
| 310 |
| 265 def AddResultsForBypass(self, tab, results, url_pattern=""): | 311 def AddResultsForBypass(self, tab, results, url_pattern=""): |
| 266 bypass_count = 0 | 312 bypass_count = 0 |
| 267 skipped_count = 0 | 313 skipped_count = 0 |
| 268 | 314 |
| 269 for resp in self.IterResponses(tab): | 315 for resp in self.IterResponses(tab): |
| 270 # Only check the url's that contain the specified pattern. | 316 # Only check the url's that contain the specified pattern. |
| 271 if url_pattern and url_pattern not in resp.response.url: | 317 if url_pattern and url_pattern not in resp.response.url: |
| 272 skipped_count += 1 | 318 skipped_count += 1 |
| 273 continue | 319 continue |
| 274 | 320 |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 if xocl != None: | 665 if xocl != None: |
| 620 err('%s: has XOriginalContentLength' % kind) | 666 err('%s: has XOriginalContentLength' % kind) |
| 621 | 667 |
| 622 if not found: | 668 if not found: |
| 623 err('%s: missing video response' % kind) | 669 err('%s: missing video response' % kind) |
| 624 | 670 |
| 625 # Finally, add all the metrics to the results. | 671 # Finally, add all the metrics to the results. |
| 626 for (k,v) in self.videoMetrics.iteritems(): | 672 for (k,v) in self.videoMetrics.iteritems(): |
| 627 k = "%s_%s" % (k, kind) | 673 k = "%s_%s" % (k, kind) |
| 628 results.AddValue(scalar.ScalarValue(results.current_page, k, "", v)) | 674 results.AddValue(scalar.ScalarValue(results.current_page, k, "", v)) |
| OLD | NEW |