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

Side by Side Diff: functional/perf.py

Issue 8548002: Adding CPU performance test for Youtube video (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/test/
Patch Set: '' Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Basic pyauto performance tests. 6 """Basic pyauto performance tests.
7 7
8 For tests that need to be run for multiple iterations (e.g., so that average 8 For tests that need to be run for multiple iterations (e.g., so that average
9 and standard deviation values can be reported), the default number of iterations 9 and standard deviation values can be reported), the default number of iterations
10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|. 10 run for each of these tests is specified by |_DEFAULT_NUM_ITERATIONS|.
11 That value can optionally be tweaked by setting an environment variable 11 That value can optionally be tweaked by setting an environment variable
12 'NUM_ITERATIONS' to a positive integer, representing the number of iterations 12 'NUM_ITERATIONS' to a positive integer, representing the number of iterations
13 to run. 13 to run.
14 14
15 Some tests rely on repeatedly appending tabs to Chrome. Occasionally, these 15 Some tests rely on repeatedly appending tabs to Chrome. Occasionally, these
16 automation calls time out, thereby affecting the timing measurements (see issue 16 automation calls time out, thereby affecting the timing measurements (see issue
17 crosbug.com/20503). To work around this, the tests discard timing measurements 17 crosbug.com/20503). To work around this, the tests discard timing measurements
18 that involve automation timeouts. The value |_DEFAULT_MAX_TIMEOUT_COUNT| 18 that involve automation timeouts. The value |_DEFAULT_MAX_TIMEOUT_COUNT|
19 specifies the threshold number of timeouts that can be tolerated before the test 19 specifies the threshold number of timeouts that can be tolerated before the test
20 fails. To tweak this value, set environment variable 'MAX_TIMEOUT_COUNT' to the 20 fails. To tweak this value, set environment variable 'MAX_TIMEOUT_COUNT' to the
21 desired threshold value. 21 desired threshold value.
22 """ 22 """
23 23
24 import BaseHTTPServer 24 import BaseHTTPServer
25 import commands
25 import logging 26 import logging
26 import math 27 import math
27 import os 28 import os
28 import posixpath 29 import posixpath
29 import re 30 import re
30 import SimpleHTTPServer 31 import SimpleHTTPServer
31 import SocketServer 32 import SocketServer
32 import tempfile 33 import tempfile
33 import threading 34 import threading
34 import time 35 import time
(...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 self._RunNewTabTest('NewTabDocs', _RunSingleDocsTabOpen) 491 self._RunNewTabTest('NewTabDocs', _RunSingleDocsTabOpen)
491 492
492 493
493 class YoutubePerfTest(BasePerfTest, YoutubeTestHelper): 494 class YoutubePerfTest(BasePerfTest, YoutubeTestHelper):
494 """Test Youtube video performance.""" 495 """Test Youtube video performance."""
495 496
496 def __init__(self, methodName='runTest', **kwargs): 497 def __init__(self, methodName='runTest', **kwargs):
497 pyauto.PyUITest.__init__(self, methodName, **kwargs) 498 pyauto.PyUITest.__init__(self, methodName, **kwargs)
498 YoutubeTestHelper.__init__(self, self) 499 YoutubeTestHelper.__init__(self, self)
499 500
500 def testYoutubeDroppedFrames(self): 501 def GetCPUUsage(self):
501 """Measures the Youtube video dropped frames. Runs for 60 secs.""" 502 """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.
503 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.
504 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.
505 'idle':int(cpu[4])}
506 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.
507
508 def VerifyVideoTotalBytes(self):
509 """Returns true if video total bytes information is available"""
510 return self.GetVideoTotalBytes() > 0
511
512 def VerifyVideoLoadedBytes(self):
513 """Returns true if video loaded bytes information is available"""
514 return self.GetVideoLoadedBytes() > 0
515
516 def StartVideoForPerformance(self):
517 """Start the test video with all required buffering"""
502 self.PlayVideoAndAssert() 518 self.PlayVideoAndAssert()
503 self.ExecuteJavascript(""" 519 self.ExecuteJavascript("""
504 ytplayer.setPlaybackQuality('hd720'); 520 ytplayer.setPlaybackQuality('hd720');
505 window.domAutomationController.send(''); 521 window.domAutomationController.send('');
506 """) 522 """)
523 self.AssertPlayingState()
524 self.assertTrue(
525 self.WaitUntil(self.VerifyVideoTotalBytes, expect_retval=True),
526 msg='Failed to get video total bytes information.')
527 self.assertTrue(
528 self.WaitUntil(self.VerifyVideoLoadedBytes, expect_retval=True),
529 msg='Failed to get video loaded bytes information')
530 loaded_video_bytes = self.GetVideoLoadedBytes()
531 total_video_bytes = self.GetVideoTotalBytes()
532 self.PauseVideo()
533 count = 0
534 while total_video_bytes > loaded_video_bytes:
535 loaded_video_bytes = self.GetVideoLoadedBytes()
536 time.sleep(1)
537 count = count + 1
538 # Ignoring first 10 seconds of video so we get smooth video playing.
539 self.PlayVideo()
540 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.
541 time.sleep(1)
542
543 def testYoutubeDroppedFrames(self):
544 """Measures the Youtube video dropped frames. Runs for 60 secs."""
545 self.StartVideoForPerformance()
546 init_dropped_frames = self.GetVideoDroppedFrames()
507 total_dropped_frames = 0 547 total_dropped_frames = 0
508 dropped_fps = [] 548 dropped_fps = []
509 youtube_apis = self.GetPrivateInfo()['youtube_api']
510 youtube_debug_text = youtube_apis['GetDebugText']
511 for _ in xrange(60): 549 for _ in xrange(60):
512 video_data = self.ExecuteJavascript( 550 frames = self.GetVideoDroppedFrames() - init_dropped_frames
513 'window.domAutomationController.send(%s);' % youtube_debug_text)
514 # Video data returns total dropped frames so far, so calculating
515 # the dropped frames for the last second.
516 matched = re.search('droppedFrames=([\d\.]+)', video_data)
517 if matched:
518 frames = int(matched.group(1))
519 current_dropped_frames = frames - total_dropped_frames 551 current_dropped_frames = frames - total_dropped_frames
520 dropped_fps.append(current_dropped_frames) 552 dropped_fps.append(current_dropped_frames)
521 total_dropped_frames = frames 553 total_dropped_frames = frames
522 time.sleep(1) 554 time.sleep(1)
523 self._PrintSummaryResults('YoutubeDroppedFrames', dropped_fps, 'frames') 555 self._PrintSummaryResults('YoutubeDroppedFrames', dropped_fps, 'frames')
524 556
557 def testYoutubeCPU(self):
558 """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
559 self.StartVideoForPerformance()
560 init_dropped_frames = self.GetVideoDroppedFrames()
561 cpu_usage1 = self.GetCPUUsage()
562 total_shown_frames = 0
563 for _ in xrange(60):
564 total_shown_frames = total_shown_frames + self.GetVideoFrames()
565 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.
566 total_dropped_frames = self.GetVideoDroppedFrames() - init_dropped_frames
567 cpu_usage2 = self.GetCPUUsage()
568
569 x2 = cpu_usage2['user'] + cpu_usage2['nice'] + cpu_usage2['system']
570 x1 = cpu_usage1['user'] + cpu_usage1['nice'] + cpu_usage1['system']
571 y2 = cpu_usage2['user'] + cpu_usage2['nice'] + \
572 cpu_usage2['system'] + cpu_usage2['idle']
573 y1 = cpu_usage1['user'] + cpu_usage1['nice'] + \
574 cpu_usage1['system'] + cpu_usage1['idle']
575 total_frames = total_shown_frames + total_dropped_frames
576 # Counting extrapolation for utilization to play the video
577 self._PrintSummaryResults('YoutubeCPUExtrapolation',
578 [((float(x2) - x1) / (y2 - y1)) * total_frames/total_shown_frames],
579 'extrapolation')
580
525 581
526 class FileUploadDownloadTest(BasePerfTest): 582 class FileUploadDownloadTest(BasePerfTest):
527 """Tests that involve measuring performance of upload and download.""" 583 """Tests that involve measuring performance of upload and download."""
528 584
529 def setUp(self): 585 def setUp(self):
530 """Performs necessary setup work before running each test in this class.""" 586 """Performs necessary setup work before running each test in this class."""
531 self._temp_dir = tempfile.mkdtemp() 587 self._temp_dir = tempfile.mkdtemp()
532 self._test_server = PerfTestServer(self._temp_dir) 588 self._test_server = PerfTestServer(self._temp_dir)
533 self._test_server_port = self._test_server.GetPort() 589 self._test_server_port = self._test_server.GetPort()
534 self._test_server.Run() 590 self._test_server.Run()
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 """Identifies the port number to which the server is currently bound. 1236 """Identifies the port number to which the server is currently bound.
1181 1237
1182 Returns: 1238 Returns:
1183 The numeric port number to which the server is currently bound. 1239 The numeric port number to which the server is currently bound.
1184 """ 1240 """
1185 return self._server.server_address[1] 1241 return self._server.server_address[1]
1186 1242
1187 1243
1188 if __name__ == '__main__': 1244 if __name__ == '__main__':
1189 pyauto_functional.Main() 1245 pyauto_functional.Main()
OLDNEW
« no previous file with comments | « data/media/youtube.html ('k') | functional/youtube.py » ('j') | functional/youtube.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698