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