diff options
author | ihf@chromium.org <ihf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 02:25:37 +0000 |
---|---|---|
committer | ihf@chromium.org <ihf@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-28 02:25:37 +0000 |
commit | 05c60f81aea4bc69b267bbe0135c3c2c6391a76b (patch) | |
tree | 63509f9d110bb7f91600bd213515b19d171d3bde | |
parent | d893b3d22f95b02b6142693eb09c6161c7cadf79 (diff) | |
download | chromium_src-05c60f81aea4bc69b267bbe0135c3c2c6391a76b.zip chromium_src-05c60f81aea4bc69b267bbe0135c3c2c6391a76b.tar.gz chromium_src-05c60f81aea4bc69b267bbe0135c3c2c6391a76b.tar.bz2 |
pyauto perf tests: Flush all buffers to disk between tests
and check that the CPU is idle before continuing.
Review URL: http://codereview.chromium.org/9271066
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@119563 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-x | chrome/test/functional/perf.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/chrome/test/functional/perf.py b/chrome/test/functional/perf.py index ac20d32..1066204 100755 --- a/chrome/test/functional/perf.py +++ b/chrome/test/functional/perf.py @@ -32,6 +32,7 @@ import re import SimpleHTTPServer import simplejson import SocketServer +import subprocess import sys import tempfile import threading @@ -81,9 +82,56 @@ class BasePerfTest(pyauto.PyUITest): # variable lets us know whether a perf measurement is for a new test # execution, or the current test execution. self._seen_graph_lines = {} + # Flush all buffers to disk and wait until system calms down. + if self.IsLinux() or self.IsMac() or self.IsChromeOS(): + os.system('sync') + self._WaitForIdleCPU(60.0, 0.03) pyauto.PyUITest.setUp(self) + def _WaitForIdleCPU(self, timeout, utilization): + """Waits for the CPU to become idle (< utilization). + + Args: + timeout: The longest time in seconds to wait before throwing an error. + utilization: The CPU usage below which the system should be considered + idle (between 0 and 1.0 independent of cores/hyperthreads). + """ + time_passed = 0.0 + fraction_non_idle_time = 1.0 + logging.info('Starting to wait up to %fs for idle CPU...' % timeout) + while fraction_non_idle_time >= utilization: + cpu_usage_start = self._GetCPUUsage() + time.sleep(2) + time_passed += 2.0 + cpu_usage_end = self._GetCPUUsage() + fraction_non_idle_time = \ + self._GetFractionNonIdleCPUTime(cpu_usage_start, cpu_usage_end) + logging.info('Current CPU utilization = %f.' % fraction_non_idle_time) + if time_passed > timeout: + self._LogProcessActivity() + self.fail('CPU did not idle after %fs wait (utilization = %f).' + % (time_passed, fraction_non_idle_time)) + logging.info('Wait for idle CPU took %fs (utilization = %f).' + % (time_passed, fraction_non_idle_time)) + + def _LogProcessActivity(self): + """Logs the output of top on Linux/Mac/CrOS. + + TODO: use taskmgr or similar on Windows. + """ + if self.IsLinux() or self.IsMac() or self.IsChromeOS(): + logging.info('Logging current process activity using top.') + cmd = 'top -b -d1 -n1' + if self.IsMac(): + cmd = 'top -l1' + p = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) + output = p.stdout.read() + logging.info(output) + else: + logging.info('Process activity logging not implemented on this OS.') + def _AppendTab(self, url): """Appends a tab and increments a counter if the automation call times out. |