Index: chrome/test/functional/media/media_fps_perf.py |
diff --git a/chrome/test/functional/media/media_fps_perf.py b/chrome/test/functional/media/media_fps_perf.py |
index d18e6bca7d99955a7883deb7e7d97ecd12f9a30c..c99348eb1c2011b54b9e53c77a28924d402e340b 100644 |
--- a/chrome/test/functional/media/media_fps_perf.py |
+++ b/chrome/test/functional/media/media_fps_perf.py |
@@ -3,21 +3,23 @@ |
# Use of this source code is governed by a BSD-style license that can be |
# found in the LICENSE file. |
-"""FPS (frames per second) performance test for <video>. |
+"""CPU, Memomry, and FPS performance test for <video>. |
DaleCurtis
2012/02/29 22:39:11
Memory
shadi
2012/03/01 02:40:53
Done.
|
-Calculates decoded fps and dropped fps while playing HTML5 media element. The |
-test compares results of playing a media file on different video resolutions. |
+Calculates decoded fps, dropped fps, CPU, and memory statistics while playing |
+HTML5 media element. The test compares results of playing a media file on |
+different video resolutions. |
""" |
import logging |
import os |
+import psutil |
import pyauto_media |
import pyauto |
import pyauto_utils |
# HTML test path; relative to src/chrome/test/data. |
-_TEST_HTML_PATH = os.path.join('media', 'html', 'media_fps_perf.html') |
+_TEST_HTML_PATH = os.path.join('media', 'html', 'media_stat_perf.html') |
# Path under data path for test files. |
_TEST_MEDIA_PATH = os.path.join('pyauto_private', 'media', 'crowd') |
@@ -29,33 +31,46 @@ _TEST_VIDEOS = { |
} |
-def ToMbit(value): |
- """Converts a value of byte per sec units into Mbps units.""" |
- return float(value * 8) / (1024 * 1024) |
- |
- |
-class MediaFPSPerfTest(pyauto.PyUITest): |
+class MediaStatsPerfTest(pyauto.PyUITest): |
"""PyAuto test container. See file doc string for more information.""" |
- def testMediaFPSPerformance(self): |
+ def _GetChromeRendererProcess(self): |
+ """Returns the Chrome renderer process.""" |
+ renderer_id = self.GetBrowserInfo()['windows'][0]['tabs'][1]['renderer_pid'] |
+ if not renderer_id: |
+ self.fail('Can not find the tab renderer process.') |
+ return psutil.Process(renderer_id) |
+ |
+ def testMediaPerformance(self): |
"""Launches HTML test which plays each video and records statistics. |
- For each video, the test plays till ended event is fired. It records decoded |
- fps, dropped fps, and total dropped frames. |
- """ |
- self.NavigateToURL(self.GetFileURLForDataPath(_TEST_HTML_PATH)) |
+ For each video, we run two consecutive tests: |
+ Test 1: records decoded fps, dropped fps, and total dropped frames. |
+ Test 2: records percentage CPU and memory used by Chrome renderer process. |
+ 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
|
+ avoid the overhead in memory or CPU of querying and recording FPS metrics. |
+ We close each tab after each test to avoid video caching and for precise |
+ measure of memory used by each test. |
+ """ |
for ext, files in _TEST_VIDEOS.iteritems(): |
for name in files: |
+ # Append a tab and delete it at the end of the test to free its memory. |
+ self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))) |
+ |
file_url = self.GetFileURLForDataPath( |
os.path.join(_TEST_MEDIA_PATH, '%s.%s' % (name, ext))) |
+ |
logging.debug('Running fps perf test for %s.', file_url) |
- self.assertTrue(self.ExecuteJavascript("startTest('%s');" % file_url)) |
- decoded_fps = [float(value) for value in |
- self.GetDOMValue("decodedFPS.join(',')").split(',')] |
- dropped_frames = self.GetDOMValue('droppedFrames') |
- dropped_fps = [float(value) for value in |
- self.GetDOMValue("droppedFPS.join(',')").split(',')] |
+ self.assertTrue( |
+ 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
|
+ decoded_fps = [ |
+ float(value) for value in |
+ self.GetDOMValue("decodedFPS.join(',')", tab_index=1).split(',')] |
+ dropped_frames = self.GetDOMValue('droppedFrames', tab_index=1) |
+ dropped_fps = [ |
+ float(value) for value in |
+ self.GetDOMValue("droppedFPS.join(',')", tab_index=1).split(',')] |
pyauto_utils.PrintPerfResult('FPS_' + ext, name, decoded_fps, 'fps') |
pyauto_utils.PrintPerfResult('Dropped_FPS_' + ext, name, dropped_fps, |
@@ -63,6 +78,24 @@ class MediaFPSPerfTest(pyauto.PyUITest): |
pyauto_utils.PrintPerfResult('Dropped_Frames_' + ext, name, |
dropped_frames, 'frames') |
+ self.GetBrowserWindow(0).GetTab(1).Close(True) |
+ # Run the same test again to measure CPU and memory without recording |
+ # any fps data. |
+ self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))) |
+ renderer_process = self._GetChromeRendererProcess() |
+ logging.debug('Running CPU perf test for %s.', file_url) |
+ # Call to set a starting time to record CPU usage by the renderer. |
+ renderer_process.get_cpu_percent() |
+ self.assertTrue( |
+ self.CallJavascriptFunc('startTest', [file_url, False], |
+ tab_index=1)) |
+ cpu_usage = renderer_process.get_cpu_percent() |
+ mem_usage = renderer_process.get_memory_info()[0] / 1024 |
+ pyauto_utils.PrintPerfResult('CPU_' + ext, name, cpu_usage, '%') |
+ pyauto_utils.PrintPerfResult('Memory_' + ext, name, mem_usage, 'KB') |
+ |
+ self.GetBrowserWindow(0).GetTab(1).Close(True) |
+ |
if __name__ == '__main__': |
pyauto_media.Main() |