OLD | NEW |
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 cpu | 7 from metrics import cpu |
8 | 8 |
9 # Testing private method. | 9 # Testing private method. |
10 # pylint: disable=W0212 | 10 # pylint: disable=W0212 |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 # A process type will be ignored if there's an empty dict for start or end. | 25 # A process type will be ignored if there's an empty dict for start or end. |
26 start['Renderer'] = {} | 26 start['Renderer'] = {} |
27 self.assertEqual({'Browser': 0.25}, cpu._SubtractCpuStats(end, start)) | 27 self.assertEqual({'Browser': 0.25}, cpu._SubtractCpuStats(end, start)) |
28 | 28 |
29 # Results for multiple process types can be computed. | 29 # Results for multiple process types can be computed. |
30 start['Renderer'] = {'CpuProcessTime': 0, 'TotalTime': 0} | 30 start['Renderer'] = {'CpuProcessTime': 0, 'TotalTime': 0} |
31 self.assertEqual({'Browser': 0.25, 'Renderer': 0.1}, | 31 self.assertEqual({'Browser': 0.25, 'Renderer': 0.1}, |
32 cpu._SubtractCpuStats(end, start)) | 32 cpu._SubtractCpuStats(end, start)) |
33 | 33 |
| 34 # The result for global frequency stats is used. |
| 35 start = { |
| 36 'Browser': {'CpuProcessTime': 0, 'TotalTime': 0}, |
| 37 'Global': {'GlobalCpuFrequencyStats': {1000000: 9, 2000000: 19}} |
| 38 } |
| 39 end = { |
| 40 'Browser': {'CpuProcessTime': 5, 'TotalTime': 20}, |
| 41 'Global': {'GlobalCpuFrequencyStats': {1000000: 20, 2000000: 31}} |
| 42 } |
| 43 |
| 44 expected = { |
| 45 'Browser': 0.25, |
| 46 'Global': {'GlobalCpuFrequencyStats': {1000000: 11, 2000000: 12}} |
| 47 } |
| 48 |
| 49 self.assertEqual(expected, cpu._SubtractCpuStats(end, start)) |
| 50 |
| 51 def testAddResults(self): |
| 52 results = { |
| 53 'Browser': 0.25, |
| 54 'Global': {'GlobalCpuFrequencyStats': {1000000: 11, 2000000: 12}} |
| 55 } |
| 56 class MockResults(object): |
| 57 def __init__(self): |
| 58 self.trace_name = None |
| 59 self.units = None |
| 60 self.value = None |
| 61 self.chart_name = None |
| 62 self.data_type = None |
| 63 |
| 64 def Add(self, trace_name, units, value, chart_name=None, |
| 65 data_type='default'): |
| 66 self.trace_name = trace_name |
| 67 self.units = units |
| 68 self.value = value |
| 69 self.chart_name = chart_name |
| 70 self.data_type = data_type |
| 71 |
| 72 mock_results = MockResults() |
| 73 cpu_metric = cpu.CpuMetric(None) |
| 74 cpu_metric._results = results |
| 75 cpu_metric.AddResults(None, mock_results) |
| 76 self.assertEquals(1521.74, mock_results.value) |
| 77 |
OLD | NEW |