Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 # pylint: disable=W0212 | 5 # pylint: disable=W0212 |
| 6 | 6 |
| 7 import fcntl | 7 import fcntl |
| 8 import logging | 8 import logging |
| 9 import os | 9 import os |
| 10 import psutil | 10 import psutil |
| 11 | 11 |
| 12 from pylib import cmd_helper | 12 from pylib import cmd_helper |
| 13 from pylib import constants | 13 from pylib import constants |
| 14 from pylib import valgrind_tools | 14 from pylib import valgrind_tools |
| 15 | 15 |
| 16 # TODO(jbudorick) Remove once telemetry gets switched over. | |
| 17 import pylib.android_commands | |
| 18 import pylib.device.device_utils | 16 import pylib.device.device_utils |
| 19 | 17 |
| 20 | 18 |
| 21 def _GetProcessStartTime(pid): | 19 def _GetProcessStartTime(pid): |
| 22 return psutil.Process(pid).create_time | 20 return psutil.Process(pid).create_time |
| 23 | 21 |
| 24 | 22 |
| 25 class _FileLock(object): | 23 class _FileLock(object): |
| 26 """With statement-aware implementation of a file lock. | 24 """With statement-aware implementation of a file lock. |
| 27 | 25 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 port will by dynamically assigned on the device. You can | 64 port will by dynamically assigned on the device. You can |
| 67 get the number of the assigned port using the | 65 get the number of the assigned port using the |
| 68 DevicePortForHostPort method. | 66 DevicePortForHostPort method. |
| 69 device: A DeviceUtils instance. | 67 device: A DeviceUtils instance. |
| 70 tool: Tool class to use to get wrapper, if necessary, for executing the | 68 tool: Tool class to use to get wrapper, if necessary, for executing the |
| 71 forwarder (see valgrind_tools.py). | 69 forwarder (see valgrind_tools.py). |
| 72 | 70 |
| 73 Raises: | 71 Raises: |
| 74 Exception on failure to forward the port. | 72 Exception on failure to forward the port. |
| 75 """ | 73 """ |
| 76 # TODO(jbudorick) Remove once telemetry gets switched over. | 74 # TODO(jbudorick) Remove once telemetry gets switched over. |
|
jbudorick
2015/07/28 17:31:42
these can go too :P
nednguyen
2015/07/28 17:39:38
Done.
| |
| 77 assert not isinstance(device, pylib.android_commands.AndroidCommands) | |
| 78 if not tool: | 75 if not tool: |
| 79 tool = valgrind_tools.CreateTool(None, device) | 76 tool = valgrind_tools.CreateTool(None, device) |
| 80 with _FileLock(Forwarder._LOCK_PATH): | 77 with _FileLock(Forwarder._LOCK_PATH): |
| 81 instance = Forwarder._GetInstanceLocked(tool) | 78 instance = Forwarder._GetInstanceLocked(tool) |
| 82 instance._InitDeviceLocked(device, tool) | 79 instance._InitDeviceLocked(device, tool) |
| 83 | 80 |
| 84 device_serial = str(device) | 81 device_serial = str(device) |
| 85 redirection_commands = [ | 82 redirection_commands = [ |
| 86 ['--adb=' + constants.GetAdbPath(), | 83 ['--adb=' + constants.GetAdbPath(), |
| 87 '--serial-id=' + device_serial, | 84 '--serial-id=' + device_serial, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 116 | 113 |
| 117 @staticmethod | 114 @staticmethod |
| 118 def UnmapDevicePort(device_port, device): | 115 def UnmapDevicePort(device_port, device): |
| 119 """Unmaps a previously forwarded device port. | 116 """Unmaps a previously forwarded device port. |
| 120 | 117 |
| 121 Args: | 118 Args: |
| 122 device: A DeviceUtils instance. | 119 device: A DeviceUtils instance. |
| 123 device_port: A previously forwarded port (through Map()). | 120 device_port: A previously forwarded port (through Map()). |
| 124 """ | 121 """ |
| 125 # TODO(jbudorick) Remove once telemetry gets switched over. | 122 # TODO(jbudorick) Remove once telemetry gets switched over. |
| 126 assert not isinstance(device, pylib.android_commands.AndroidCommands) | |
| 127 with _FileLock(Forwarder._LOCK_PATH): | 123 with _FileLock(Forwarder._LOCK_PATH): |
| 128 Forwarder._UnmapDevicePortLocked(device_port, device) | 124 Forwarder._UnmapDevicePortLocked(device_port, device) |
| 129 | 125 |
| 130 @staticmethod | 126 @staticmethod |
| 131 def UnmapAllDevicePorts(device): | 127 def UnmapAllDevicePorts(device): |
| 132 """Unmaps all the previously forwarded ports for the provided device. | 128 """Unmaps all the previously forwarded ports for the provided device. |
| 133 | 129 |
| 134 Args: | 130 Args: |
| 135 device: A DeviceUtils instance. | 131 device: A DeviceUtils instance. |
| 136 port_pairs: A list of tuples (device_port, host_port) to unmap. | 132 port_pairs: A list of tuples (device_port, host_port) to unmap. |
| 137 """ | 133 """ |
| 138 # TODO(jbudorick) Remove once telemetry gets switched over. | 134 # TODO(jbudorick) Remove once telemetry gets switched over. |
| 139 assert not isinstance(device, pylib.android_commands.AndroidCommands) | |
| 140 with _FileLock(Forwarder._LOCK_PATH): | 135 with _FileLock(Forwarder._LOCK_PATH): |
| 141 if not Forwarder._instance: | 136 if not Forwarder._instance: |
| 142 return | 137 return |
| 143 adb_serial = str(device) | 138 adb_serial = str(device) |
| 144 if adb_serial not in Forwarder._instance._initialized_devices: | 139 if adb_serial not in Forwarder._instance._initialized_devices: |
| 145 return | 140 return |
| 146 port_map = Forwarder._GetInstanceLocked( | 141 port_map = Forwarder._GetInstanceLocked( |
| 147 None)._device_to_host_port_map | 142 None)._device_to_host_port_map |
| 148 for (device_serial, device_port) in port_map.keys(): | 143 for (device_serial, device_port) in port_map.keys(): |
| 149 if adb_serial == device_serial: | 144 if adb_serial == device_serial: |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 319 logging.info('Killing device_forwarder.') | 314 logging.info('Killing device_forwarder.') |
| 320 Forwarder._instance._initialized_devices.discard(str(device)) | 315 Forwarder._instance._initialized_devices.discard(str(device)) |
| 321 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): | 316 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): |
| 322 return | 317 return |
| 323 | 318 |
| 324 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), | 319 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), |
| 325 Forwarder._DEVICE_FORWARDER_PATH) | 320 Forwarder._DEVICE_FORWARDER_PATH) |
| 326 device.RunShellCommand( | 321 device.RunShellCommand( |
| 327 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, | 322 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, |
| 328 check_return=True) | 323 check_return=True) |
| OLD | NEW |