OLD | NEW |
---|---|
(Empty) | |
1 #!/usr/bin/env python | |
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 | |
4 # found in the LICENSE file. | |
5 | |
6 """CPU and memory test performance for <video>. | |
7 | |
8 Calculates CPU and memory statistics while playing videos with different | |
9 resolutions. | |
10 """ | |
11 | |
12 import logging | |
13 import os | |
14 import psutil | |
15 | |
16 import pyauto_media | |
17 import pyauto | |
18 import pyauto_utils | |
19 | |
20 # HTML test path; relative to src/chrome/test/data. | |
21 _TEST_HTML_PATH = os.path.join('media', 'html', 'media_cpu_perf.html') | |
22 | |
23 # Path under data path for test files. | |
24 _TEST_MEDIA_PATH = os.path.join('pyauto_private', 'media', 'crowd') | |
25 | |
26 # The media files used for testing. The map is from the media file type to short | |
27 # file names. A perf graph is generated for each file type. | |
28 _TEST_VIDEOS = { | |
29 'webm': ['crowd2160', 'crowd1080', 'crowd720', 'crowd480', 'crowd360'] | |
30 } | |
31 | |
32 | |
33 class MediaFPSPerfTest(pyauto.PyUITest): | |
DaleCurtis
2012/02/24 17:02:24
CPUTest?
| |
34 """PyAuto test container. See file doc string for more information.""" | |
35 | |
36 def _GetChromeRendererProcess(self): | |
37 """Returns the Chrome renderer process.""" | |
38 renderer_id = self.GetBrowserInfo()['windows'][0]['tabs'][1]['renderer_pid'] | |
39 if not renderer_id: | |
40 self.fail('Can not find the tab renderer process.') | |
41 return psutil.Process(renderer_id) | |
42 | |
43 def testMediaCPUandMemoryPerformance(self): | |
44 """Launches HTML test which plays each video and records CPU usage. | |
45 | |
46 For each video, the test plays the video and records percentage of | |
47 CPU and memory used by the chrome renderer process. | |
48 """ | |
49 for ext, files in _TEST_VIDEOS.iteritems(): | |
50 for name in files: | |
51 # Append a tab and delete it at the end of the test to free its memory. | |
52 self.AppendTab(pyauto.GURL(self.GetFileURLForDataPath(_TEST_HTML_PATH))) | |
53 | |
54 renderer_process = self._GetChromeRendererProcess() | |
55 file_url = self.GetFileURLForDataPath( | |
56 os.path.join(_TEST_MEDIA_PATH, '%s.%s' % (name, ext))) | |
57 logging.debug('Running CPU perf test for %s.', file_url) | |
58 | |
59 # Call to set a starting time to record CPU usage by the renderer. | |
60 renderer_process.get_cpu_percent() | |
61 | |
62 self.assertTrue( | |
63 self.CallJavascriptFunc('startTest', [file_url], tab_index=1)) | |
64 cpu_usage = renderer_process.get_cpu_percent() | |
65 mem_usage = renderer_process.get_memory_info()[0] / 1024 | |
66 pyauto_utils.PrintPerfResult('CPU_' + ext, name, cpu_usage, '%') | |
67 pyauto_utils.PrintPerfResult('Memory_' + ext, name, mem_usage, 'KB') | |
68 | |
69 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
70 | |
71 | |
72 if __name__ == '__main__': | |
73 pyauto_media.Main() | |
OLD | NEW |