Chromium Code Reviews| 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..8c5a776568c37087a168ae01334ade3fb2b73eed |
| --- /dev/null |
| +++ b/tools/perf/measurements/v8_detached_context_age_in_gc.py |
| @@ -0,0 +1,46 @@ |
| +# Copyright 2012 The Chromium Authors. All rights reserved. |
|
Sami
2015/02/17 17:14:06
year += 3 :)
ulan
2015/02/18 10:35:56
Done.
|
| +# 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 |
| + |
| +_NAME = 'V8.DetachedContextAgeInGC' |
| +_UNITS = 'garbage_collections' |
| +_DISPLAY_NAME = 'V8_DetachedContextAgeInGC' |
| +_TYPE = histogram_util.RENDERER_HISTOGRAM |
| +_DESCRIPTION = 'Number of GCs needed to collect detached context' |
| + |
|
Sami
2015/02/17 17:14:06
nit: add an extra blank line here.
ulan
2015/02/18 10:35:56
Done.
|
| +def _MaxDetachedContextAge(histogram_data): |
| + if not 'buckets' in histogram_data: |
| + return 0 |
| + buckets = json.loads(histogram_data)['buckets'] |
| + return max(map(lambda x: x['high'], buckets)) if buckets else 0 |
|
Sami
2015/02/17 17:14:06
nit: max(x['high'] for x in buckets) works too.
ulan
2015/02/18 10:35:55
Done.
|
| + |
| + |
| +class V8DetachedContextAgeInGC(page_test.PageTest): |
|
Sami
2015/02/17 17:14:06
Could you please add a unit test for this too?
ulan
2015/02/18 10:35:56
Done.
|
| + 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. |
| + for _ in xrange(8): |
| + tab.CollectGarbage() |
| + data = histogram_util.GetHistogram(_TYPE, _NAME, tab) |
| + delta = histogram_util.SubtractHistogram(data, self._data_start) |
| + value = _MaxDetachedContextAge(delta) |
| + results.AddValue(scalar.ScalarValue( |
| + results.current_page, _DISPLAY_NAME, _UNITS, value, |
| + description=_DESCRIPTION)) |