| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 logging | 5 import logging |
| 6 import os | 6 import os |
| 7 import posixpath | 7 import posixpath |
| 8 import re | 8 import re |
| 9 import subprocess | 9 import subprocess |
| 10 import tempfile | 10 import tempfile |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 try: | 87 try: |
| 88 self._device.EnableRoot() | 88 self._device.EnableRoot() |
| 89 except device_errors.CommandFailedError: | 89 except device_errors.CommandFailedError: |
| 90 logging.warning('Unable to root %s', str(self._device)) | 90 logging.warning('Unable to root %s', str(self._device)) |
| 91 self._battery = battery_utils.BatteryUtils(self._device) | 91 self._battery = battery_utils.BatteryUtils(self._device) |
| 92 self._enable_performance_mode = device.enable_performance_mode | 92 self._enable_performance_mode = device.enable_performance_mode |
| 93 self._surface_stats_collector = None | 93 self._surface_stats_collector = None |
| 94 self._perf_tests_setup = perf_control.PerfControl(self._device) | 94 self._perf_tests_setup = perf_control.PerfControl(self._device) |
| 95 self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device) | 95 self._thermal_throttle = thermal_throttle.ThermalThrottle(self._device) |
| 96 self._raw_display_frame_rate_measurements = [] | 96 self._raw_display_frame_rate_measurements = [] |
| 97 self._can_access_protected_file_contents = ( | 97 self._can_elevate_privilege = ( |
| 98 self._device.HasRoot() or self._device.NeedsSU()) | 98 self._device.HasRoot() or self._device.NeedsSU()) |
| 99 self._device_copy_script = None | 99 self._device_copy_script = None |
| 100 self._power_monitor = ( | 100 self._power_monitor = ( |
| 101 android_power_monitor_controller.AndroidPowerMonitorController([ | 101 android_power_monitor_controller.AndroidPowerMonitorController([ |
| 102 android_temperature_monitor.AndroidTemperatureMonitor(self._device), | 102 android_temperature_monitor.AndroidTemperatureMonitor(self._device), |
| 103 monsoon_power_monitor.MonsoonPowerMonitor(self._device, self), | 103 monsoon_power_monitor.MonsoonPowerMonitor(self._device, self), |
| 104 android_dumpsys_power_monitor.DumpsysPowerMonitor( | 104 android_dumpsys_power_monitor.DumpsysPowerMonitor( |
| 105 self._battery, self), | 105 self._battery, self), |
| 106 sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True), | 106 sysfs_power_monitor.SysfsPowerMonitor(self, standalone=True), |
| 107 android_fuelgauge_power_monitor.FuelGaugePowerMonitor( | 107 android_fuelgauge_power_monitor.FuelGaugePowerMonitor( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 def CanMonitorThermalThrottling(self): | 207 def CanMonitorThermalThrottling(self): |
| 208 return True | 208 return True |
| 209 | 209 |
| 210 def IsThermallyThrottled(self): | 210 def IsThermallyThrottled(self): |
| 211 return self._thermal_throttle.IsThrottled() | 211 return self._thermal_throttle.IsThrottled() |
| 212 | 212 |
| 213 def HasBeenThermallyThrottled(self): | 213 def HasBeenThermallyThrottled(self): |
| 214 return self._thermal_throttle.HasBeenThrottled() | 214 return self._thermal_throttle.HasBeenThrottled() |
| 215 | 215 |
| 216 def GetCpuStats(self, pid): | 216 def GetCpuStats(self, pid): |
| 217 if not self._can_access_protected_file_contents: | 217 if not self._can_elevate_privilege: |
| 218 logging.warning('CPU stats cannot be retrieved on non-rooted device.') | 218 logging.warning('CPU stats cannot be retrieved on non-rooted device.') |
| 219 return {} | 219 return {} |
| 220 return super(AndroidPlatformBackend, self).GetCpuStats(pid) | 220 return super(AndroidPlatformBackend, self).GetCpuStats(pid) |
| 221 | 221 |
| 222 def GetCpuTimestamp(self): | 222 def GetCpuTimestamp(self): |
| 223 if not self._can_access_protected_file_contents: | 223 if not self._can_elevate_privilege: |
| 224 logging.warning('CPU timestamp cannot be retrieved on non-rooted device.') | 224 logging.warning('CPU timestamp cannot be retrieved on non-rooted device.') |
| 225 return {} | 225 return {} |
| 226 return super(AndroidPlatformBackend, self).GetCpuTimestamp() | 226 return super(AndroidPlatformBackend, self).GetCpuTimestamp() |
| 227 | 227 |
| 228 def SetGraphicsMemoryTrackingEnabled(self, enabled): | 228 def SetGraphicsMemoryTrackingEnabled(self, enabled): |
| 229 if not enabled: | 229 if not enabled: |
| 230 self.KillApplication('memtrack_helper') | 230 self.KillApplication('memtrack_helper') |
| 231 return | 231 return |
| 232 | 232 |
| 233 if not android_prebuilt_profiler_helper.InstallOnDevice( | 233 if not android_prebuilt_profiler_helper.InstallOnDevice( |
| 234 self._device, 'memtrack_helper'): | 234 self._device, 'memtrack_helper'): |
| 235 raise Exception('Error installing memtrack_helper.') | 235 raise Exception('Error installing memtrack_helper.') |
| 236 self._device.RunShellCommand([ | 236 self._device.RunShellCommand([ |
| 237 android_prebuilt_profiler_helper.GetDevicePath('memtrack_helper'), | 237 android_prebuilt_profiler_helper.GetDevicePath('memtrack_helper'), |
| 238 '-d'], as_root=True, check_return=True) | 238 '-d'], as_root=True, check_return=True) |
| 239 | 239 |
| 240 def PurgeUnpinnedMemory(self): | 240 def PurgeUnpinnedMemory(self): |
| 241 """Purges the unpinned ashmem memory for the whole system. | 241 """Purges the unpinned ashmem memory for the whole system. |
| 242 | 242 |
| 243 This can be used to make memory measurements more stable. Requires root. | 243 This can be used to make memory measurements more stable. Requires root. |
| 244 """ | 244 """ |
| 245 if not self._can_access_protected_file_contents: | 245 if not self._can_elevate_privilege: |
| 246 logging.warning('Cannot run purge_ashmem. Requires a rooted device.') | 246 logging.warning('Cannot run purge_ashmem. Requires a rooted device.') |
| 247 return | 247 return |
| 248 | 248 |
| 249 if not android_prebuilt_profiler_helper.InstallOnDevice( | 249 if not android_prebuilt_profiler_helper.InstallOnDevice( |
| 250 self._device, 'purge_ashmem'): | 250 self._device, 'purge_ashmem'): |
| 251 raise Exception('Error installing purge_ashmem.') | 251 raise Exception('Error installing purge_ashmem.') |
| 252 output = self._device.RunShellCommand([ | 252 output = self._device.RunShellCommand([ |
| 253 android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem')]) | 253 android_prebuilt_profiler_helper.GetDevicePath('purge_ashmem')]) |
| 254 for l in output: | 254 for l in output: |
| 255 logging.info(l) | 255 logging.info(l) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 return self._device.product_model | 293 return self._device.product_model |
| 294 | 294 |
| 295 @decorators.Cache | 295 @decorators.Cache |
| 296 def GetOSVersionName(self): | 296 def GetOSVersionName(self): |
| 297 return self._device.GetProp('ro.build.id')[0] | 297 return self._device.GetProp('ro.build.id')[0] |
| 298 | 298 |
| 299 def CanFlushIndividualFilesFromSystemCache(self): | 299 def CanFlushIndividualFilesFromSystemCache(self): |
| 300 return False | 300 return False |
| 301 | 301 |
| 302 def FlushEntireSystemCache(self): | 302 def FlushEntireSystemCache(self): |
| 303 if not self._can_elevate_privilege: |
| 304 logging.warning('Cannot flush system cache on non-rooted device.') |
| 305 return |
| 303 cache = cache_control.CacheControl(self._device) | 306 cache = cache_control.CacheControl(self._device) |
| 304 cache.DropRamCaches() | 307 cache.DropRamCaches() |
| 305 | 308 |
| 306 def FlushSystemCacheForDirectory(self, directory): | 309 def FlushSystemCacheForDirectory(self, directory): |
| 307 raise NotImplementedError() | 310 raise NotImplementedError() |
| 308 | 311 |
| 309 def FlushDnsCache(self): | 312 def FlushDnsCache(self): |
| 310 self._device.RunShellCommand( | 313 self._device.RunShellCommand( |
| 311 ['ndc', 'resolver', 'flushdefaultif'], as_root=True) | 314 ['ndc', 'resolver', 'flushdefaultif'], as_root=True) |
| 312 | 315 |
| 313 def StopApplication(self, application): | 316 def StopApplication(self, application): |
| 314 """Stop the given |application|. | 317 """Stop the given |application|. |
| 315 | 318 |
| 316 Args: | 319 Args: |
| 317 application: The full package name string of the application to stop. | 320 application: The full package name string of the application to stop. |
| 318 """ | 321 """ |
| 319 self._device.ForceStop(application) | 322 self._device.ForceStop(application) |
| 320 | 323 |
| 321 def KillApplication(self, application): | 324 def KillApplication(self, application): |
| 322 """Kill the given |application|. | 325 """Kill the given |application|. |
| 323 | 326 |
| 324 Might be used instead of ForceStop for efficiency reasons. | 327 Might be used instead of ForceStop for efficiency reasons. |
| 325 | 328 |
| 326 Args: | 329 Args: |
| 327 application: The full package name string of the application to kill. | 330 application: The full package name string of the application to kill. |
| 328 """ | 331 """ |
| 329 assert isinstance(application, basestring) | 332 assert isinstance(application, basestring) |
| 330 self._device.KillAll(application, blocking=True, quiet=True) | 333 self._device.KillAll(application, blocking=True, quiet=True) |
| 331 | 334 |
| 335 def CanElevatePrivilege(self): |
| 336 return self._can_elevate_privilege |
| 337 |
| 332 def LaunchApplication( | 338 def LaunchApplication( |
| 333 self, application, parameters=None, elevate_privilege=False): | 339 self, application, parameters=None, elevate_privilege=False): |
| 334 """Launches the given |application| with a list of |parameters| on the OS. | 340 """Launches the given |application| with a list of |parameters| on the OS. |
| 335 | 341 |
| 336 Args: | 342 Args: |
| 337 application: The full package name string of the application to launch. | 343 application: The full package name string of the application to launch. |
| 338 parameters: A list of parameters to be passed to the ActivityManager. | 344 parameters: A list of parameters to be passed to the ActivityManager. |
| 339 elevate_privilege: Currently unimplemented on Android. | 345 elevate_privilege: Currently unimplemented on Android. |
| 340 """ | 346 """ |
| 341 if elevate_privilege: | 347 if elevate_privilege: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 | 415 |
| 410 def PathExists(self, device_path, timeout=None, retries=None): | 416 def PathExists(self, device_path, timeout=None, retries=None): |
| 411 """ Return whether the given path exists on the device. | 417 """ Return whether the given path exists on the device. |
| 412 This method is the same as | 418 This method is the same as |
| 413 devil.android.device_utils.DeviceUtils.PathExists. | 419 devil.android.device_utils.DeviceUtils.PathExists. |
| 414 """ | 420 """ |
| 415 return self._device.PathExists( | 421 return self._device.PathExists( |
| 416 device_path, timeout=timeout, retries=retries) | 422 device_path, timeout=timeout, retries=retries) |
| 417 | 423 |
| 418 def GetFileContents(self, fname): | 424 def GetFileContents(self, fname): |
| 419 if not self._can_access_protected_file_contents: | 425 if not self._can_elevate_privilege: |
| 420 logging.warning('%s cannot be retrieved on non-rooted device.', fname) | 426 logging.warning('%s cannot be retrieved on non-rooted device.', fname) |
| 421 return '' | 427 return '' |
| 422 return self._device.ReadFile(fname, as_root=True) | 428 return self._device.ReadFile(fname, as_root=True) |
| 423 | 429 |
| 424 def GetPsOutput(self, columns, pid=None): | 430 def GetPsOutput(self, columns, pid=None): |
| 425 assert columns == ['pid', 'name'] or columns == ['pid'], \ | 431 assert columns == ['pid', 'name'] or columns == ['pid'], \ |
| 426 'Only know how to return pid and name. Requested: ' + columns | 432 'Only know how to return pid and name. Requested: ' + columns |
| 427 cmd = ['ps'] | 433 cmd = ['ps'] |
| 428 if pid: | 434 if pid: |
| 429 cmd.extend(['-p', str(pid)]) | 435 cmd.extend(['-p', str(pid)]) |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 for process in psutil.process_iter(): | 759 for process in psutil.process_iter(): |
| 754 try: | 760 try: |
| 755 if psutil.version_info >= (2, 0): | 761 if psutil.version_info >= (2, 0): |
| 756 if 'adb' in process.name(): | 762 if 'adb' in process.name(): |
| 757 process.cpu_affinity([0]) | 763 process.cpu_affinity([0]) |
| 758 else: | 764 else: |
| 759 if 'adb' in process.name: | 765 if 'adb' in process.name: |
| 760 process.set_cpu_affinity([0]) | 766 process.set_cpu_affinity([0]) |
| 761 except (psutil.NoSuchProcess, psutil.AccessDenied): | 767 except (psutil.NoSuchProcess, psutil.AccessDenied): |
| 762 logging.warn('Failed to set adb process CPU affinity') | 768 logging.warn('Failed to set adb process CPU affinity') |
| OLD | NEW |