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 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 cpu_usage2['system'] + cpu_usage2['idle'] | 594 cpu_usage2['system'] + cpu_usage2['idle'] |
595 y1 = cpu_usage1['user'] + cpu_usage1['nice'] + \ | 595 y1 = cpu_usage1['user'] + cpu_usage1['nice'] + \ |
596 cpu_usage1['system'] + cpu_usage1['idle'] | 596 cpu_usage1['system'] + cpu_usage1['idle'] |
597 total_frames = total_shown_frames + total_dropped_frames | 597 total_frames = total_shown_frames + total_dropped_frames |
598 # Counting extrapolation for utilization to play the video | 598 # Counting extrapolation for utilization to play the video |
599 self._PrintSummaryResults('YoutubeCPUExtrapolation', | 599 self._PrintSummaryResults('YoutubeCPUExtrapolation', |
600 [((float(x2) - x1) / (y2 - y1)) * total_frames/total_shown_frames], | 600 [((float(x2) - x1) / (y2 - y1)) * total_frames/total_shown_frames], |
601 'extrapolation') | 601 'extrapolation') |
602 | 602 |
603 | 603 |
| 604 class WebGLTest(BasePerfTest): |
| 605 """Tests for WebGL performance.""" |
| 606 |
| 607 def _RunWebGLTest(self, url, description): |
| 608 """Measures FPS using a specified WebGL demo. |
| 609 |
| 610 Args: |
| 611 url: The string URL that, once loaded, will run the WebGL demo (default |
| 612 WebGL demo settings are used, since this test does not modify any |
| 613 settings in the demo). |
| 614 description: A string description for this demo, used as a performance |
| 615 value description. Should not contain any spaces. |
| 616 """ |
| 617 self.assertTrue(self.AppendTab(pyauto.GURL(url)), |
| 618 msg='Failed to append tab for %s.' % description) |
| 619 |
| 620 get_fps_js = """ |
| 621 var fps_field = document.getElementById("fps"); |
| 622 var result = -1; |
| 623 if (fps_field) |
| 624 result = fps_field.innerHTML; |
| 625 window.domAutomationController.send(JSON.stringify(result)); |
| 626 """ |
| 627 |
| 628 # Wait until we start getting FPS values. |
| 629 self.assertTrue( |
| 630 self.WaitUntil( |
| 631 lambda: self.ExecuteJavascript(get_fps_js, tab_index=1) != '-1', |
| 632 timeout=300, retry_sleep=1), |
| 633 msg='Timed out when waiting for FPS values to be available.') |
| 634 |
| 635 # Let the experiment run for 5 seconds before we start collecting perf |
| 636 # measurements. |
| 637 time.sleep(5) |
| 638 |
| 639 # Collect the current FPS value each second for the next 30 seconds. The |
| 640 # final result of this test will be the average of these FPS values. |
| 641 fps_vals = [] |
| 642 for _ in xrange(30): |
| 643 fps = self.ExecuteJavascript(get_fps_js, tab_index=1) |
| 644 fps_vals.append(float(fps.replace('"', ''))) |
| 645 time.sleep(1) |
| 646 self._PrintSummaryResults(description, fps_vals, 'fps') |
| 647 |
| 648 def testWebGLAquarium(self): |
| 649 """Measures performance using the WebGL Aquarium demo.""" |
| 650 self._RunWebGLTest( |
| 651 self.GetFileURLForDataPath('pyauto_private', 'webgl', 'aquarium', |
| 652 'aquarium.html'), |
| 653 'WebGLAquarium') |
| 654 |
| 655 def testWebGLField(self): |
| 656 """Measures performance using the WebGL Field demo.""" |
| 657 self._RunWebGLTest( |
| 658 self.GetFileURLForDataPath('pyauto_private', 'webgl', 'field', |
| 659 'field.html'), |
| 660 'WebGLField') |
| 661 |
| 662 |
604 class FileUploadDownloadTest(BasePerfTest): | 663 class FileUploadDownloadTest(BasePerfTest): |
605 """Tests that involve measuring performance of upload and download.""" | 664 """Tests that involve measuring performance of upload and download.""" |
606 | 665 |
607 def setUp(self): | 666 def setUp(self): |
608 """Performs necessary setup work before running each test in this class.""" | 667 """Performs necessary setup work before running each test in this class.""" |
609 self._temp_dir = tempfile.mkdtemp() | 668 self._temp_dir = tempfile.mkdtemp() |
610 self._test_server = PerfTestServer(self._temp_dir) | 669 self._test_server = PerfTestServer(self._temp_dir) |
611 self._test_server_port = self._test_server.GetPort() | 670 self._test_server_port = self._test_server.GetPort() |
612 self._test_server.Run() | 671 self._test_server.Run() |
613 self.assertTrue(self.WaitUntil(self._IsTestServerRunning), | 672 self.assertTrue(self.WaitUntil(self._IsTestServerRunning), |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 """Identifies the port number to which the server is currently bound. | 1317 """Identifies the port number to which the server is currently bound. |
1259 | 1318 |
1260 Returns: | 1319 Returns: |
1261 The numeric port number to which the server is currently bound. | 1320 The numeric port number to which the server is currently bound. |
1262 """ | 1321 """ |
1263 return self._server.server_address[1] | 1322 return self._server.server_address[1] |
1264 | 1323 |
1265 | 1324 |
1266 if __name__ == '__main__': | 1325 if __name__ == '__main__': |
1267 pyauto_functional.Main() | 1326 pyauto_functional.Main() |
OLD | NEW |