diff --git a/android/chrome_profiler/chrome_controller.py b/android/chrome_profiler/chrome_controller.py index 6c422f331..745e5d7df 100644 --- a/android/chrome_profiler/chrome_controller.py +++ b/android/chrome_profiler/chrome_controller.py @@ -11,9 +11,11 @@ from chrome_profiler import controllers from pylib import pexpect +_HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap' class ChromeTracingController(controllers.BaseController): - def __init__(self, device, package_info, categories, ring_buffer): + def __init__(self, device, package_info, + categories, ring_buffer, trace_memory=False): controllers.BaseController.__init__(self) self._device = device self._package_info = package_info @@ -21,6 +23,7 @@ class ChromeTracingController(controllers.BaseController): self._ring_buffer = ring_buffer self._trace_file = None self._trace_interval = None + self._trace_memory = trace_memory self._trace_start_re = \ re.compile(r'Logging performance trace to file') self._trace_finish_re = \ @@ -59,6 +62,12 @@ class ChromeTracingController(controllers.BaseController): self._package_info.package, 'GPU_PROFILER_START', '-e categories "%s"' % ','.join(self._categories), '-e continuous' if self._ring_buffer else '') + + if self._trace_memory: + self._device.old_interface.EnableAdbRoot() + self._device.old_interface.system_properties \ + [_HEAP_PROFILE_MMAP_PROPERTY] = 1 + # Chrome logs two different messages related to tracing: # # 1. "Logging performance trace to file" @@ -79,6 +88,9 @@ class ChromeTracingController(controllers.BaseController): 'GPU_PROFILER_STOP') self._trace_file = self._device.old_interface.WaitForLogMatch( self._trace_finish_re, None, timeout=120).group(1) + if self._trace_memory: + self._device.old_interface.system_properties \ + [_HEAP_PROFILE_MMAP_PROPERTY] = 0 def PullTrace(self): # Wait a bit for the browser to finish writing the trace file. diff --git a/android/chrome_profiler/main.py b/android/chrome_profiler/main.py index e3435d17f..401115fb5 100755 --- a/android/chrome_profiler/main.py +++ b/android/chrome_profiler/main.py @@ -32,6 +32,8 @@ def _ComputeChromeCategories(options): categories.append('disabled-by-default-gpu.debug*') if options.trace_flow: categories.append('disabled-by-default-toplevel.flow') + if options.trace_memory: + categories.append('disabled-by-default-memory') if options.chrome_categories: categories += options.chrome_categories.split(',') return categories @@ -87,6 +89,9 @@ def _CreateOptionParser(): 'for GPU data.', action='store_true') chrome_opts.add_option('--trace-flow', help='Enable extra trace categories ' 'for IPC message flows.', action='store_true') + chrome_opts.add_option('--trace-memory', help='Enable extra trace categories ' + 'for memory profile. (tcmalloc required)', + action='store_true') parser.add_option_group(chrome_opts) systrace_opts = optparse.OptionGroup(parser, 'Systrace tracing options') @@ -181,7 +186,8 @@ When in doubt, just try out --trace-frame-viewer. chrome_controller.ChromeTracingController(device, package_info, chrome_categories, - options.ring_buffer)) + options.ring_buffer, + options.trace_memory)) if systrace_categories: enabled_controllers.append( systrace_controller.SystraceController(device,