| Index: tools/perf/measurements/v8_detached_context_age_in_gc.py
|
| diff --git a/tools/perf/measurements/v8_detached_context_age_in_gc.py b/tools/perf/measurements/v8_detached_context_age_in_gc.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ca9800f8cd1974f04ae4faee0fb716d88137a328
|
| --- /dev/null
|
| +++ b/tools/perf/measurements/v8_detached_context_age_in_gc.py
|
| @@ -0,0 +1,54 @@
|
| +# Copyright 2015 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import json
|
| +from telemetry.page import page_test
|
| +from telemetry.value import histogram
|
| +from telemetry.value import histogram_util
|
| +from telemetry.value import scalar
|
| +from telemetry.value import skip
|
| +
|
| +_NAME = 'V8.DetachedContextAgeInGC'
|
| +_UNITS = 'garbage_collections'
|
| +_DISPLAY_NAME = 'V8_DetachedContextAgeInGC'
|
| +_TYPE = histogram_util.RENDERER_HISTOGRAM
|
| +_DESCRIPTION = 'Number of GCs needed to collect detached context'
|
| +
|
| +
|
| +def _GetMaxDetachedContextAge(tab, data_start):
|
| + data = histogram_util.GetHistogram(_TYPE, _NAME, tab)
|
| + delta = histogram_util.SubtractHistogram(data, data_start)
|
| + if not 'buckets' in delta:
|
| + return
|
| + buckets = json.loads(delta)['buckets']
|
| + if buckets:
|
| + return max(x['high'] for x in buckets)
|
| +
|
| +
|
| +class V8DetachedContextAgeInGC(page_test.PageTest):
|
| + def __init__(self):
|
| + super(V8DetachedContextAgeInGC, self).__init__('RunPageInteractions')
|
| + self._data_start = None
|
| +
|
| + def CustomizeBrowserOptions(self, options):
|
| + options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
|
| +
|
| + def DidNavigateToPage(self, page, tab):
|
| + self._data_start = histogram_util.GetHistogram(_TYPE, _NAME, tab)
|
| +
|
| + def ValidateAndMeasurePage(self, page, tab, results):
|
| + # Trigger GC to get histogram data.
|
| + # Seven GCs should be enough to collect any detached context.
|
| + # If a detached context survives more GCs then there is a leak.
|
| + MAX_AGE = 8
|
| + for _ in xrange(MAX_AGE):
|
| + tab.CollectGarbage()
|
| + value = _GetMaxDetachedContextAge(tab, self._data_start)
|
| + if value is None:
|
| + results.AddValue(skip.SkipValue(
|
| + results.current_page, "No detached contexts"))
|
| + else:
|
| + results.AddValue(scalar.ScalarValue(
|
| + results.current_page, _DISPLAY_NAME, _UNITS, value,
|
| + description=_DESCRIPTION))
|
|
|