| 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 """Android-specific implementation of the core backend interfaces. | 5 """Android-specific implementation of the core backend interfaces. |
| 6 | 6 |
| 7 See core/backends.py for more docs. | 7 See core/backends.py for more docs. |
| 8 """ | 8 """ |
| 9 | 9 |
| 10 import datetime | 10 import datetime |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 | 159 |
| 160 _SETTINGS_KEYS = { | 160 _SETTINGS_KEYS = { |
| 161 'native_symbol_paths': 'Semicolon-sep. list of native libs search path'} | 161 'native_symbol_paths': 'Semicolon-sep. list of native libs search path'} |
| 162 | 162 |
| 163 def __init__(self, backend, underlying_device): | 163 def __init__(self, backend, underlying_device): |
| 164 super(AndroidDevice, self).__init__( | 164 super(AndroidDevice, self).__init__( |
| 165 backend=backend, | 165 backend=backend, |
| 166 settings=backends.Settings(AndroidDevice._SETTINGS_KEYS)) | 166 settings=backends.Settings(AndroidDevice._SETTINGS_KEYS)) |
| 167 self.underlying_device = underlying_device | 167 self.underlying_device = underlying_device |
| 168 self._id = underlying_device.old_interface.GetDevice() | 168 self._id = underlying_device.old_interface.GetDevice() |
| 169 self._name = underlying_device.old_interface.GetProductModel() | 169 self._name = underlying_device.GetProp('ro.product.model') |
| 170 self._sys_stats = None | 170 self._sys_stats = None |
| 171 self._last_device_stats = None | 171 self._last_device_stats = None |
| 172 self._sys_stats_last_update = None | 172 self._sys_stats_last_update = None |
| 173 self._processes = {} # pid (int) -> |Process| | 173 self._processes = {} # pid (int) -> |Process| |
| 174 self._initialized = False | 174 self._initialized = False |
| 175 | 175 |
| 176 def Initialize(self): | 176 def Initialize(self): |
| 177 """Starts adb root and deploys the prebuilt binaries on initialization.""" | 177 """Starts adb root and deploys the prebuilt binaries on initialization.""" |
| 178 try: | 178 try: |
| 179 self.underlying_device.EnableRoot() | 179 self.underlying_device.EnableRoot() |
| 180 except device_errors.CommandFailedError as e: | 180 except device_errors.CommandFailedError as e: |
| 181 # Try to deploy memdump and ps_ext anyway. | 181 # Try to deploy memdump and ps_ext anyway. |
| 182 # TODO(jbudorick) Handle this exception appropriately after interface | 182 # TODO(jbudorick) Handle this exception appropriately after interface |
| 183 # conversions are finished. | 183 # conversions are finished. |
| 184 logging.error(str(e)) | 184 logging.error(str(e)) |
| 185 | 185 |
| 186 # Download (from GCS) and deploy prebuilt helper binaries on the device. | 186 # Download (from GCS) and deploy prebuilt helper binaries on the device. |
| 187 self._DeployPrebuiltOnDeviceIfNeeded(_MEMDUMP_PREBUILT_PATH, | 187 self._DeployPrebuiltOnDeviceIfNeeded(_MEMDUMP_PREBUILT_PATH, |
| 188 _MEMDUMP_PATH_ON_DEVICE) | 188 _MEMDUMP_PATH_ON_DEVICE) |
| 189 self._DeployPrebuiltOnDeviceIfNeeded(_PSEXT_PREBUILT_PATH, | 189 self._DeployPrebuiltOnDeviceIfNeeded(_PSEXT_PREBUILT_PATH, |
| 190 _PSEXT_PATH_ON_DEVICE) | 190 _PSEXT_PATH_ON_DEVICE) |
| 191 self._initialized = True | 191 self._initialized = True |
| 192 | 192 |
| 193 def IsNativeTracingEnabled(self): | 193 def IsNativeTracingEnabled(self): |
| 194 """Checks for the libc.debug.malloc system property.""" | 194 """Checks for the libc.debug.malloc system property.""" |
| 195 return bool(self.underlying_device.old_interface.system_properties[ | 195 return bool(self.underlying_device.GetProp( |
| 196 _DLMALLOC_DEBUG_SYSPROP]) | 196 _DLMALLOC_DEBUG_SYSPROP)) |
| 197 | 197 |
| 198 def EnableNativeTracing(self, enabled): | 198 def EnableNativeTracing(self, enabled): |
| 199 """Enables libc.debug.malloc and restarts the shell.""" | 199 """Enables libc.debug.malloc and restarts the shell.""" |
| 200 assert(self._initialized) | 200 assert(self._initialized) |
| 201 prop_value = '1' if enabled else '' | 201 prop_value = '1' if enabled else '' |
| 202 self.underlying_device.old_interface.system_properties[ | 202 self.underlying_device.SetProp(_DLMALLOC_DEBUG_SYSPROP, prop_value) |
| 203 _DLMALLOC_DEBUG_SYSPROP] = prop_value | |
| 204 assert(self.IsNativeTracingEnabled()) | 203 assert(self.IsNativeTracingEnabled()) |
| 205 # The libc.debug property takes effect only after restarting the Zygote. | 204 # The libc.debug property takes effect only after restarting the Zygote. |
| 206 self.underlying_device.old_interface.RestartShell() | 205 self.underlying_device.old_interface.RestartShell() |
| 207 | 206 |
| 208 def ListProcesses(self): | 207 def ListProcesses(self): |
| 209 """Returns a sequence of |AndroidProcess|.""" | 208 """Returns a sequence of |AndroidProcess|.""" |
| 210 self._RefreshProcessesList() | 209 self._RefreshProcessesList() |
| 211 return self._processes.itervalues() | 210 return self._processes.itervalues() |
| 212 | 211 |
| 213 def GetProcess(self, pid): | 212 def GetProcess(self, pid): |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 proc_stats = backends.ProcessStats( | 354 proc_stats = backends.ProcessStats( |
| 356 threads=cur_proc_stats['n_threads'], | 355 threads=cur_proc_stats['n_threads'], |
| 357 run_time=run_time, | 356 run_time=run_time, |
| 358 cpu_usage=cpu_usage, | 357 cpu_usage=cpu_usage, |
| 359 vm_rss=cur_proc_stats['vm_rss'], | 358 vm_rss=cur_proc_stats['vm_rss'], |
| 360 page_faults=( | 359 page_faults=( |
| 361 (cur_proc_stats['maj_faults'] + cur_proc_stats['min_faults']) - | 360 (cur_proc_stats['maj_faults'] + cur_proc_stats['min_faults']) - |
| 362 (old_proc_stats['maj_faults'] + old_proc_stats['min_faults']))) | 361 (old_proc_stats['maj_faults'] + old_proc_stats['min_faults']))) |
| 363 self._last_sys_stats = cur_sys_stats | 362 self._last_sys_stats = cur_sys_stats |
| 364 return proc_stats | 363 return proc_stats |
| OLD | NEW |