| OLD | NEW |
| (Empty) |
| 1 #!/usr/bin/env python | |
| 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 | |
| 4 # found in the LICENSE file. | |
| 5 | |
| 6 """Performance test for HTML5 media tag. | |
| 7 | |
| 8 This PyAuto powered script plays media (video or audio) files using the HTML5 | |
| 9 tag embedded in an HTML file (specified in the GetPlayerHTMLFileName() method) | |
| 10 and measures CPU and memory usage using the psutil library in a different | |
| 11 thread using the UIPerfTestMeasureThread class. The parameters needed to | |
| 12 run this test are passed in the form of environment variables | |
| 13 (such as the number of runs). media_perf_runner.py is used for | |
| 14 generating these variables (PyAuto does not support direct parameters). | |
| 15 | |
| 16 Ref: http://code.google.com/p/psutil/wiki/Documentation | |
| 17 """ | |
| 18 | |
| 19 import os | |
| 20 import time | |
| 21 | |
| 22 import pyauto_media | |
| 23 from media_test_base import MediaTestBase | |
| 24 from media_test_env_names import MediaTestEnvNames | |
| 25 from ui_perf_test_measure_thread import UIPerfTestMeasureThread | |
| 26 from ui_perf_test_utils import UIPerfTestUtils | |
| 27 | |
| 28 | |
| 29 class MediaPerformanceTest(MediaTestBase): | |
| 30 """Tests for basic media performance.""" | |
| 31 # Since PyAuto does not support commandline argument, we have to rely on | |
| 32 # environment variables. The followings are the names of the environment | |
| 33 # variables that are used in the tests. | |
| 34 # Time interval between measurement. | |
| 35 DEFAULT_MEASURE_INTERVAL = 1 | |
| 36 TIMEOUT = 10000 | |
| 37 | |
| 38 # These predefined names are coming from library psutil | |
| 39 # except for 'measure-time' which represents the timestamp at the start | |
| 40 # of program execution. | |
| 41 CHROME_PROCESS_INFO_NAMES = ['time', | |
| 42 'procutil', | |
| 43 # procutil: a float representing the current system-wide CPU utilization | |
| 44 # as a percentage. When interval is > 0.0 compares system CPU times | |
| 45 # elapsed before and after the interval (blocking). | |
| 46 'procuser', | |
| 47 'procsystem', | |
| 48 # procuser, procsystem: process CPU user and system times which means | |
| 49 # the amount of time expressed in seconds that a process has spent in | |
| 50 # user/system mode. | |
| 51 'memoryrss', | |
| 52 'memoryvms', | |
| 53 # memoryrss, memoryvms: values representing RSS (Resident Set Size) and | |
| 54 # VMS (Virtual Memory Size) in bytes. | |
| 55 'memoryutil'] | |
| 56 # memoryutil: compare physical system memory to process resident | |
| 57 # memory and calculate process memory utilization as a percentage. | |
| 58 CHROME_PROCESS_INFO_UNITS = ['sec', | |
| 59 'percent', | |
| 60 'load', | |
| 61 'load', | |
| 62 'MB', | |
| 63 'MB', | |
| 64 'percent'] | |
| 65 # A trace list is used for legends in perf graph. One letter is | |
| 66 # preferable for trace and can be any one character letter. Here | |
| 67 # I use the first letter of each unit except for 'sec'. | |
| 68 CHROME_PROCESS_TRACE_LIST = ['t', 'p', 'l', 'l', 'm', 'm', 'p'] | |
| 69 # Instance variables. | |
| 70 run_counter = 0 | |
| 71 chrome_renderer_process_infos = [] | |
| 72 measure_thread = None | |
| 73 | |
| 74 def testHTML5MediaTag(self): | |
| 75 """Test the HTML5 media tag.""" | |
| 76 MediaTestBase.ExecuteTest(self) | |
| 77 | |
| 78 def PreAllRunsProcess(self): | |
| 79 """A method to execute before all runs.""" | |
| 80 MediaTestBase.PreAllRunsProcess(self) | |
| 81 self.chrome_renderer_process_infos = [] | |
| 82 for i in range(self.number_of_runs): | |
| 83 self.chrome_renderer_process_infos.append([]) | |
| 84 | |
| 85 def PostAllRunsProcess(self): | |
| 86 """A method to execute after all runs.""" | |
| 87 MediaTestBase.PostAllRunsProcess(self) | |
| 88 print UIPerfTestUtils.PrintMeasuredData( | |
| 89 measured_data_list=self.chrome_renderer_process_infos, | |
| 90 measured_data_name_list=self.CHROME_PROCESS_INFO_NAMES, | |
| 91 measured_data_unit_list=self.CHROME_PROCESS_INFO_UNITS, | |
| 92 remove_first_result=self.remove_first_result, | |
| 93 parameter_string=self.parameter_str, | |
| 94 trace_list=self.CHROME_PROCESS_TRACE_LIST, | |
| 95 reference_build=self.reference_build) | |
| 96 | |
| 97 def PreEachRunProcess(self, run_counter): | |
| 98 """A method to execute before each run. | |
| 99 | |
| 100 Starts a thread that measures the performance. | |
| 101 | |
| 102 Args: | |
| 103 run_counter: a counter for each run. | |
| 104 """ | |
| 105 MediaTestBase.PreEachRunProcess(self, run_counter) | |
| 106 | |
| 107 self.run_counter = run_counter | |
| 108 measure_intervals = os.getenv(MediaTestEnvNames.MEASURE_INTERVAL_ENV_NAME, | |
| 109 self.DEFAULT_MEASURE_INTERVAL) | |
| 110 # Start the thread. | |
| 111 self.measure_thread = UIPerfTestMeasureThread() | |
| 112 self.measure_thread.start() | |
| 113 | |
| 114 def PostEachRunProcess(self, run_counter): | |
| 115 """A method to execute after each run. | |
| 116 | |
| 117 Terminates the measuring thread and records the measurement in | |
| 118 measure_thread.chrome_renderer_process_info. | |
| 119 | |
| 120 Args: | |
| 121 run_counter: a counter for each run. | |
| 122 """ | |
| 123 MediaTestBase.PostEachRunProcess(self, run_counter) | |
| 124 # Record the measurement data. | |
| 125 self.chrome_renderer_process_infos[run_counter] = ( | |
| 126 self.measure_thread.chrome_renderer_process_info) | |
| 127 # Join the thread. | |
| 128 self.measure_thread.stop_measurement = True | |
| 129 self.measure_thread.join(self.TIMEOUT) | |
| 130 | |
| 131 | |
| 132 if __name__ == '__main__': | |
| 133 pyauto_media.Main() | |
| OLD | NEW |