blob: 44f450df22cd44751b88ba40e6751cf3e3478964 [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
Ionela Voinescu67802f22017-02-01 15:54:56 +000014 # Android Workload to run
15 bm_name = 'YouTube'
16
17 # Default products to be collected
18 bm_collect = 'ftrace energy'
19
20 def benchmarkInit(self):
21 self.setupWorkload()
22 self.setupGovernor()
Ionela Voinescu67802f22017-02-01 15:54:56 +000023
Juri Lelli6604ad22017-04-14 15:30:16 +010024 def __init__(self, governor, video_url, video_duration_s):
Ionela Voinescu67802f22017-02-01 15:54:56 +000025 self.governor = governor
26 self.video_url = video_url
27 self.video_duration_s = video_duration_s
Ionela Voinescu67802f22017-02-01 15:54:56 +000028 super(YouTubeTest, 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,
33 self.video_url.replace('/', '_'))
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 'video_url' : self.video_url,
41 'video_duration_s' : self.video_duration_s,
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# Run the benchmark in each of the supported governors
96
97video_duration_s = 60
98
99governors = [
100 'performance',
101 'ondemand',
102 'interactive',
103 'sched',
104 'schedutil',
105 'powersave',
106]
107
108video_urls = [
109 'https://youtu.be/XSGBVzeBUbk?t=45s',
110]
111
Ionela Voinescu67802f22017-02-01 15:54:56 +0000112tests_remaining = len(governors) * len(video_urls)
113tests_completed = 0
114for governor in governors:
115 for url in video_urls:
116 tests_remaining -= 1
Ionela Voinescu67802f22017-02-01 15:54:56 +0000117 try:
Juri Lelli6604ad22017-04-14 15:30:16 +0100118 YouTubeTest(governor, url, video_duration_s)
Ionela Voinescu67802f22017-02-01 15:54:56 +0000119 tests_completed += 1
120 except:
121 # A test configuraion failed, continue with other tests
122 pass
Ionela Voinescu67802f22017-02-01 15:54:56 +0000123
124# We want to collect data from at least one governor
125assert(tests_completed >= 1)
126
127# vim :set tabstop=4 shiftwidth=4 expandtab