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

Unified Diff: tools/telemetry/telemetry/core/platform/profiler/tcmalloc_profiler.py

Issue 15093008: Telemetry: integrates memory_measurement with TCMalloc dumps (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments Created 7 years, 7 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
Index: tools/telemetry/telemetry/core/platform/profiler/tcmalloc_profiler.py
diff --git a/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_profiler.py b/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_profiler.py
new file mode 100644
index 0000000000000000000000000000000000000000..fd47502e0a81d613141aab58598d7e1fec31997c
--- /dev/null
+++ b/tools/telemetry/telemetry/core/platform/profiler/tcmalloc_profiler.py
@@ -0,0 +1,125 @@
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import sys
+
+from telemetry.core.chrome import adb_commands
+from telemetry.core.platform import profiler
+
+# Enviroment variables to (android properties, default value) mapping.
+_ENV_VARIABLES = {
+ 'HEAP_PROFILE_TIME_INTERVAL': ('heapprof.time_interval', 20),
+ 'HEAP_PROFILE_MMAP': ('heapprof.mmap', 1),
+ 'DEEP_HEAP_PROFILE': ('heapprof.deep_heap_profile', 1),
+}
+
+class _TCMallocProfilerAndroid(profiler.Profiler):
+ """An internal class to set android properties and fetch dumps from device."""
+
+ _DEFAULT_DEVICE_DIR = '/data/local/tmp/heap/'
+
+ def __init__(self, browser_backend, _, output_path):
+ super(_TCMallocProfilerAndroid, self).__init__(output_path)
+ self._browser_backend = browser_backend
+
+ properties = dict(_ENV_VARIABLES)
+ properties['HEAPPROFILE'] = ('heapprof',
+ self._DEFAULT_DEVICE_DIR + 'dmprof')
+
+ self._SetDeviceProperties(self._browser_backend.options.android_device,
+ properties)
+
+ def _SetDeviceProperties(self, android_device, properties):
+ adb = adb_commands.AdbCommands(android_device)
+ has_set_property = False
+ for values in properties.itervalues():
+ device_property = adb.RunShellCommand('getprop ' + values[0])
+ if (not device_property or len(device_property) != 1 or
+ not device_property[0].strip()):
+ print 'Setting device property ', values[0], values[1]
+ adb.RunShellCommand('setprop ' + values[0] + ' ' + str(values[1]))
+ has_set_property = True
+ if has_set_property:
+ raise Exception('New device properties were set, run again.')
+ adb.RunShellCommand('rm -rf ' + self._DEFAULT_DEVICE_DIR)
+ adb.RunShellCommand('mkdir -p ' + self._DEFAULT_DEVICE_DIR)
+ adb.RunShellCommand('chmod 777 ' + self._DEFAULT_DEVICE_DIR)
+
+ @classmethod
+ def name(cls):
+ return 'tcmalloc'
+
+ @classmethod
+ def is_supported(cls, options):
+ return True
+
+ def CollectProfile(self):
+ print 'TCMalloc dumps available in the device ', self._DEFAULT_DEVICE_DIR
+ adb = adb_commands.AdbCommands(self._browser_backend.options.android_device)
+ adb.Adb().Adb().Pull(self._DEFAULT_DEVICE_DIR, self.output_path)
+ print 'TCMalloc dumps pulled to ', self.output_path
+
+
+class _TCMallocProfilerLinux(profiler.Profiler):
+ """An internal class to set environment variables and fetch dumps."""
+
+ _DEFAULT_DIR = '/tmp/tcmalloc/'
+
+ def __init__(self, browser_backend, _, output_path):
+ super(_TCMallocProfilerLinux, self).__init__(output_path)
+ self._browser_backend = browser_backend
+
+ env_vars = dict(_ENV_VARIABLES)
+ env_vars['HEAPPROFILE'] = ('heapprof', self._DEFAULT_DIR + 'dmp')
Dai Mikurube (NOT FULLTIME) 2013/05/14 15:07:07 also 'dmprof'
bulach 2013/05/14 15:34:17 Done.
+ self._CheckEnvironmentVariables(env_vars)
+
+ def _CheckEnvironmentVariables(self, env_vars):
+ msg = ''
+ for key, values in env_vars.iteritems():
+ if key not in os.environ:
+ msg += '%s=%s ' % (key, str(values[1]))
+ if msg:
+ raise Exception('Need enviroment variables, try again with:\n %s' % msg)
+ if not os.path.exists(os.environ['HEAPPROFILE']):
+ os.makedirs(os.environ['HEAPPROFILE'])
+
+ @classmethod
+ def name(cls):
+ return 'tcmalloc'
+
+ @classmethod
+ def is_supported(cls, options):
+ return True
+
+ def CollectProfile(self):
+ print 'TCMalloc dumps available ', os.environ['HEAPPROFILE']
+
+
+class TCMallocProfilerFactory(profiler.Profiler):
Dai Mikurube (NOT FULLTIME) 2013/05/14 15:07:07 Maybe it's a delegate or a proxy rather than a fac
bulach 2013/05/14 15:34:17 hmm... it's a factory in the sense that it creates
Dai Mikurube (NOT FULLTIME) 2013/05/14 17:02:10 Looks good!
+ """A Factory to instantiate the platform-specific profiler."""
+ def __init__(self, browser_backend, _, output_path):
+ super(TCMallocProfilerFactory, self).__init__(output_path)
+ self._browser_backend = browser_backend
+ if self._browser_backend.options.browser_type.startswith('android'):
+ self._platform_profiler = _TCMallocProfilerAndroid(
+ browser_backend, _, output_path)
+ else:
+ self._platform_profiler = _TCMallocProfilerLinux(
+ browser_backend, _, output_path)
+
+ @classmethod
+ def name(cls):
+ return 'tcmalloc'
+
+ @classmethod
+ def is_supported(cls, options):
+ if (sys.platform != 'linux2'):
+ return False
+ if options.browser_type.startswith('android'):
+ return _TCMallocProfilerAndroid.is_supported(options)
+ return _TCMallocProfilerLinux.is_supported(options)
+
+ def CollectProfile(self):
+ self._platform_profiler.CollectProfile()

Powered by Google App Engine
This is Rietveld 408576698