OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import json |
| 6 from telemetry.page import page_test |
| 7 from telemetry.value import histogram |
| 8 from telemetry.value import histogram_util |
| 9 from telemetry.value import scalar |
| 10 from telemetry.value import skip |
| 11 |
| 12 _NAME = 'V8.DetachedContextAgeInGC' |
| 13 _UNITS = 'garbage_collections' |
| 14 _DISPLAY_NAME = 'V8_DetachedContextAgeInGC' |
| 15 _TYPE = histogram_util.RENDERER_HISTOGRAM |
| 16 _DESCRIPTION = 'Number of GCs needed to collect detached context' |
| 17 |
| 18 |
| 19 def _GetMaxDetachedContextAge(tab, data_start): |
| 20 data = histogram_util.GetHistogram(_TYPE, _NAME, tab) |
| 21 delta = histogram_util.SubtractHistogram(data, data_start) |
| 22 if not 'buckets' in delta: |
| 23 return |
| 24 buckets = json.loads(delta)['buckets'] |
| 25 if buckets: |
| 26 return max(x['high'] for x in buckets) |
| 27 |
| 28 |
| 29 class V8DetachedContextAgeInGC(page_test.PageTest): |
| 30 def __init__(self): |
| 31 super(V8DetachedContextAgeInGC, self).__init__('RunPageInteractions') |
| 32 self._data_start = None |
| 33 |
| 34 def CustomizeBrowserOptions(self, options): |
| 35 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) |
| 36 |
| 37 def DidNavigateToPage(self, page, tab): |
| 38 self._data_start = histogram_util.GetHistogram(_TYPE, _NAME, tab) |
| 39 |
| 40 def ValidateAndMeasurePage(self, page, tab, results): |
| 41 # Trigger GC to get histogram data. |
| 42 # Seven GCs should be enough to collect any detached context. |
| 43 # If a detached context survives more GCs then there is a leak. |
| 44 MAX_AGE = 8 |
| 45 for _ in xrange(MAX_AGE): |
| 46 tab.CollectGarbage() |
| 47 value = _GetMaxDetachedContextAge(tab, self._data_start) |
| 48 if value is None: |
| 49 results.AddValue(skip.SkipValue( |
| 50 results.current_page, "No detached contexts")) |
| 51 else: |
| 52 results.AddValue(scalar.ScalarValue( |
| 53 results.current_page, _DISPLAY_NAME, _UNITS, value, |
| 54 description=_DESCRIPTION)) |
OLD | NEW |