blob: e09ca7f140a18017050c4204f377d12cc39dc9ef [file] [log] [blame]
Ionela Voinescu67802f22017-02-01 15:54:56 +00001#!/usr/bin/python
2
3import os
4from time import sleep
5
6# The workload class MUST be loaded before the LisaBenchmark
7from android import Workload
8from android import LisaBenchmark
9
10from devlib.exception import TargetError
11
12class YouTubeTest(LisaBenchmark):
13
14 bm_conf = {
15
16 # Target platform and board
17 "platform" : 'android',
18
19 # Define devlib modules to load
20 "modules" : [
21 'cpufreq',
22 ],
23
24 # FTrace events to collect for all the tests configuration which have
25 # the "ftrace" flag enabled
26 "ftrace" : {
27 "events" : [
28 "sched_switch",
29 "sched_overutilized",
30 "sched_contrib_scale_f",
31 "sched_load_avg_cpu",
32 "sched_load_avg_task",
33 "sched_tune_tasks_update",
34 "sched_boost_cpu",
35 "sched_boost_task",
36 "sched_energy_diff",
37 "cpu_frequency",
38 "cpu_idle",
39 "cpu_capacity",
40 ],
41 "buffsize" : 10 * 1024,
42 },
43
44 # Default EnergyMeter Configuration
45 "emeter" : {
46 "instrument" : "acme",
47 "channel_map" : {
48 "Device0" : 0,
49 }
50 },
51
52 # Tools required by the experiments
53 "tools" : [ 'trace-cmd' ],
54
55 # Default results folder
56 "results_dir" : "AndroidYouTube",
57
58 }
59
60 # Android Workload to run
61 bm_name = 'YouTube'
62
63 # Default products to be collected
64 bm_collect = 'ftrace energy'
65
66 def benchmarkInit(self):
67 self.setupWorkload()
68 self.setupGovernor()
69 if self.reboot:
70 self.reboot_target()
71
72 def benchmarkFinalize(self):
73 if self.delay_after_s:
74 self._log.info("Waiting %d[s] before to continue...",
75 self.delay_after_s)
76 sleep(self.delay_after_s)
77
78 def __init__(self, governor, video_url, video_duration_s, reboot=False,
79 delay_after_s=0):
80 self.reboot = reboot
81 self.governor = governor
82 self.video_url = video_url
83 self.video_duration_s = video_duration_s
84 self.delay_after_s = delay_after_s
85 super(YouTubeTest, self).__init__()
86
87 def setupWorkload(self):
88 # Create a results folder for each "governor/test"
89 self.out_dir = os.path.join(self.te.res_dir, governor,
90 self.video_url.replace('/', '_'))
91 try:
92 os.stat(self.out_dir)
93 except:
94 os.makedirs(self.out_dir)
95 # Setup workload parameters
96 self.bm_params = {
97 'video_url' : self.video_url,
98 'video_duration_s' : self.video_duration_s,
99 }
100
101 def setupGovernor(self):
102 try:
103 self.target.cpufreq.set_all_governors(self.governor);
104 except TargetError:
105 self._log.warning('Governor [%s] not available on target',
106 self.governor)
107 raise
108
109 # Setup schedutil parameters
110 if self.governor == 'schedutil':
111 rate_limit_us = 2000
112 # Different schedutil versions have different tunables
113 tunables = self.target.cpufreq.list_governor_tunables(0)
114 if 'rate_limit_us' in tunables:
115 tunables = {'rate_limit_us' : str(rate_limit_us)}
116 else:
117 assert ('up_rate_limit_us' in tunables and
118 'down_rate_limit_us' in tunables)
119 tunables = {
120 'up_rate_limit_us' : str(rate_limit_us),
121 'down_rate_limit_us' : str(rate_limit_us)
122 }
123
124 try:
125 for cpu_id in range(self.te.platform['cpus_count']):
126 self.target.cpufreq.set_governor_tunables(
127 cpu_id, 'schedutil', **tunables)
128 except TargetError as e:
129 self._log.warning('Failed to set schedutils parameters: {}'\
130 .format(e))
131 raise
132 self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us)
133
134 # Setup ondemand parameters
135 if self.governor == 'ondemand':
136 try:
137 for cpu_id in range(self.te.platform['cpus_count']):
138 tunables = self.target.cpufreq.get_governor_tunables(cpu_id)
139 self.target.cpufreq.set_governor_tunables(
140 cpu_id, 'ondemand',
141 **{'sampling_rate' : tunables['sampling_rate_min']})
142 except TargetError as e:
143 self._log.warning('Failed to set ondemand parameters: {}'\
144 .format(e))
145 raise
146 self._log.info('Set ondemand.sampling_rate to minimum supported')
147
148 # Report configured governor
149 governors = self.target.cpufreq.get_all_governors()
150 self._log.info('Using governors: %s', governors)
151
152# Run the benchmark in each of the supported governors
153
154video_duration_s = 60
155
156governors = [
157 'performance',
158 'ondemand',
159 'interactive',
160 'sched',
161 'schedutil',
162 'powersave',
163]
164
165video_urls = [
166 'https://youtu.be/XSGBVzeBUbk?t=45s',
167]
168
169# Reboot device only the first time
170do_reboot = True
171tests_remaining = len(governors) * len(video_urls)
172tests_completed = 0
173for governor in governors:
174 for url in video_urls:
175 tests_remaining -= 1
176 delay_after_s = 30 if tests_remaining else 0
177 try:
178 YouTubeTest(governor, url, video_duration_s,
179 do_reboot, delay_after_s)
180 tests_completed += 1
181 except:
182 # A test configuraion failed, continue with other tests
183 pass
184 do_reboot = False
185
186# We want to collect data from at least one governor
187assert(tests_completed >= 1)
188
189# vim :set tabstop=4 shiftwidth=4 expandtab