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 | |
11 _NAME = 'V8.DetachedContextAgeInGC' | |
12 _UNITS = 'garbage_collections' | |
13 _DISPLAY_NAME = 'V8_DetachedContextAgeInGC' | |
14 _TYPE = histogram_util.RENDERER_HISTOGRAM | |
15 _DESCRIPTION = 'Number of GCs needed to collect detached context' | |
16 | |
17 | |
18 def _MaxDetachedContextAge(histogram_data): | |
19 if not 'buckets' in histogram_data: | |
20 return 0 | |
21 buckets = json.loads(histogram_data)['buckets'] | |
22 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,
| |
23 | |
24 | |
25 class V8DetachedContextAgeInGC(page_test.PageTest): | |
26 def __init__(self): | |
27 super(V8DetachedContextAgeInGC, self).__init__('RunPageInteractions') | |
28 self._data_start = None | |
29 | |
30 def CustomizeBrowserOptions(self, options): | |
31 options.AppendExtraBrowserArgs(['--enable-stats-collection-bindings']) | |
32 | |
33 def DidNavigateToPage(self, page, tab): | |
34 self._data_start = histogram_util.GetHistogram(_TYPE, _NAME, tab) | |
35 | |
36 def ValidateAndMeasurePage(self, page, tab, results): | |
37 # Trigger GC to get histogram data. | |
38 # Seven GCs should be enough to collect any detached context. | |
39 # If a detached context survives more GCs then there is a leak. | |
40 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.
| |
41 tab.CollectGarbage() | |
42 data = histogram_util.GetHistogram(_TYPE, _NAME, tab) | |
43 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.
| |
44 value = _MaxDetachedContextAge(delta) | |
45 results.AddValue(scalar.ScalarValue( | |
46 results.current_page, _DISPLAY_NAME, _UNITS, value, | |
47 description=_DESCRIPTION)) | |
OLD | NEW |