Index: functional/perf.py |
=================================================================== |
--- functional/perf.py (revision 109125) |
+++ functional/perf.py (working copy) |
@@ -22,6 +22,7 @@ |
""" |
import BaseHTTPServer |
+import commands |
import logging |
import math |
import os |
@@ -497,32 +498,87 @@ |
pyauto.PyUITest.__init__(self, methodName, **kwargs) |
YoutubeTestHelper.__init__(self, self) |
- def testYoutubeDroppedFrames(self): |
- """Measures the Youtube video dropped frames. Runs for 60 secs.""" |
+ def GetCPUUsage(self): |
+ """Returns the CPU usage""" |
Nirnimesh
2011/11/15 02:13:50
Mention that it get's machine's CPU usage (as oppo
rohitbm
2011/11/15 03:10:50
Done.
|
+ cpu = commands.getoutput("grep \"cpu \" /proc/stat").split() |
Nirnimesh
2011/11/15 02:13:50
use ' for the outer quote.
Then you don't need to
Nirnimesh
2011/11/15 02:13:50
Why grep? Why not read the first line (in python)
rohitbm
2011/11/15 03:10:50
Reading /proc/stat file.
rohitbm
2011/11/15 03:10:50
Done.
|
+ dict = {'user':int(cpu[1]), 'nice':int(cpu[2]), 'system':int(cpu[3]), |
Nirnimesh
2011/11/15 02:13:50
nit: put space after :
rohitbm
2011/11/15 03:10:50
Done.
|
+ 'idle':int(cpu[4])} |
+ return dict |
Nirnimesh
2011/11/15 02:13:50
merge with previous line. Get rid of |dict|
retur
rohitbm
2011/11/15 03:10:50
Done.
|
+ |
+ def VerifyVideoTotalBytes(self): |
+ """Returns true if video total bytes information is available""" |
+ return self.GetVideoTotalBytes() > 0 |
+ |
+ def VerifyVideoLoadedBytes(self): |
+ """Returns true if video loaded bytes information is available""" |
+ return self.GetVideoLoadedBytes() > 0 |
+ |
+ def StartVideoForPerformance(self): |
+ """Start the test video with all required buffering""" |
self.PlayVideoAndAssert() |
self.ExecuteJavascript(""" |
ytplayer.setPlaybackQuality('hd720'); |
window.domAutomationController.send(''); |
""") |
+ self.AssertPlayingState() |
+ self.assertTrue( |
+ self.WaitUntil(self.VerifyVideoTotalBytes, expect_retval=True), |
+ msg='Failed to get video total bytes information.') |
+ self.assertTrue( |
+ self.WaitUntil(self.VerifyVideoLoadedBytes, expect_retval=True), |
+ msg='Failed to get video loaded bytes information') |
+ loaded_video_bytes = self.GetVideoLoadedBytes() |
+ total_video_bytes = self.GetVideoTotalBytes() |
+ self.PauseVideo() |
+ count = 0 |
+ while total_video_bytes > loaded_video_bytes: |
+ loaded_video_bytes = self.GetVideoLoadedBytes() |
+ time.sleep(1) |
+ count = count + 1 |
+ # Ignoring first 10 seconds of video so we get smooth video playing. |
+ self.PlayVideo() |
+ for _ in xrange(10): |
krisr
2011/11/15 00:42:42
can we replace this with sleep(10)?
Nirnimesh
2011/11/15 02:13:50
What's this sleep for? Add comments
rohitbm
2011/11/15 03:10:50
Done.
rohitbm
2011/11/15 03:10:50
Done.
|
+ time.sleep(1) |
+ |
+ def testYoutubeDroppedFrames(self): |
+ """Measures the Youtube video dropped frames. Runs for 60 secs.""" |
+ self.StartVideoForPerformance() |
+ init_dropped_frames = self.GetVideoDroppedFrames() |
total_dropped_frames = 0 |
dropped_fps = [] |
- youtube_apis = self.GetPrivateInfo()['youtube_api'] |
- youtube_debug_text = youtube_apis['GetDebugText'] |
for _ in xrange(60): |
- video_data = self.ExecuteJavascript( |
- 'window.domAutomationController.send(%s);' % youtube_debug_text) |
- # Video data returns total dropped frames so far, so calculating |
- # the dropped frames for the last second. |
- matched = re.search('droppedFrames=([\d\.]+)', video_data) |
- if matched: |
- frames = int(matched.group(1)) |
+ frames = self.GetVideoDroppedFrames() - init_dropped_frames |
current_dropped_frames = frames - total_dropped_frames |
dropped_fps.append(current_dropped_frames) |
total_dropped_frames = frames |
time.sleep(1) |
self._PrintSummaryResults('YoutubeDroppedFrames', dropped_fps, 'frames') |
+ def testYoutubeCPU(self): |
+ """Measure the Youtube video CPU usage. Runs for 60 seconds.""" |
ilja
2011/11/14 05:14:07
Measures the Youtube video CPU usage (between 0 an
rohitbm
2011/11/15 03:10:50
Done. We found that few high motion videos's perfo
|
+ self.StartVideoForPerformance() |
+ init_dropped_frames = self.GetVideoDroppedFrames() |
+ cpu_usage1 = self.GetCPUUsage() |
+ total_shown_frames = 0 |
+ for _ in xrange(60): |
+ total_shown_frames = total_shown_frames + self.GetVideoFrames() |
+ time.sleep(1) |
Nirnimesh
2011/11/15 02:13:50
mention why you're sleeping.
# Play the video for
rohitbm
2011/11/15 03:10:50
Done.
|
+ total_dropped_frames = self.GetVideoDroppedFrames() - init_dropped_frames |
+ cpu_usage2 = self.GetCPUUsage() |
+ |
+ x2 = cpu_usage2['user'] + cpu_usage2['nice'] + cpu_usage2['system'] |
+ x1 = cpu_usage1['user'] + cpu_usage1['nice'] + cpu_usage1['system'] |
+ y2 = cpu_usage2['user'] + cpu_usage2['nice'] + \ |
+ cpu_usage2['system'] + cpu_usage2['idle'] |
+ y1 = cpu_usage1['user'] + cpu_usage1['nice'] + \ |
+ cpu_usage1['system'] + cpu_usage1['idle'] |
+ total_frames = total_shown_frames + total_dropped_frames |
+ # Counting extrapolation for utilization to play the video |
+ self._PrintSummaryResults('YoutubeCPUExtrapolation', |
+ [((float(x2) - x1) / (y2 - y1)) * total_frames/total_shown_frames], |
+ 'extrapolation') |
+ |
class FileUploadDownloadTest(BasePerfTest): |
"""Tests that involve measuring performance of upload and download.""" |