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

Side by Side Diff: build/android/chrome_profiler/chrome_controller.py

Issue 291723002: Add --trace-memory option for tracing heap memory (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 unified diff | Download patch
« no previous file with comments | « no previous file | build/android/chrome_profiler/main.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import json 5 import json
6 import os 6 import os
7 import re 7 import re
8 import time 8 import time
9 9
10 from chrome_profiler import controllers 10 from chrome_profiler import controllers
11 11
12 from pylib import pexpect 12 from pylib import pexpect
13 13
14 _HEAP_PROFILE_MMAP_PROPERTY = 'heapprof.mmap'
14 15
15 class ChromeTracingController(controllers.BaseController): 16 class ChromeTracingController(controllers.BaseController):
16 def __init__(self, device, package_info, categories, ring_buffer): 17 def __init__(self, device, package_info,
18 categories, ring_buffer, trace_memory):
Sami 2014/05/27 16:32:36 Could you make this "trace_memory=False" to avoid
17 controllers.BaseController.__init__(self) 19 controllers.BaseController.__init__(self)
18 self._device = device 20 self._device = device
19 self._package_info = package_info 21 self._package_info = package_info
20 self._categories = categories 22 self._categories = categories
21 self._ring_buffer = ring_buffer 23 self._ring_buffer = ring_buffer
22 self._trace_file = None 24 self._trace_file = None
23 self._trace_interval = None 25 self._trace_interval = None
26 self._trace_memory = trace_memory
24 self._trace_start_re = \ 27 self._trace_start_re = \
25 re.compile(r'Logging performance trace to file') 28 re.compile(r'Logging performance trace to file')
26 self._trace_finish_re = \ 29 self._trace_finish_re = \
27 re.compile(r'Profiler finished[.] Results are in (.*)[.]') 30 re.compile(r'Profiler finished[.] Results are in (.*)[.]')
28 self._device.old_interface.StartMonitoringLogcat(clear=False) 31 self._device.old_interface.StartMonitoringLogcat(clear=False)
29 32
30 def __repr__(self): 33 def __repr__(self):
31 return 'chrome trace' 34 return 'chrome trace'
32 35
33 @staticmethod 36 @staticmethod
(...skipping 18 matching lines...) Expand all
52 55
53 return record_categories, disabled_by_default_categories 56 return record_categories, disabled_by_default_categories
54 57
55 def StartTracing(self, interval): 58 def StartTracing(self, interval):
56 self._trace_interval = interval 59 self._trace_interval = interval
57 self._device.old_interface.SyncLogCat() 60 self._device.old_interface.SyncLogCat()
58 self._device.old_interface.BroadcastIntent( 61 self._device.old_interface.BroadcastIntent(
59 self._package_info.package, 'GPU_PROFILER_START', 62 self._package_info.package, 'GPU_PROFILER_START',
60 '-e categories "%s"' % ','.join(self._categories), 63 '-e categories "%s"' % ','.join(self._categories),
61 '-e continuous' if self._ring_buffer else '') 64 '-e continuous' if self._ring_buffer else '')
65
66 if self._trace_memory:
67 self._device.old_interface.EnableAdbRoot()
68 self._device.old_interface.system_properties \
69 [_HEAP_PROFILE_MMAP_PROPERTY] = 1
70
62 # Chrome logs two different messages related to tracing: 71 # Chrome logs two different messages related to tracing:
63 # 72 #
64 # 1. "Logging performance trace to file" 73 # 1. "Logging performance trace to file"
65 # 2. "Profiler finished. Results are in [...]" 74 # 2. "Profiler finished. Results are in [...]"
66 # 75 #
67 # The first one is printed when tracing starts and the second one indicates 76 # The first one is printed when tracing starts and the second one indicates
68 # that the trace file is ready to be pulled. 77 # that the trace file is ready to be pulled.
69 try: 78 try:
70 self._device.old_interface.WaitForLogMatch( 79 self._device.old_interface.WaitForLogMatch(
71 self._trace_start_re, None, timeout=5) 80 self._trace_start_re, None, timeout=5)
72 except pexpect.TIMEOUT: 81 except pexpect.TIMEOUT:
73 raise RuntimeError('Trace start marker not found. Is the correct version ' 82 raise RuntimeError('Trace start marker not found. Is the correct version '
74 'of the browser running?') 83 'of the browser running?')
75 84
76 def StopTracing(self): 85 def StopTracing(self):
77 self._device.old_interface.BroadcastIntent( 86 self._device.old_interface.BroadcastIntent(
78 self._package_info.package, 87 self._package_info.package,
79 'GPU_PROFILER_STOP') 88 'GPU_PROFILER_STOP')
80 self._trace_file = self._device.old_interface.WaitForLogMatch( 89 self._trace_file = self._device.old_interface.WaitForLogMatch(
81 self._trace_finish_re, None, timeout=120).group(1) 90 self._trace_finish_re, None, timeout=120).group(1)
91 if self._trace_memory:
92 self._device.old_interface.system_properties \
93 [_HEAP_PROFILE_MMAP_PROPERTY] = 0
82 94
83 def PullTrace(self): 95 def PullTrace(self):
84 # Wait a bit for the browser to finish writing the trace file. 96 # Wait a bit for the browser to finish writing the trace file.
85 time.sleep(self._trace_interval / 4 + 1) 97 time.sleep(self._trace_interval / 4 + 1)
86 98
87 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') 99 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/')
88 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file)) 100 host_file = os.path.join(os.path.curdir, os.path.basename(trace_file))
89 self._device.old_interface.PullFileFromDevice(trace_file, host_file) 101 self._device.old_interface.PullFileFromDevice(trace_file, host_file)
90 return host_file 102 return host_file
OLDNEW
« no previous file with comments | « no previous file | build/android/chrome_profiler/main.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698