blob: 382296585d285d25d39c03b8dbc0adb567f682e0 [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()
Ionela Voinescu67802f22017-02-01 15:54:56 +000069
Juri Lelli6604ad22017-04-14 15:30:16 +010070 def __init__(self, governor, video_url, video_duration_s):
Ionela Voinescu67802f22017-02-01 15:54:56 +000071 self.governor = governor
72 self.video_url = video_url
73 self.video_duration_s = video_duration_s
Ionela Voinescu67802f22017-02-01 15:54:56 +000074 super(YouTubeTest, self).__init__()
75
76 def setupWorkload(self):
77 # Create a results folder for each "governor/test"
78 self.out_dir = os.path.join(self.te.res_dir, governor,
79 self.video_url.replace('/', '_'))
80 try:
81 os.stat(self.out_dir)
82 except:
83 os.makedirs(self.out_dir)
84 # Setup workload parameters
85 self.bm_params = {
86 'video_url' : self.video_url,
87 'video_duration_s' : self.video_duration_s,
88 }
89
90 def setupGovernor(self):
91 try:
92 self.target.cpufreq.set_all_governors(self.governor);
93 except TargetError:
94 self._log.warning('Governor [%s] not available on target',
95 self.governor)
96 raise
97
98 # Setup schedutil parameters
99 if self.governor == 'schedutil':
100 rate_limit_us = 2000
101 # Different schedutil versions have different tunables
102 tunables = self.target.cpufreq.list_governor_tunables(0)
103 if 'rate_limit_us' in tunables:
104 tunables = {'rate_limit_us' : str(rate_limit_us)}
105 else:
106 assert ('up_rate_limit_us' in tunables and
107 'down_rate_limit_us' in tunables)
108 tunables = {
109 'up_rate_limit_us' : str(rate_limit_us),
110 'down_rate_limit_us' : str(rate_limit_us)
111 }
112
113 try:
114 for cpu_id in range(self.te.platform['cpus_count']):
115 self.target.cpufreq.set_governor_tunables(
116 cpu_id, 'schedutil', **tunables)
117 except TargetError as e:
118 self._log.warning('Failed to set schedutils parameters: {}'\
119 .format(e))
120 raise
121 self._log.info('Set schedutil.rate_limit_us=%d', rate_limit_us)
122
123 # Setup ondemand parameters
124 if self.governor == 'ondemand':
125 try:
126 for cpu_id in range(self.te.platform['cpus_count']):
127 tunables = self.target.cpufreq.get_governor_tunables(cpu_id)
128 self.target.cpufreq.set_governor_tunables(
129 cpu_id, 'ondemand',
130 **{'sampling_rate' : tunables['sampling_rate_min']})
131 except TargetError as e:
132 self._log.warning('Failed to set ondemand parameters: {}'\
133 .format(e))
134 raise
135 self._log.info('Set ondemand.sampling_rate to minimum supported')
136
137 # Report configured governor
138 governors = self.target.cpufreq.get_all_governors()
139 self._log.info('Using governors: %s', governors)
140
141# Run the benchmark in each of the supported governors
142
143video_duration_s = 60
144
145governors = [
146 'performance',
147 'ondemand',
148 'interactive',
149 'sched',
150 'schedutil',
151 'powersave',
152]
153
154video_urls = [
155 'https://youtu.be/XSGBVzeBUbk?t=45s',
156]
157
Ionela Voinescu67802f22017-02-01 15:54:56 +0000158tests_remaining = len(governors) * len(video_urls)
159tests_completed = 0
160for governor in governors:
161 for url in video_urls:
162 tests_remaining -= 1
Ionela Voinescu67802f22017-02-01 15:54:56 +0000163 try:
Juri Lelli6604ad22017-04-14 15:30:16 +0100164 YouTubeTest(governor, url, video_duration_s)
Ionela Voinescu67802f22017-02-01 15:54:56 +0000165 tests_completed += 1
166 except:
167 # A test configuraion failed, continue with other tests
168 pass
Ionela Voinescu67802f22017-02-01 15:54:56 +0000169
170# We want to collect data from at least one governor
171assert(tests_completed >= 1)
172
173# vim :set tabstop=4 shiftwidth=4 expandtab