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 devil.android.valgrind_tools import base_tool |
12 from devil.utils import cmd_helper | 13 from devil.utils import cmd_helper |
13 from pylib import constants | 14 from pylib import constants |
14 from pylib import valgrind_tools | |
15 | 15 |
16 | 16 |
17 def _GetProcessStartTime(pid): | 17 def _GetProcessStartTime(pid): |
18 return psutil.Process(pid).create_time | 18 return psutil.Process(pid).create_time |
19 | 19 |
20 | 20 |
21 class _FileLock(object): | 21 class _FileLock(object): |
22 """With statement-aware implementation of a file lock. | 22 """With statement-aware implementation of a file lock. |
23 | 23 |
24 File locks are needed for cross-process synchronization when the | 24 File locks are needed for cross-process synchronization when the |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 get the number of the assigned port using the | 63 get the number of the assigned port using the |
64 DevicePortForHostPort method. | 64 DevicePortForHostPort method. |
65 device: A DeviceUtils instance. | 65 device: A DeviceUtils instance. |
66 tool: Tool class to use to get wrapper, if necessary, for executing the | 66 tool: Tool class to use to get wrapper, if necessary, for executing the |
67 forwarder (see valgrind_tools.py). | 67 forwarder (see valgrind_tools.py). |
68 | 68 |
69 Raises: | 69 Raises: |
70 Exception on failure to forward the port. | 70 Exception on failure to forward the port. |
71 """ | 71 """ |
72 if not tool: | 72 if not tool: |
73 tool = valgrind_tools.CreateTool(None, device) | 73 tool = base_tool.BaseTool() |
74 with _FileLock(Forwarder._LOCK_PATH): | 74 with _FileLock(Forwarder._LOCK_PATH): |
75 instance = Forwarder._GetInstanceLocked(tool) | 75 instance = Forwarder._GetInstanceLocked(tool) |
76 instance._InitDeviceLocked(device, tool) | 76 instance._InitDeviceLocked(device, tool) |
77 | 77 |
78 device_serial = str(device) | 78 device_serial = str(device) |
79 redirection_commands = [ | 79 redirection_commands = [ |
80 ['--adb=' + constants.GetAdbPath(), | 80 ['--adb=' + constants.GetAdbPath(), |
81 '--serial-id=' + device_serial, | 81 '--serial-id=' + device_serial, |
82 '--map', str(device_port), str(host_port)] | 82 '--map', str(device_port), str(host_port)] |
83 for device_port, host_port in port_pairs] | 83 for device_port, host_port in port_pairs] |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 return | 138 return |
139 adb_serial = str(device) | 139 adb_serial = str(device) |
140 if adb_serial not in Forwarder._instance._initialized_devices: | 140 if adb_serial not in Forwarder._instance._initialized_devices: |
141 return | 141 return |
142 port_map = Forwarder._GetInstanceLocked( | 142 port_map = Forwarder._GetInstanceLocked( |
143 None)._device_to_host_port_map | 143 None)._device_to_host_port_map |
144 for (device_serial, device_port) in port_map.keys(): | 144 for (device_serial, device_port) in port_map.keys(): |
145 if adb_serial == device_serial: | 145 if adb_serial == device_serial: |
146 Forwarder._UnmapDevicePortLocked(device_port, device) | 146 Forwarder._UnmapDevicePortLocked(device_port, device) |
147 # There are no more ports mapped, kill the device_forwarder. | 147 # There are no more ports mapped, kill the device_forwarder. |
148 tool = valgrind_tools.CreateTool(None, device) | 148 tool = base_tool.BaseTool() |
149 Forwarder._KillDeviceLocked(device, tool) | 149 Forwarder._KillDeviceLocked(device, tool) |
150 | 150 |
151 @staticmethod | 151 @staticmethod |
152 def DevicePortForHostPort(host_port): | 152 def DevicePortForHostPort(host_port): |
153 """Returns the device port that corresponds to a given host port.""" | 153 """Returns the device port that corresponds to a given host port.""" |
154 with _FileLock(Forwarder._LOCK_PATH): | 154 with _FileLock(Forwarder._LOCK_PATH): |
155 _, device_port = Forwarder._GetInstanceLocked( | 155 _, device_port = Forwarder._GetInstanceLocked( |
156 None)._host_to_device_port_map.get(host_port) | 156 None)._host_to_device_port_map.get(host_port) |
157 return device_port | 157 return device_port |
158 | 158 |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 logging.info('Killing device_forwarder.') | 317 logging.info('Killing device_forwarder.') |
318 Forwarder._instance._initialized_devices.discard(str(device)) | 318 Forwarder._instance._initialized_devices.discard(str(device)) |
319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): | 319 if not device.FileExists(Forwarder._DEVICE_FORWARDER_PATH): |
320 return | 320 return |
321 | 321 |
322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), | 322 cmd = '%s %s --kill-server' % (tool.GetUtilWrapper(), |
323 Forwarder._DEVICE_FORWARDER_PATH) | 323 Forwarder._DEVICE_FORWARDER_PATH) |
324 device.RunShellCommand( | 324 device.RunShellCommand( |
325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, | 325 cmd, env={'LD_LIBRARY_PATH': Forwarder._DEVICE_FORWARDER_FOLDER}, |
326 check_return=True) | 326 check_return=True) |
OLD | NEW |