Chromium Code Reviews| OLD | NEW |
|---|---|
| 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|. |
| (...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1111 benchmark = benchmark[:benchmark.find('_mflops')] | 1111 benchmark = benchmark[:benchmark.find('_mflops')] |
| 1112 logging.info('Results for ScimarkGui_' + benchmark + ':') | 1112 logging.info('Results for ScimarkGui_' + benchmark + ':') |
| 1113 logging.info(' %.2f MFLOPS', mflops) | 1113 logging.info(' %.2f MFLOPS', mflops) |
| 1114 logging.info(' %.2f MB', mem) | 1114 logging.info(' %.2f MB', mem) |
| 1115 self._OutputPerfGraphValue( | 1115 self._OutputPerfGraphValue( |
| 1116 '%s_ScimarkGui-%s-MFLOPS' % ('MFLOPS', benchmark), mflops) | 1116 '%s_ScimarkGui-%s-MFLOPS' % ('MFLOPS', benchmark), mflops) |
| 1117 self._OutputPerfGraphValue( | 1117 self._OutputPerfGraphValue( |
| 1118 '%s_ScimarkGui-%s-Mem' % ('MB', benchmark), mem) | 1118 '%s_ScimarkGui-%s-Mem' % ('MB', benchmark), mem) |
| 1119 | 1119 |
| 1120 | 1120 |
| 1121 class LiveGamePerfTest(BasePerfTest): | |
| 1122 """Tests to measure performance of live gaming webapps.""" | |
| 1123 | |
| 1124 def ExtraChromeFlags(self): | |
| 1125 """Ensures Chrome is launched with custom flags. | |
| 1126 | |
| 1127 Returns: | |
| 1128 A list of extra flags to pass to Chrome when it is launched. | |
| 1129 """ | |
| 1130 # Ensure Chrome enables remote debugging on port 9222. This is required to | |
| 1131 # take v8 heap snapshots of tabs in Chrome. | |
| 1132 return (super(LiveGamePerfTest, self).ExtraChromeFlags() + | |
| 1133 ['--remote-debugging-port=9222']) | |
| 1134 | |
| 1135 def _RunLiveGamePerfTest(self, url, url_title_substring, | |
| 1136 description): | |
| 1137 """Measures performance metrics for the specified live gaming webapp. | |
| 1138 | |
| 1139 This function connects to the specified URL to launch the gaming webapp, | |
| 1140 waits for a period of time for the webapp to run, then collects some | |
| 1141 performance metrics about the running webapp. | |
| 1142 | |
| 1143 Args: | |
| 1144 url: The string URL of the gaming webapp to analyze. | |
| 1145 url_title_substring: A string that is expected to be a substring of the | |
| 1146 webpage title for the specified gaming webapp. Used | |
| 1147 to verify that the webapp loads correctly. | |
| 1148 description: A string description for this game, used in the performance | |
| 1149 value description. Should not contain any spaces. | |
| 1150 """ | |
| 1151 self.NavigateToURL(url) | |
| 1152 loaded_tab_title = self.GetActiveTabTitle() | |
| 1153 self.assertTrue(loaded_tab_title.find(url_title_substring) >= 0, | |
|
Nirnimesh
2011/11/19 02:31:14
better written as: url_title_substring in loaded_t
dennis_jeffrey
2011/11/22 23:36:37
Done.
| |
| 1154 msg='Loaded tab title missing "%s": "%s"' % | |
| 1155 (url_title_substring, loaded_tab_title)) | |
| 1156 cpu_usage_start = self._GetCPUUsage() | |
| 1157 | |
| 1158 # Let the app run for 1 minute. | |
|
Nirnimesh
2011/11/19 02:31:14
Don't you want to measure cpu usage over a range o
dennis_jeffrey
2011/11/22 23:36:37
Ignoring this as per our offline discussion. With
| |
| 1159 time.sleep(60) | |
| 1160 | |
| 1161 cpu_usage_end = self._GetCPUUsage() | |
| 1162 fraction_non_idle_time = self._GetFractionNonIdleCPUTime( | |
| 1163 cpu_usage_start, cpu_usage_end) | |
| 1164 | |
| 1165 logging.info('Fraction of CPU time spent non-idle: %.2f' % | |
| 1166 fraction_non_idle_time) | |
| 1167 self._OutputPerfGraphValue('Fraction_%sCpuBusy' % description, | |
| 1168 fraction_non_idle_time) | |
| 1169 snapshotter = perf_snapshot.PerformanceSnapshotter() | |
| 1170 snapshot = snapshotter.HeapSnapshot()[0] | |
| 1171 v8_heap_size = snapshot['total_heap_size'] / (1024.0 * 1024.0) | |
| 1172 logging.info('Total v8 heap size: %.2f MB' % v8_heap_size) | |
| 1173 self._OutputPerfGraphValue('MB_%sV8HeapSize' % description, v8_heap_size) | |
| 1174 | |
| 1175 def testAngryBirds(self): | |
| 1176 """Measures performance for Angry Birds.""" | |
| 1177 self._RunLiveGamePerfTest('http://chrome.angrybirds.com', 'Angry Birds', | |
| 1178 'AngryBirds') | |
| 1179 | |
| 1180 | |
| 1121 class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | 1181 class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
| 1122 """Request handler for the local performance test server.""" | 1182 """Request handler for the local performance test server.""" |
| 1123 | 1183 |
| 1124 def _IgnoreHandler(self, unused_args): | 1184 def _IgnoreHandler(self, unused_args): |
| 1125 """A GET request handler that simply replies with status code 200. | 1185 """A GET request handler that simply replies with status code 200. |
| 1126 | 1186 |
| 1127 Args: | 1187 Args: |
| 1128 unused_args: A dictionary of arguments for the current GET request. | 1188 unused_args: A dictionary of arguments for the current GET request. |
| 1129 The arguments are ignored. | 1189 The arguments are ignored. |
| 1130 """ | 1190 """ |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1344 """Identifies the port number to which the server is currently bound. | 1404 """Identifies the port number to which the server is currently bound. |
| 1345 | 1405 |
| 1346 Returns: | 1406 Returns: |
| 1347 The numeric port number to which the server is currently bound. | 1407 The numeric port number to which the server is currently bound. |
| 1348 """ | 1408 """ |
| 1349 return self._server.server_address[1] | 1409 return self._server.server_address[1] |
| 1350 | 1410 |
| 1351 | 1411 |
| 1352 if __name__ == '__main__': | 1412 if __name__ == '__main__': |
| 1353 pyauto_functional.Main() | 1413 pyauto_functional.Main() |
| OLD | NEW |