1#!/usr/bin/env python 2 3import os 4 5from time import sleep 6 7# The workload class MUST be loaded before the LisaBenchmark 8from android import Workload 9from android import LisaBenchmark 10 11from devlib.exception import TargetError 12 13class JankbenchTest(LisaBenchmark): 14 15 # Android Workload to run 16 bm_name = 'Jankbench' 17 18 # Default products to be collected 19 bm_collect = 'ftrace energy' 20 21 def benchmarkInit(self): 22 self.setupWorkload() 23 self.setupGovernor() 24 25 def __init__(self, governor, test, iterations): 26 self.governor = governor 27 self.test = test 28 self.iterations = iterations 29 super(JankbenchTest, self).__init__() 30 31 def setupWorkload(self): 32 # Create a results folder for each "governor/test" 33 self.out_dir = os.path.join(self.te.res_dir, governor, self.test) 34 try: 35 os.stat(self.out_dir) 36 except: 37 os.makedirs(self.out_dir) 38 # Setup workload parameters 39 self.bm_params = { 40 'test_name' : self.test, 41 'iterations' : self.iterations, 42 } 43 44 def setupGovernor(self): 45 try: 46 self.target.cpufreq.set_all_governors(self.governor); 47 except TargetError: 48 self._log.warning('Governor [%s] not available on target', 49 self.governor) 50 raise 51 52 # Setup schedutil parameters 53 if self.governor == 'schedutil': 54 rate_limit_us = 2000 55 # Different schedutil versions have different tunables 56 tunables = self.target.cpufreq.list_governor_tunables(0) 57 if 'rate_limit_us' in tunables: 58 tunables = {'rate_limit_us' : str(rate_limit_us)} 59 else: 60 assert ('up_rate_limit_us' in tunables and 61 'down_rate_limit_us' in tunables) 62 tunables = { 63 'up_rate_limit_us' : str(rate_limit_us), 64 'down_rate_limit_us' : str(rate_limit_us) 65 } 66 67 try: 68 for cpu_id in range(self.te.platform['cpus_count']): 69 self.target.cpufreq.set_governor_tunables( 70 cpu_id, 'schedutil', **tunables) 71 except TargetError as e: 72 self._log.warning('Failed to set schedutils parameters: {}'\ 73 .format(e)) 74 raise 75 self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us) 76 77 # Setup ondemand parameters 78 if self.governor == 'ondemand': 79 try: 80 for cpu_id in range(self.te.platform['cpus_count']): 81 tunables = self.target.cpufreq.get_governor_tunables(cpu_id) 82 self.target.cpufreq.set_governor_tunables( 83 cpu_id, 'ondemand', 84 **{'sampling_rate' : tunables['sampling_rate_min']}) 85 except TargetError as e: 86 self._log.warning('Failed to set ondemand parameters: {}'\ 87 .format(e)) 88 raise 89 self._log.info('Set ondemand.sampling_rate to minimum supported') 90 91 # Report configured governor 92 governors = self.target.cpufreq.get_all_governors() 93 self._log.info('Using governors: %s', governors) 94 95 96# Run the benchmark in each of the supported governors 97 98iterations = 1 99 100governors = [ 101 'performance', 102 'powersave', 103 'ondemand', 104 'interactive', 105 'sched', 106 'schedutil' 107] 108 109tests = [ 110 'list_view', 111 'image_list_view', 112 'shadow_grid', 113 'low_hitrate_text', 114 'high_hitrate_text', 115 'edit_text' 116] 117 118tests_remaining = len(governors) * len(tests) 119tests_completed = 0 120for governor in governors: 121 for test in tests: 122 tests_remaining -= 1 123 try: 124 JankbenchTest(governor, test, iterations) 125 tests_completed += 1 126 except: 127 # A test configuraion failed, continue with other tests 128 pass 129 130# We want to collect data from at least one governor 131assert(tests_completed >= 1) 132 133# vim :set tabstop=4 shiftwidth=4 expandtab 134