OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 self._seen_graph_lines = {} | 83 self._seen_graph_lines = {} |
84 | 84 |
85 pyauto.PyUITest.setUp(self) | 85 pyauto.PyUITest.setUp(self) |
86 | 86 |
87 # Flush all buffers to disk and wait until system calms down. Must be done | 87 # Flush all buffers to disk and wait until system calms down. Must be done |
88 # *after* calling pyauto.PyUITest.setUp, since that is where Chrome is | 88 # *after* calling pyauto.PyUITest.setUp, since that is where Chrome is |
89 # killed and re-initialized for a new test. | 89 # killed and re-initialized for a new test. |
90 # TODO(dennisjeffrey): Implement wait for idle CPU on Windows/Mac. | 90 # TODO(dennisjeffrey): Implement wait for idle CPU on Windows/Mac. |
91 if self.IsLinux(): # IsLinux() also implies IsChromeOS(). | 91 if self.IsLinux(): # IsLinux() also implies IsChromeOS(). |
92 os.system('sync') | 92 os.system('sync') |
93 self._WaitForIdleCPU(60.0, 0.03) | 93 self._WaitForIdleCPU(60.0, 0.05) |
ilja
2012/04/25 19:50:23
Any reason you need to change this?
dennis_jeffrey
2012/04/25 21:31:58
Yes - I mentioned about it as one of the notes in
| |
94 | 94 |
95 def _WaitForIdleCPU(self, timeout, utilization): | 95 def _WaitForIdleCPU(self, timeout, utilization): |
96 """Waits for the CPU to become idle (< utilization). | 96 """Waits for the CPU to become idle (< utilization). |
97 | 97 |
98 Args: | 98 Args: |
99 timeout: The longest time in seconds to wait before throwing an error. | 99 timeout: The longest time in seconds to wait before throwing an error. |
100 utilization: The CPU usage below which the system should be considered | 100 utilization: The CPU usage below which the system should be considered |
101 idle (between 0 and 1.0 independent of cores/hyperthreads). | 101 idle (between 0 and 1.0 independent of cores/hyperthreads). |
102 """ | 102 """ |
103 time_passed = 0.0 | 103 time_passed = 0.0 |
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1758 def testIntl2File(self): | 1758 def testIntl2File(self): |
1759 self._RunPageCyclerTest('intl2', self._num_iterations, 'Intl2File') | 1759 self._RunPageCyclerTest('intl2', self._num_iterations, 'Intl2File') |
1760 | 1760 |
1761 def testMozFile(self): | 1761 def testMozFile(self): |
1762 self._RunPageCyclerTest('moz', self._num_iterations, 'MozFile') | 1762 self._RunPageCyclerTest('moz', self._num_iterations, 'MozFile') |
1763 | 1763 |
1764 def testMoz2File(self): | 1764 def testMoz2File(self): |
1765 self._RunPageCyclerTest('moz2', self._num_iterations, 'Moz2File') | 1765 self._RunPageCyclerTest('moz2', self._num_iterations, 'Moz2File') |
1766 | 1766 |
1767 | 1767 |
1768 class MemoryTest(BasePerfTest): | |
1769 """Tests to measure memory consumption under different usage scenarios.""" | |
1770 | |
1771 def setUp(self): | |
1772 pyauto.PyUITest.setUp(self) | |
1773 | |
1774 if self.GetLoginInfo()['is_logged_in']: | |
1775 self.Logout() | |
1776 self.assertFalse(self.GetLoginInfo()['is_logged_in'], | |
1777 msg='Failed to log out.') | |
1778 | |
1779 # Log in. | |
1780 credentials = self.GetPrivateInfo()['test_google_account'] | |
1781 self.Login(credentials['username'], credentials['password']) | |
1782 self.assertTrue(self.GetLoginInfo()['is_logged_in'], | |
1783 msg='Failed to log in.') | |
1784 | |
1785 def _GetMemoryStats(self): | |
1786 """Identifies and returns different kinds of current memory usage stats. | |
1787 | |
1788 Returns: | |
1789 A dictionary containing current memory usage information. All values are | |
1790 given in KB. | |
1791 { | |
1792 'gtt': GPU memory usage (graphics translation table), | |
1793 'mem_free': CPU free memory, | |
1794 } | |
1795 """ | |
1796 stats = {} | |
1797 | |
ilja
2012/04/25 19:50:23
I spoke with Stephane about your numbers. He think
dennis_jeffrey
2012/04/25 21:31:58
I was confused at first about exactly when you wan
| |
1798 # GPU memory. | |
1799 p = subprocess.Popen('grep bytes /sys/kernel/debug/dri/0/i915_gem_gtt', | |
1800 stdout=subprocess.PIPE, | |
1801 shell=True) | |
1802 stdout = p.communicate()[0] | |
1803 gtt_used = re.search('Total [\d]+ objects, ([\d]+) bytes', stdout).group(1) | |
1804 stats['gtt'] = int(gtt_used) / 1024.0 | |
1805 | |
1806 # CPU memory. | |
1807 stdout = '' | |
1808 with open('/proc/meminfo') as f: | |
1809 stdout = f.read() | |
1810 mem_free = re.search('MemFree:\s*([\d]+) kB', stdout).group(1) | |
James Cook
2012/04/25 19:15:56
I recommend using available memory as a stat, whic
ilja
2012/04/25 19:50:23
Lets track as James suggest AvailableMem instead o
dennis_jeffrey
2012/04/25 21:31:58
Sure, we can track this data. Puneet also said th
| |
1811 stats['mem_free'] = int(mem_free) | |
1812 | |
1813 return stats | |
1814 | |
1815 def _RecordMemoryStats(self, description, when): | |
1816 mem = self._GetMemoryStats() | |
1817 self._OutputPerfGraphValue('%s-GTT-%s' % (description, when), mem['gtt'], | |
1818 'KB', '%s-GTT' % description) | |
1819 self._OutputPerfGraphValue('%s-MemFree-%s' % (description, when), | |
1820 mem['mem_free'], 'KB', '%s-GTT' % description) | |
1821 | |
1822 def _RunTest(self, tabs, description): | |
1823 self._RecordMemoryStats(description, 'Start') | |
1824 | |
1825 for iteration_num in xrange(2): | |
1826 for site in tabs: | |
1827 self.AppendTab(pyauto.GURL(site)) | |
James Cook
2012/04/25 19:15:56
Depending on how realistic you want this to be, ve
ilja
2012/04/25 19:50:23
I think it does not. But maybe we don't need to wa
dennis_jeffrey
2012/04/25 21:31:58
AppendTab should return only when notified of the
| |
1828 | |
1829 self._RecordMemoryStats(description, 'Open%d' % (iteration_num + 1)) | |
1830 | |
1831 for _ in xrange(len(tabs)): | |
1832 self.GetBrowserWindow(0).GetTab(1).Close(True) | |
1833 | |
1834 self._RecordMemoryStats(description, 'Close%d' % (iteration_num + 1)) | |
1835 | |
1836 def testOpenCloseTabsControl(self): | |
1837 tabs = ['about:blank'] * 10 | |
1838 self._RunTest(tabs, 'MemControl') | |
1839 | |
1840 | |
1768 class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | 1841 class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): |
1769 """Request handler for the local performance test server.""" | 1842 """Request handler for the local performance test server.""" |
1770 | 1843 |
1771 def _IgnoreHandler(self, unused_args): | 1844 def _IgnoreHandler(self, unused_args): |
1772 """A GET request handler that simply replies with status code 200. | 1845 """A GET request handler that simply replies with status code 200. |
1773 | 1846 |
1774 Args: | 1847 Args: |
1775 unused_args: A dictionary of arguments for the current GET request. | 1848 unused_args: A dictionary of arguments for the current GET request. |
1776 The arguments are ignored. | 1849 The arguments are ignored. |
1777 """ | 1850 """ |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1990 """Identifies the port number to which the server is currently bound. | 2063 """Identifies the port number to which the server is currently bound. |
1991 | 2064 |
1992 Returns: | 2065 Returns: |
1993 The numeric port number to which the server is currently bound. | 2066 The numeric port number to which the server is currently bound. |
1994 """ | 2067 """ |
1995 return self._server.server_address[1] | 2068 return self._server.server_address[1] |
1996 | 2069 |
1997 | 2070 |
1998 if __name__ == '__main__': | 2071 if __name__ == '__main__': |
1999 pyauto_functional.Main() | 2072 pyauto_functional.Main() |
OLD | NEW |