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

Side by Side Diff: tools/perf/metrics/timeline_unittest.py

Issue 211133004: Added telemetry test metric network.py. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@loading_metrics
Patch Set: sync to head. Created 6 years, 9 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
« no previous file with comments | « tools/perf/metrics/test_page_measurement_results.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2013 The Chromium Authors. All rights reserved. 1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import unittest 5 import unittest
6 6
7 from metrics import test_page_measurement_results
7 from metrics import timeline 8 from metrics import timeline
8 from telemetry.core.timeline import bounds 9 from telemetry.core.timeline import bounds
9 from telemetry.core.timeline import model as model_module 10 from telemetry.core.timeline import model as model_module
10 from telemetry.page import page as page_module
11 from telemetry.page import page_measurement_results
12 from telemetry.value import scalar
13 11
14 class TestPageMeasurementResults(
15 page_measurement_results.PageMeasurementResults):
16 def __init__(self, test):
17 super(TestPageMeasurementResults, self).__init__()
18 self.test = test
19 page = page_module.Page("http://www.google.com", {})
20 self.WillMeasurePage(page)
21
22 def GetPageSpecificValueNamed(self, name):
23 values = [value for value in self.all_page_specific_values
24 if value.name == name]
25 assert len(values) == 1, 'Could not find value named %s' % name
26 return values[0]
27
28 def AssertHasPageSpecificScalarValue(self, name, units, expected_value):
29 value = self.GetPageSpecificValueNamed(name)
30 self.test.assertEquals(units, value.units)
31 self.test.assertTrue(isinstance(value, scalar.ScalarValue))
32 self.test.assertEquals(expected_value, value.value)
33
34 def __str__(self):
35 return '\n'.join([repr(x) for x in self.all_page_specific_values])
36 12
37 class LoadTimesTimelineMetric(unittest.TestCase): 13 class LoadTimesTimelineMetric(unittest.TestCase):
38 def GetResults(self, metric): 14 def GetResults(self, metric):
39 results = TestPageMeasurementResults(self) 15 results = test_page_measurement_results.TestPageMeasurementResults(self)
40 tab = None 16 tab = None
41 metric.AddResults(tab, results) 17 metric.AddResults(tab, results)
42 return results 18 return results
43 19
44 def testSanitizing(self): 20 def testSanitizing(self):
45 model = model_module.TimelineModel() 21 model = model_module.TimelineModel()
46 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2) 22 renderer_main = model.GetOrCreateProcess(1).GetOrCreateThread(2)
47 renderer_main.name = 'CrRendererMain' 23 renderer_main.name = 'CrRendererMain'
48 24
49 # [ X ] 25 # [ X ]
(...skipping 25 matching lines...) Expand all
75 metric = timeline.LoadTimesTimelineMetric(model, renderer_main.parent) 51 metric = timeline.LoadTimesTimelineMetric(model, renderer_main.parent)
76 results = self.GetResults(metric) 52 results = self.GetResults(metric)
77 results.AssertHasPageSpecificScalarValue( 53 results.AssertHasPageSpecificScalarValue(
78 'cat_x_y', 'count', 3) 54 'cat_x_y', 'count', 3)
79 results.AssertHasPageSpecificScalarValue( 55 results.AssertHasPageSpecificScalarValue(
80 'cat_x_y_avg', 'count', 1.5) 56 'cat_x_y_avg', 'count', 1.5)
81 57
82 58
83 class ThreadTimesTimelineMetricUnittest(unittest.TestCase): 59 class ThreadTimesTimelineMetricUnittest(unittest.TestCase):
84 def GetResults(self, metric): 60 def GetResults(self, metric):
85 results = TestPageMeasurementResults(self) 61 results = test_page_measurement_results.TestPageMeasurementResults(self)
86 tab = None 62 tab = None
87 metric.AddResults(tab, results) 63 metric.AddResults(tab, results)
88 return results 64 return results
89 65
90 def GetActionRange(self, start, end): 66 def GetActionRange(self, start, end):
91 action_range = bounds.Bounds() 67 action_range = bounds.Bounds()
92 action_range.AddValue(start) 68 action_range.AddValue(start)
93 action_range.AddValue(end) 69 action_range.AddValue(end)
94 return action_range 70 return action_range
95 71
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 model, renderer_main.parent, action_ranges=[self.GetActionRange(10, 30)]) 148 model, renderer_main.parent, action_ranges=[self.GetActionRange(10, 30)])
173 metric.details_to_report = timeline.ReportMainThreadOnly 149 metric.details_to_report = timeline.ReportMainThreadOnly
174 results = self.GetResults(metric) 150 results = self.GetResults(metric)
175 151
176 # Test a couple specific results. 152 # Test a couple specific results.
177 assert_results = { 153 assert_results = {
178 timeline.ThreadCpuTimeResultName('renderer_main') : 9.0, 154 timeline.ThreadCpuTimeResultName('renderer_main') : 9.0,
179 } 155 }
180 for name, value in assert_results.iteritems(): 156 for name, value in assert_results.iteritems():
181 results.AssertHasPageSpecificScalarValue(name, 'ms', value) 157 results.AssertHasPageSpecificScalarValue(name, 'ms', value)
OLDNEW
« no previous file with comments | « tools/perf/metrics/test_page_measurement_results.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698