OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 os | 5 import os |
| 6 import json |
6 | 7 |
7 from chrome_profiler import controllers_unittest | 8 from chrome_profiler import controllers_unittest |
8 from chrome_profiler import systrace_controller | 9 from chrome_profiler import perf_controller |
9 | 10 |
10 | 11 |
11 class SystraceControllerTest(controllers_unittest.BaseControllerTest): | 12 class PerfProfilerControllerTest(controllers_unittest.BaseControllerTest): |
12 def testGetCategories(self): | 13 def testGetCategories(self): |
| 14 if not perf_controller.PerfProfilerController.IsSupported(): |
| 15 return |
13 categories = \ | 16 categories = \ |
14 systrace_controller.SystraceController.GetCategories(self.device) | 17 perf_controller.PerfProfilerController.GetCategories(self.device) |
15 self.assertTrue(categories) | 18 assert 'cycles' in ' '.join(categories) |
16 assert 'gfx' in ' '.join(categories) | |
17 | 19 |
18 def testTracing(self): | 20 def testTracing(self): |
19 categories = ['gfx', 'input', 'view'] | 21 if not perf_controller.PerfProfilerController.IsSupported(): |
20 ring_buffer = False | 22 return |
21 controller = systrace_controller.SystraceController(self.device, | 23 categories = ['cycles'] |
22 categories, | 24 controller = perf_controller.PerfProfilerController(self.device, |
23 ring_buffer) | 25 categories) |
24 | 26 |
25 interval = 1 | 27 interval = 1 |
26 try: | 28 try: |
27 controller.StartTracing(interval) | 29 controller.StartTracing(interval) |
28 finally: | 30 finally: |
29 controller.StopTracing() | 31 controller.StopTracing() |
30 | 32 |
31 result = controller.PullTrace() | 33 result = controller.PullTrace() |
32 try: | 34 try: |
33 with open(result) as f: | 35 with open(result) as f: |
34 self.assertTrue('CPU#' in f.read()) | 36 json.loads(f.read()) |
35 finally: | 37 finally: |
36 os.remove(result) | 38 os.remove(result) |
OLD | NEW |