Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Side by Side Diff: client/site_tests/realtimecomm_GTalkPlayground/realtimecomm_GTalkPlayground.py

Issue 1224003: Add dep for playground (Closed)
Patch Set: Improvement from codereview Created 10 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/deps/realtimecomm_playground/realtimecomm_playground.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import os, re, shutil, time 5 import os, re, shutil, sys, time
6 6
7 from autotest_lib.client.bin import test, utils 7 from autotest_lib.client.bin import test, utils
8 from autotest_lib.client.common_lib import error, site_ui 8 from autotest_lib.client.common_lib import error, site_ui
9 9
10 WARMUP_TIME = 60 10 WARMUP_TIME = 60
11 SLEEP_DURATION = 260 11 SLEEP_DURATION = 260
12 12
13 def get_pids(program_name):
14 """
15 Collect a list of pids for all the instances of a program.
16
17 @param program_name the name of the program
18 @return list of pids
19 """
20 # pgrep is not appropriate here due to its truncation.
21 return utils.system_output("ps -ef | grep \'%s\' | grep -v grep | \
22 awk '{print $2}'" % program_name).split("\n")
23
24
25 def get_number_of_logical_cpu():
26 """
27 From /proc/stat/.
28
29 @return number of logic cpu
30 """
31 ret = utils.system_output("cat /proc/stat | grep ^cpu[0-9+] | wc -l")
32 return int(ret)
33
34
35 def get_utime_stime(pids):
36 """
37 Snapshot the sum of utime and the sum of stime for a list of processes.
38
39 @param pids a list of pid
40 @return [sum_of_utime, sum_of_stime]
41 """
42 timelist = [0, 0]
43 for p in pids:
44 statFile = file("/proc/%s/stat" % p, "r")
45 T = statFile.readline().split(" ")[13:15]
46 statFile.close()
47 for i in range(len(timelist)):
48 timelist[i] = timelist[i] + int(T[i])
49 return timelist
50
51
52 def get_cpu_usage(duration, time):
53 """
54 Calculate cpu usage based on duration and time on cpu.
55
56 @param duration
57 @param time on cpu
58 @return cpu usage
59 """
60 return float(time) / float(duration * get_number_of_logical_cpu())
61
62
63 class realtimecomm_GTalkPlayground(test.test): 13 class realtimecomm_GTalkPlayground(test.test):
64 version = 1 14 version = 1
65 playground = '/home/chronos/playground' 15 playground = '/home/chronos/playground'
16 dep = 'realtimecomm_playground'
66 17
67 # The tarball is created from GTalk Playground. 18 def setup(self):
68 # https://sites.google.com/a/google.com/wavelet/Home/video-playground 19 self.job.setup_dep(['realtimecomm_playground'])
69 def setup(self, tarball='GTalkPlayground.tar.gz'):
70 if os.path.exists(self.playground):
71 utils.system('rm -rf %s' % self.playground)
72 tarball = utils.unmap_url(self.bindir, tarball, self.tmpdir)
73 utils.extract_tarball_to_dir(tarball, self.srcdir)
74 20
75 21 def run_cleanup(self, testdone=False):
76 def run_cleanup(self):
77 utils.run('pkill chrome', ignore_status=True) 22 utils.run('pkill chrome', ignore_status=True)
78 time.sleep(10) 23 time.sleep(10)
79 utils.run('pkill GoogleTalkPlugin', ignore_status=True) 24 utils.run('pkill GoogleTalkPlugin', ignore_status=True)
80 time.sleep(10) 25 time.sleep(10)
81 utils.run('rm -f /tmp/tmp.log', ignore_status=True) 26 utils.run('rm -f /tmp/tmp.log', ignore_status=True)
82 utils.run('rm -rf %s' % self.playground) 27 if testdone:
28 utils.run('rm -rf %s' % self.playground)
83 # Delete previous browser state if any 29 # Delete previous browser state if any
84 shutil.rmtree('/home/chronos/.config/chromium', ignore_errors=True) 30 shutil.rmtree('/home/chronos/.config/chromium', ignore_errors=True)
31 shutil.rmtree('/home/chronos/.config/google-chrome', ignore_errors=True)
85 32
86 33
87 def run_setup(self): 34 def run_setup(self):
88 utils.run('cp -r %s %s' % (self.srcdir, self.playground)) 35 if os.path.exists(self.playground):
36 shutil.rmtree(self.playground)
37 shutil.copytree(os.path.join(self.dep_dir, 'src'), self.playground)
89 utils.run('chown chronos %s -R' % self.playground) 38 utils.run('chown chronos %s -R' % self.playground)
90 src_opt = os.path.join(self.bindir, 'options') 39 src_opt = os.path.join(self.bindir, 'options')
91 des_path= '/home/chronos/.Google/' 40 des_path= '/home/chronos/.Google/'
92 opt_path= os.path.join(des_path, 'Google Talk Plugin') 41 opt_path= os.path.join(des_path, 'Google Talk Plugin')
93 des_opt = os.path.join(opt_path, 'options') 42 des_opt = os.path.join(opt_path, 'options')
94 utils.run('mkdir -p \'%s\'' % opt_path) 43 utils.run('mkdir -p \'%s\'' % opt_path)
95 utils.run('cp -f %s \'%s\'' % (src_opt, des_opt)) 44 utils.run('cp -f %s \'%s\'' % (src_opt, des_opt))
96 utils.run('chown chronos \'%s\' -R' % des_path) 45 utils.run('chown chronos \'%s\' -R' % des_path)
97 utils.run('chmod o+r+w \'%s\'' % des_opt) 46 utils.run('chmod o+r+w \'%s\'' % des_opt)
98 47
(...skipping 23 matching lines...) Expand all
122 except IOError: 71 except IOError:
123 raise error.TestFail('Error in reading GTalk log file!') 72 raise error.TestFail('Error in reading GTalk log file!')
124 73
125 74
126 def get_framerate(self, log): 75 def get_framerate(self, log):
127 d = {} 76 d = {}
128 # We get a framerate report every 10 seconds for both streams. 77 # We get a framerate report every 10 seconds for both streams.
129 # We run for 5 mins, and should get around (5 * 60/10) * 2 = 60 78 # We run for 5 mins, and should get around (5 * 60/10) * 2 = 60
130 # framerate reports for 2 streams. 79 # framerate reports for 2 streams.
131 # Ignore the first and last framerate since they are not accurate. 80 # Ignore the first and last framerate since they are not accurate.
132 l = re.findall(r"Decoded framerate \((.*)\): (\d+\.?\d*) fps", log) 81 l = re.findall(r"Rendered framerate \((.*)\): (\d+\.?\d*) fps", log)
133 if len(l) < 57: 82 if len(l) < 57:
134 raise error.TestFail('Error in Video duration!') 83 raise error.TestFail('Error in Video duration!')
135 for i in range(1, len(l) - 1): 84 for i in range(1, len(l) - 1):
136 if d.has_key(l[i][0]): 85 if d.has_key(l[i][0]):
137 d[l[i][0]] = d[l[i][0]] + float(l[i][1]) 86 d[l[i][0]] = d[l[i][0]] + float(l[i][1])
138 else: 87 else:
139 d[l[i][0]] = float(l[i][1]) 88 d[l[i][0]] = float(l[i][1])
140 if len(d) != 2: 89 if len(d) != 2:
141 raise error.TestFail('Number of video stream is NOT 2!') 90 raise error.TestFail('Number of video stream is NOT 2!')
142 # Get framerate for two streams. 91 # Get framerate for two streams.
143 fps = [] 92 fps = []
144 for k in d: 93 for k in d:
145 fps.insert(0, d[k] * 2 / (len(l) - 2)) 94 fps.insert(0, d[k] * 2 / (len(l) - 2))
146 self.performance_results['fps_gtalk_up'] = max(fps[0], fps[1]) 95 self.performance_results['fps_gtalk_up'] = max(fps[0], fps[1])
147 self.performance_results['fps_gtalk_down'] = min(fps[0], fps[1]) 96 self.performance_results['fps_gtalk_down'] = min(fps[0], fps[1])
97 # Very low framerate means something wrong. Video hang or crash.
98 if (min(fps[0], fps[1]) < 5.0):
99 raise error.TestFail('Error in Video framerate.')
148 100
149 101
150 def run_once(self): 102 def run_once(self):
103 self.dep_dir = os.path.join(self.autodir, 'deps', self.dep)
104 sys.path.append(self.dep_dir)
105 import pgutil
106
151 self.performance_results = {} 107 self.performance_results = {}
152 self.run_cleanup() 108 self.run_cleanup()
153 self.run_setup() 109 self.run_setup()
154 110
155 # Launch Playground 111 # Launch Playground
156 path = os.path.join(self.playground, 112 path = os.path.join(self.playground,
157 'buzz/javascript/media/examples') 113 'buzz/javascript/media/examples')
158 page = 'videoplayground.html' 114 page = 'videoplayground.html'
159 para = 'callType=v' 115 para = 'callType=v'
160 playground_url = "%s/%s?%s" % (path, page, para) 116 playground_url = "%s/%s?%s" % (path, page, para)
161 # Here we somehow have to use utils.run 117 # Here we somehow have to use utils.run
162 # Other approaches like utils.system and site_ui.ChromeSession 118 # Other approaches like utils.system and site_ui.ChromeSession
163 # cause problem in video. 119 # cause problem in video.
164 # http://code.google.com/p/chromium-os/issues/detail?id=1764 120 # http://code.google.com/p/chromium-os/issues/detail?id=1764
165 utils.run('su chronos -c \'DISPLAY=:0 \ 121 utils.run('su chronos -c \'DISPLAY=:0 \
166 XAUTHORITY=/home/chronos/.Xauthority \ 122 XAUTHORITY=/home/chronos/.Xauthority \
167 /opt/google/chrome/chrome \ 123 /opt/google/chrome/chrome \
168 --no-first-run %s\' &' % playground_url) 124 --no-first-run %s\' &' % playground_url)
169 125
170 # Collect ctime,stime for GoogleTalkPlugin 126 # Collect ctime,stime for GoogleTalkPlugin
171 time.sleep(WARMUP_TIME) 127 time.sleep(WARMUP_TIME)
172 gtalk_s = get_utime_stime(get_pids('GoogleTalkPlugin')) 128 gtalk_s = pgutil.get_utime_stime(pgutil.get_pids('GoogleTalkPlugin'))
173 chrome_s = get_utime_stime(get_pids('chrome/chrome')) 129 chrome_s = pgutil.get_utime_stime(pgutil.get_pids('chrome/chrome'))
174 time.sleep(SLEEP_DURATION) 130 time.sleep(SLEEP_DURATION)
175 gtalk_e = get_utime_stime(get_pids('GoogleTalkPlugin')) 131 gtalk_e = pgutil.get_utime_stime(pgutil.get_pids('GoogleTalkPlugin'))
176 chrome_e = get_utime_stime(get_pids('chrome/chrome')) 132 chrome_e = pgutil.get_utime_stime(pgutil.get_pids('chrome/chrome'))
177 133
178 self.performance_results['ctime_gtalk'] = \ 134 self.performance_results['ctime_gtalk'] = \
179 get_cpu_usage(SLEEP_DURATION, gtalk_e[0] - gtalk_s[0]) 135 pgutil.get_cpu_usage(SLEEP_DURATION, gtalk_e[0] - gtalk_s[0])
180 self.performance_results['stime_gtalk'] = \ 136 self.performance_results['stime_gtalk'] = \
181 get_cpu_usage(SLEEP_DURATION, gtalk_e[1] - gtalk_s[1]) 137 pgutil.get_cpu_usage(SLEEP_DURATION, gtalk_e[1] - gtalk_s[1])
182 self.performance_results['ctime_chrome'] = \ 138 self.performance_results['ctime_chrome'] = \
183 get_cpu_usage(SLEEP_DURATION, chrome_e[0] - chrome_s[0]) 139 pgutil.get_cpu_usage(SLEEP_DURATION, chrome_e[0] - chrome_s[0])
184 self.performance_results['stime_chrome'] = \ 140 self.performance_results['stime_chrome'] = \
185 get_cpu_usage(SLEEP_DURATION, chrome_e[1] - chrome_s[1]) 141 pgutil.get_cpu_usage(SLEEP_DURATION, chrome_e[1] - chrome_s[1])
186 142
187 # Verify log 143 # Verify log
188 try: 144 try:
189 self.run_verification() 145 self.run_verification()
190 finally: 146 finally:
191 self.run_cleanup() 147 self.run_cleanup(True)
192 148
193 # Report perf 149 # Report perf
194 self.write_perf_keyval(self.performance_results) 150 self.write_perf_keyval(self.performance_results)
195 151
OLDNEW
« no previous file with comments | « client/deps/realtimecomm_playground/realtimecomm_playground.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698