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..a0537205cc23eac3bf93dd079a477d21ef5c1ee6 |
--- /dev/null |
+++ b/tools/perf/measurements/v8_detached_context_age_in_gc.py |
@@ -0,0 +1,47 @@ |
+# 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 |
+ |
+_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 _MaxDetachedContextAge(histogram_data): |
+ if not 'buckets' in histogram_data: |
+ return 0 |
+ buckets = json.loads(histogram_data)['buckets'] |
+ return max(x['high'] for x in buckets) if buckets else 0 |
rmcilroy
2015/02/18 11:20:31
is '0' a good value for when we don't find buckets
ulan
2015/02/18 13:33:16
Good point. There can be no detached contexts. If,
|
+ |
+ |
+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. |
+ for _ in xrange(8): |
rmcilroy
2015/02/18 11:20:31
nit - pull '8' out into a constant.
ulan
2015/02/18 13:33:16
Done.
|
+ tab.CollectGarbage() |
+ data = histogram_util.GetHistogram(_TYPE, _NAME, tab) |
+ delta = histogram_util.SubtractHistogram(data, self._data_start) |
rmcilroy
2015/02/18 11:20:31
nit - I would do the getHistogram / SubtractHistog
ulan
2015/02/18 13:33:16
Done.
|
+ value = _MaxDetachedContextAge(delta) |
+ results.AddValue(scalar.ScalarValue( |
+ results.current_page, _DISPLAY_NAME, _UNITS, value, |
+ description=_DESCRIPTION)) |