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.
7 from telemetry
.page
import page_test
8 from telemetry
.value
import histogram_util
9 from telemetry
.value
import scalar
10 from telemetry
.value
import skip
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'
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
:
24 buckets
= json
.loads(delta
)['buckets']
26 return max(x
.get('high', x
['low']) for x
in buckets
)
29 class V8DetachedContextAgeInGC(page_test
.PageTest
):
31 super(V8DetachedContextAgeInGC
, self
).__init
__()
32 self
._data
_start
= None
34 def CustomizeBrowserOptions(self
, options
):
35 options
.AppendExtraBrowserArgs(['--enable-stats-collection-bindings'])
37 def DidNavigateToPage(self
, page
, tab
):
38 self
._data
_start
= histogram_util
.GetHistogram(_TYPE
, _NAME
, tab
)
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.
45 for _
in xrange(MAX_AGE
):
47 value
= _GetMaxDetachedContextAge(tab
, self
._data
_start
)
49 results
.AddValue(skip
.SkipValue(
50 results
.current_page
, 'No detached contexts'))
52 results
.AddValue(scalar
.ScalarValue(
53 results
.current_page
, _DISPLAY_NAME
, _UNITS
, value
,
54 description
=_DESCRIPTION
))