Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(147)

Unified Diff: chrome/test/functional/perf.py

Issue 10161033: Adding pyauto-based memory usage tests for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments from patch set 4. Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/test/functional/perf.py
diff --git a/chrome/test/functional/perf.py b/chrome/test/functional/perf.py
index 174f73131618b659a1e2bb39407460cda8360210..6d909ab27e5426b011b2139fcdc0a05f7729eeed 100755
--- a/chrome/test/functional/perf.py
+++ b/chrome/test/functional/perf.py
@@ -90,7 +90,7 @@ class BasePerfTest(pyauto.PyUITest):
# TODO(dennisjeffrey): Implement wait for idle CPU on Windows/Mac.
if self.IsLinux(): # IsLinux() also implies IsChromeOS().
os.system('sync')
- self._WaitForIdleCPU(60.0, 0.03)
+ self._WaitForIdleCPU(60.0, 0.05)
def _WaitForIdleCPU(self, timeout, utilization):
"""Waits for the CPU to become idle (< utilization).
@@ -1765,6 +1765,160 @@ class PageCyclerTest(BasePerfTest):
self._RunPageCyclerTest('moz2', self._num_iterations, 'Moz2File')
+class MemoryTest(BasePerfTest):
+ """Tests to measure memory consumption under different usage scenarios."""
+
+ def setUp(self):
+ pyauto.PyUITest.setUp(self)
+
+ # Log in to get a fresh Chrome instance with a clean memory state (if
+ # already logged in, log out first).
+ if self.GetLoginInfo()['is_logged_in']:
+ self.Logout()
+ self.assertFalse(self.GetLoginInfo()['is_logged_in'],
+ msg='Failed to log out.')
+
+ credentials = self.GetPrivateInfo()['test_google_account']
+ self.Login(credentials['username'], credentials['password'])
+ self.assertTrue(self.GetLoginInfo()['is_logged_in'],
+ msg='Failed to log in.')
+
+ def _GetMemoryStats(self, duration):
+ """Identifies and returns different kinds of current memory usage stats.
+
+ This function samples values each second for |duration| seconds, then
+ outputs the min, max, and ending values for each measurement type.
+
+ Args:
+ duration: The number of seconds to sample data before outputting the
+ minimum, maximum, and ending values for each measurement type.
+
+ Returns:
+ A dictionary containing memory usage information. Each measurement type
+ is associated with the min, max, and ending values from among all
+ sampled values. Values are specified in KB.
+ {
+ 'gtt': { # GPU memory usage (graphics translation table)
+ 'min': ...,
+ 'max': ...,
+ 'end': ...,
+ },
+ 'mem_available': { ... }, # CPU available memory
+ 'mem_shared': { ... }, # CPU shared memory
+ }
+ """
+ logging.debug('Sampling memory information for %d seconds...' % duration)
+ stats = {
+ 'gtt': [],
+ 'mem_available': [],
+ 'mem_shared': [],
+ }
+
+ for _ in xrange(duration):
+ p = subprocess.Popen('grep bytes /sys/kernel/debug/dri/0/i915_gem_gtt',
Sonny 2012/04/26 04:55:18 GTT isn't guaranteed to always be there. It'll on
ihf 2012/04/26 05:19:17 Good catch on the checking for file existence.
dennis_jeffrey 2012/04/26 18:47:39 I modified the code to exclude GTT values if the f
+ stdout=subprocess.PIPE,
+ shell=True)
+ stdout = p.communicate()[0]
+
+ # GPU memory.
+ gtt_used = re.search(
+ 'Total [\d]+ objects, ([\d]+) bytes', stdout).group(1)
+ stats['gtt'].append(int(gtt_used) / 1024.0)
+
+ # CPU memory.
+ stdout = ''
+ with open('/proc/meminfo') as f:
+ stdout = f.read()
+ mem_free = re.search('MemFree:\s*([\d]+) kB', stdout).group(1)
+ mem_dirty = re.search('Dirty:\s*([\d]+) kB', stdout).group(1)
Sonny 2012/04/26 04:55:18 Dirty Memory isn't really very interesting becaus
Sonny 2012/04/26 05:38:14 Now that I understand what mem_available is suppos
dennis_jeffrey 2012/04/26 18:47:39 See my comment at line 1846 below.
+ mem_active_file = re.search(
+ 'Active\(file\):\s*([\d]+) kB', stdout).group(1)
+ mem_inactive_file = re.search(
+ 'Inactive\(file\):\s*([\d]+) kB', stdout).group(1)
+ stats['mem_available'].append(
+ (int(mem_active_file) + int(mem_inactive_file)) - int(mem_dirty) +
+ int(mem_free))
Sonny 2012/04/26 04:55:18 I'm not sure what mem_available is supposed to mea
ihf 2012/04/26 05:19:17 This was suggested by James as it is used for disc
James Cook 2012/04/26 05:25:59 It's apparently what Luigi uses in the kernel to p
Sonny 2012/04/26 05:38:14 Ah.. I see. That's not actually exactly true eith
dennis_jeffrey 2012/04/26 18:47:39 Let me know how the computation for available memo
Sonny 2012/04/26 22:25:40 so it should be MemFree + Inactive file + active f
dennis_jeffrey 2012/04/28 00:21:35 Done.
+
+ mem_shared = re.search('Shmem:\s*([\d]+) kB', stdout).group(1)
+ stats['mem_shared'].append(int(mem_shared))
+
+ time.sleep(1)
+
Sonny 2012/04/26 04:55:18 Also weren't we going to get the memory stats from
ihf 2012/04/26 05:19:17 First time I read about it.
Sonny 2012/04/26 05:38:14 we want the private and shared and possibly the ja
dennis_jeffrey 2012/04/26 18:47:39 Yes, there is lots more information that people wa
Sonny 2012/04/26 22:25:40 Ok... I just feel like we'll be adding more stuff
dennis_jeffrey 2012/04/28 00:21:35 We're now recording more different types of memory
+ # Compute min, max, and ending values to return.
+ result = {}
+ for measurement_type in stats:
+ values = stats[measurement_type]
+ result[measurement_type] = {
+ 'min': min(values),
+ 'max': max(values),
+ 'end': values[-1],
+ }
+
+ return result
+
+ def _RecordMemoryStats(self, description, when, duration):
+ """Outputs memory statistics to be graphed.
+
+ Args:
+ description: A string description for the test. Should not contain
+ spaces. For example, 'MemCtrl'.
+ when: A string description of when the memory stats are being recorded
+ during test execution (since memory stats may be recorded multiple
+ times during a test execution at certain "interesting" times). Should
+ not contain spaces.
+ duration: The number of seconds to sample data before outputting the
+ memory statistics.
+ """
+ mem = self._GetMemoryStats(duration)
+ measurement_types = [
+ ('gtt', 'GTT'),
+ ('mem_available', 'MemAvail'),
+ ('mem_shared', 'MemShare'),
+ ]
+ for type_key, type_string in measurement_types:
+ self._OutputPerfGraphValue(
+ '%s-Min%s-%s' % (description, type_string, when),
+ mem[type_key]['min'], 'KB', '%s-%s' % (description, type_string))
+ self._OutputPerfGraphValue(
+ '%s-Max%s-%s' % (description, type_string, when),
+ mem[type_key]['max'], 'KB', '%s-%s' % (description, type_string))
+ self._OutputPerfGraphValue(
+ '%s-End%s-%s' % (description, type_string, when),
+ mem[type_key]['end'], 'KB', '%s-%s' % (description, type_string))
+
+ def _RunTest(self, tabs, description, duration):
+ """Runs a general memory test.
+
+ Args:
+ tabs: A list of strings representing the URLs of the websites to open
+ during this test.
+ description: A string description for the test. Should not contain
+ spaces. For example, 'MemCtrl'.
+ duration: The number of seconds to sample data before outputting memory
+ statistics.
+ """
+ self._RecordMemoryStats(description, '0Tabs0', duration)
+
+ for iteration_num in xrange(2):
+ for site in tabs:
+ self.AppendTab(pyauto.GURL(site))
+
+ self._RecordMemoryStats(description,
+ '%dTabs%d' % (len(tabs), iteration_num + 1),
+ duration)
Sonny 2012/04/26 04:55:18 I'm not sure we want to record after opening every
ihf 2012/04/26 05:19:17 This works exactly as you want it.
Sonny 2012/04/26 05:38:14 Ahh oops, didn't see the indent, thanks.
dennis_jeffrey 2012/04/26 18:47:39 Done - working as intended.
+
+ for _ in xrange(len(tabs)):
+ self.GetBrowserWindow(0).GetTab(1).Close(True)
+
+ self._RecordMemoryStats(description, '0Tabs%d' % (iteration_num + 1),
+ duration)
+
+ def testOpenCloseTabsControl(self):
+ """Measures memory usage when opening/closing tabs to about:blank."""
+ tabs = ['about:blank'] * 10
+ self._RunTest(tabs, 'MemCtrl', 15)
+
+
class PerfTestServerRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
"""Request handler for the local performance test server."""
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698