Home | History | Annotate | Download | only in profile_chrome
      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
      3 # found in the LICENSE file.
      4 
      5 import os
      6 import json
      7 
      8 from profile_chrome import controllers_unittest
      9 from profile_chrome import perf_controller
     10 from profile_chrome import ui
     11 
     12 from pylib import constants
     13 
     14 
     15 class PerfProfilerControllerTest(controllers_unittest.BaseControllerTest):
     16   def testGetCategories(self):
     17     if not perf_controller.PerfProfilerController.IsSupported():
     18       return
     19     categories = \
     20         perf_controller.PerfProfilerController.GetCategories(self.device)
     21     assert 'cycles' in ' '.join(categories)
     22 
     23   def testTracing(self):
     24     if not perf_controller.PerfProfilerController.IsSupported():
     25       return
     26     ui.EnableTestMode()
     27     categories = ['cycles']
     28     controller = perf_controller.PerfProfilerController(self.device,
     29                                                         categories)
     30 
     31     interval = 1
     32     try:
     33       controller.StartTracing(interval)
     34     finally:
     35       controller.StopTracing()
     36 
     37     result = controller.PullTrace()
     38     try:
     39       with open(result) as f:
     40         json.loads(f.read())
     41     finally:
     42       os.remove(result)
     43