Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 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 """FPS (frames per second) performance test for <video>. | 6 """CPU, Memomry, and FPS performance test for <video>. |
|
DaleCurtis
2012/02/29 22:39:11
Memory
shadi
2012/03/01 02:40:53
Done.
| |
| 7 | 7 |
| 8 Calculates decoded fps and dropped fps while playing HTML5 media element. The | 8 Calculates decoded fps, dropped fps, CPU, and memory statistics while playing |
| 9 test compares results of playing a media file on different video resolutions. | 9 HTML5 media element. The test compares results of playing a media file on |
| 10 different video resolutions. | |
| 10 """ | 11 """ |
| 11 | 12 |
| 12 import logging | 13 import logging |
| 13 import os | 14 import os |
| 15 import psutil | |
| 14 | 16 |
| 15 import pyauto_media | 17 import pyauto_media |
| 16 import pyauto | 18 import pyauto |
| 17 import pyauto_utils | 19 import pyauto_utils |
| 18 | 20 |
| 19 # HTML test path; relative to src/chrome/test/data. | 21 # HTML test path; relative to src/chrome/test/data. |
| 20 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_fps_perf.html') | 22 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_stat_perf.html') |
| 21 | 23 |
| 22 # Path under data path for test files. | 24 # Path under data path for test files. |
| 23 _TEST_MEDIA_PATH = os.path.join('pyauto_private', 'media', 'crowd') | 25 _TEST_MEDIA_PATH = os.path.join('pyauto_private', 'media', 'crowd') |
| 24 | 26 |
| 25 # The media files used for testing. The map is from the media file type to short | 27 # The media files used for testing. The map is from the media file type to short |
| 26 # file names. A perf graph is generated for each file type. | 28 # file names. A perf graph is generated for each file type. |
| 27 _TEST_VIDEOS = { | 29 _TEST_VIDEOS = { |
| 28 'webm': ['crowd2160', 'crowd1080', 'crowd720', 'crowd480', 'crowd360'] | 30 'webm': ['crowd2160', 'crowd1080', 'crowd720', 'crowd480', 'crowd360'] |
| 29 } | 31 } |
| 30 | 32 |
| 31 | 33 |
| 32 def ToMbit(value): | 34 class MediaStatsPerfTest(pyauto.PyUITest): |
| 33 """Converts a value of byte per sec units into Mbps units.""" | |
| 34 return float(value * 8) / (1024 * 1024) | |
| 35 | |
| 36 | |
| 37 class MediaFPSPerfTest(pyauto.PyUITest): | |
| 38 """PyAuto test container. See file doc string for more information.""" | 35 """PyAuto test container. See file doc string for more information.""" |
| 39 | 36 |
| 40 def testMediaFPSPerformance(self): | 37 def _GetChromeRendererProcess(self): |
| 38 """Returns the Chrome renderer process.""" | |
| 39 renderer_id = self.GetBrowserInfo()['windows'][0]['tabs'][1]['renderer_pid'] | |
| 40 if not renderer_id: | |
| 41 self.fail('Can not find the tab renderer process.') | |
| 42 return psutil.Process(renderer_id) | |
| 43 | |
| 44 def testMediaPerformance(self): | |
| 41 """Launches HTML test which plays each video and records statistics. | 45 """Launches HTML test which plays each video and records statistics. |
| 42 | 46 |
| 43 For each video, the test plays till ended event is fired. It records decoded | 47 For each video, we run two consecutive tests: |
| 44 fps, dropped fps, and total dropped frames. | 48 Test 1: records decoded fps, dropped fps, and total dropped frames. |
| 49 Test 2: records percentage CPU and memory used by Chrome renderer process. | |
| 50 | |
| 51 We do not calculate the CPU and memory stats while running the FPS test to | |
|
DaleCurtis
2012/02/29 22:39:11
Did you observe differences that made you decide t
shadi
2012/03/01 02:40:53
After offline discussion, we decided that even tho
| |
| 52 avoid the overhead in memory or CPU of querying and recording FPS metrics. | |
| 53 We close each tab after each test to avoid video caching and for precise | |
| 54 measure of memory used by each test. | |
| 45 """ | 55 """ |
| 46 self.NavigateToURL(self.GetFileURLForDataPath(_TEST_HTML_PATH)) | |
| 47 | |
| 48 for ext, files in _TEST_VIDEOS.iteritems(): | 56 for ext, files in _TEST_VIDEOS.iteritems(): |
| 49 for name in files: | 57 for name in files: |
| 58 # Append a tab and delete it at the end of the test to free its memory. | |
| 59 self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))) | |
| 60 | |
| 50 file_url = self.GetFileURLForDataPath( | 61 file_url = self.GetFileURLForDataPath( |
| 51 os.path.join(_TEST_MEDIA_PATH, '%s.%s' % (name, ext))) | 62 os.path.join(_TEST_MEDIA_PATH, '%s.%s' % (name, ext))) |
| 63 | |
| 52 logging.debug('Running fps perf test for %s.', file_url) | 64 logging.debug('Running fps perf test for %s.', file_url) |
| 53 self.assertTrue(self.ExecuteJavascript("startTest('%s');" % file_url)) | 65 self.assertTrue( |
| 54 decoded_fps = [float(value) for value in | 66 self.CallJavascriptFunc('startTest', [file_url, True], tab_index=1)) |
|
DaleCurtis
2012/02/29 22:39:11
I thought tab_index wasn't consistent, does this a
shadi
2012/03/01 02:40:53
It appears to work. :-)
On 2012/02/29 22:39:11, Da
| |
| 55 self.GetDOMValue("decodedFPS.join(',')").split(',')] | 67 decoded_fps = [ |
| 56 dropped_frames = self.GetDOMValue('droppedFrames') | 68 float(value) for value in |
| 57 dropped_fps = [float(value) for value in | 69 self.GetDOMValue("decodedFPS.join(',')", tab_index=1).split(',')] |
| 58 self.GetDOMValue("droppedFPS.join(',')").split(',')] | 70 dropped_frames = self.GetDOMValue('droppedFrames', tab_index=1) |
| 71 dropped_fps = [ | |
| 72 float(value) for value in | |
| 73 self.GetDOMValue("droppedFPS.join(',')", tab_index=1).split(',')] | |
| 59 | 74 |
| 60 pyauto_utils.PrintPerfResult('FPS_' + ext, name, decoded_fps, 'fps') | 75 pyauto_utils.PrintPerfResult('FPS_' + ext, name, decoded_fps, 'fps') |
| 61 pyauto_utils.PrintPerfResult('Dropped_FPS_' + ext, name, dropped_fps, | 76 pyauto_utils.PrintPerfResult('Dropped_FPS_' + ext, name, dropped_fps, |
| 62 'fps') | 77 'fps') |
| 63 pyauto_utils.PrintPerfResult('Dropped_Frames_' + ext, name, | 78 pyauto_utils.PrintPerfResult('Dropped_Frames_' + ext, name, |
| 64 dropped_frames, 'frames') | 79 dropped_frames, 'frames') |
| 65 | 80 |
| 81 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
| 82 # Run the same test again to measure CPU and memory without recording | |
| 83 # any fps data. | |
| 84 self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))) | |
| 85 renderer_process = self._GetChromeRendererProcess() | |
| 86 logging.debug('Running CPU perf test for %s.', file_url) | |
| 87 # Call to set a starting time to record CPU usage by the renderer. | |
| 88 renderer_process.get_cpu_percent() | |
| 89 self.assertTrue( | |
| 90 self.CallJavascriptFunc('startTest', [file_url, False], | |
| 91 tab_index=1)) | |
| 92 cpu_usage = renderer_process.get_cpu_percent() | |
| 93 mem_usage = renderer_process.get_memory_info()[0] / 1024 | |
| 94 pyauto_utils.PrintPerfResult('CPU_' + ext, name, cpu_usage, '%') | |
| 95 pyauto_utils.PrintPerfResult('Memory_' + ext, name, mem_usage, 'KB') | |
| 96 | |
| 97 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
| 98 | |
| 66 | 99 |
| 67 if __name__ == '__main__': | 100 if __name__ == '__main__': |
| 68 pyauto_media.Main() | 101 pyauto_media.Main() |
| OLD | NEW |