OLD | NEW |
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 adb_profile_chrome import controllers | 10 from adb_profile_chrome import controllers |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 self._device.old_interface.SyncLogCat() | 61 self._device.old_interface.SyncLogCat() |
62 start_extras = {'categories': ','.join(self._categories)} | 62 start_extras = {'categories': ','.join(self._categories)} |
63 if self._ring_buffer: | 63 if self._ring_buffer: |
64 start_extras['continuous'] = None | 64 start_extras['continuous'] = None |
65 self._device.BroadcastIntent(intent.Intent( | 65 self._device.BroadcastIntent(intent.Intent( |
66 action='%s.GPU_PROFILER_START' % self._package_info.package, | 66 action='%s.GPU_PROFILER_START' % self._package_info.package, |
67 extras=start_extras)) | 67 extras=start_extras)) |
68 | 68 |
69 if self._trace_memory: | 69 if self._trace_memory: |
70 self._device.old_interface.EnableAdbRoot() | 70 self._device.old_interface.EnableAdbRoot() |
71 self._device.old_interface.system_properties \ | 71 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 1) |
72 [_HEAP_PROFILE_MMAP_PROPERTY] = 1 | |
73 | 72 |
74 # Chrome logs two different messages related to tracing: | 73 # Chrome logs two different messages related to tracing: |
75 # | 74 # |
76 # 1. "Logging performance trace to file" | 75 # 1. "Logging performance trace to file" |
77 # 2. "Profiler finished. Results are in [...]" | 76 # 2. "Profiler finished. Results are in [...]" |
78 # | 77 # |
79 # The first one is printed when tracing starts and the second one indicates | 78 # The first one is printed when tracing starts and the second one indicates |
80 # that the trace file is ready to be pulled. | 79 # that the trace file is ready to be pulled. |
81 try: | 80 try: |
82 self._device.old_interface.WaitForLogMatch( | 81 self._device.old_interface.WaitForLogMatch( |
83 self._trace_start_re, None, timeout=5) | 82 self._trace_start_re, None, timeout=5) |
84 except pexpect.TIMEOUT: | 83 except pexpect.TIMEOUT: |
85 raise RuntimeError('Trace start marker not found. Is the correct version ' | 84 raise RuntimeError('Trace start marker not found. Is the correct version ' |
86 'of the browser running?') | 85 'of the browser running?') |
87 | 86 |
88 def StopTracing(self): | 87 def StopTracing(self): |
89 self._device.BroadcastIntent(intent.Intent( | 88 self._device.BroadcastIntent(intent.Intent( |
90 action='%s.GPU_PROFILER_STOP' % self._package_info.package)) | 89 action='%s.GPU_PROFILER_STOP' % self._package_info.package)) |
91 self._trace_file = self._device.old_interface.WaitForLogMatch( | 90 self._trace_file = self._device.old_interface.WaitForLogMatch( |
92 self._trace_finish_re, None, timeout=120).group(1) | 91 self._trace_finish_re, None, timeout=120).group(1) |
93 if self._trace_memory: | 92 if self._trace_memory: |
94 self._device.old_interface.system_properties \ | 93 self._device.SetProp(_HEAP_PROFILE_MMAP_PROPERTY, 0) |
95 [_HEAP_PROFILE_MMAP_PROPERTY] = 0 | |
96 | 94 |
97 def PullTrace(self): | 95 def PullTrace(self): |
98 # 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. |
99 time.sleep(self._trace_interval / 4 + 1) | 97 time.sleep(self._trace_interval / 4 + 1) |
100 | 98 |
101 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') | 99 trace_file = self._trace_file.replace('/storage/emulated/0/', '/sdcard/') |
102 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)) |
103 self._device.PullFile(trace_file, host_file) | 101 self._device.PullFile(trace_file, host_file) |
104 return host_file | 102 return host_file |
OLD | NEW |