Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(240)

Side by Side Diff: tools/perf/measurements/v8_detached_context_age_in_gc_unittest.py

Issue 930333002: [telemetry] Add new measurement that counts number of GCs needed to free V8 context. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix bucket value getter Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 from measurements import v8_detached_context_age_in_gc
6 from telemetry.core import wpr_modes
7 from telemetry.page import page_test
8 from telemetry.page import page as page_module
9 from telemetry.results import page_test_results
10 from telemetry.unittest_util import options_for_unittests
11 from telemetry.unittest_util import page_test_test_case
12 from telemetry.value import skip
13
14
15 class FakePage(object):
16 def __init__(self, url):
17 self.url = url
18 self.is_file = url.startswith('file://')
19
20
21 class FakeTab(object):
22 def __init__(self, histograms):
23 self.histograms = histograms
24 self.current_histogram_index = 0
25
26 def EvaluateJavaScript(self, script):
27 if 'V8.DetachedContextAgeInGC' in script:
28 self.current_histogram_index += 1
29 return self.histograms[self.current_histogram_index - 1]
30 return '{}'
31
32 def CollectGarbage(self):
33 pass
34
35
36 def _MeasureFakePage(histograms):
37 results = page_test_results.PageTestResults()
38 page = FakePage('file://blank.html')
39 tab = FakeTab(histograms)
40 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC()
41 results.WillRunPage(page)
42 metric.DidNavigateToPage(page, tab)
43 metric.ValidateAndMeasurePage(page, tab, results)
44 results.DidRunPage(page)
45 return results
46
47
48 def _ActualValues(results):
49 return dict((v.name, v) for v in results.all_page_specific_values)
50
51
52 class SimplePage(page_module.Page):
53 def __init__(self, page_set):
54 super(SimplePage, self).__init__(
55 'file://host.html', page_set, page_set.base_dir)
56 def RunPageInteractions(self, action_runner):
57 # Reload the page to detach the previous context.
58 action_runner.ReloadPage()
59
60
61 class V8DetachedContextAgeInGCTests(page_test_test_case.PageTestTestCase):
62
63 def setUp(self):
64 self._options = options_for_unittests.GetCopy()
65 self._options.browser_options.wpr_mode = wpr_modes.WPR_OFF
66
67 def testWithNoData(self):
68 histograms = [
69 """{"count": 0, "buckets": []}""",
70 """{"count": 0, "buckets": []}"""
71 ]
72 results = _MeasureFakePage(histograms)
73 actual = _ActualValues(results)
74 self.assertTrue('skip' in actual)
75 self.assertFalse('V8_DetachedContextAgeInGC' in actual)
76
77 def testWithData(self):
78 histograms = [
79 """{"count": 3, "buckets": [{"low": 1, "high": 2, "count": 1},
80 {"low": 2, "high": 3, "count": 2}]}""",
81 """{"count": 4, "buckets": [{"low": 1, "high": 2, "count": 2},
82 {"low": 2, "high": 3, "count": 2}]}""",
83 ]
84 results = _MeasureFakePage(histograms)
85 actual = _ActualValues(results)['V8_DetachedContextAgeInGC']
86 self.assertEqual(2, actual.value)
87 self.assertEqual('garbage_collections', actual.units)
88
89 def testWithSimplePage(self):
90 page_set = self.CreateEmptyPageSet()
91 page = SimplePage(page_set)
92 page_set.AddUserStory(page)
93 metric = v8_detached_context_age_in_gc.V8DetachedContextAgeInGC()
94 results = self.RunMeasurement(metric, page_set, options=self._options)
95 self.assertEquals(0, len(results.failures))
96 actual = _ActualValues(results)['V8_DetachedContextAgeInGC']
97 self.assertLessEqual(0, actual.value)
98 self.assertEqual('garbage_collections', actual.units)
OLDNEW
« no previous file with comments | « tools/perf/measurements/v8_detached_context_age_in_gc.py ('k') | tools/perf/page_sets/page_reload_cases.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698