Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1125)

Side by Side Diff: build/android/pylib/forwarder.py

Issue 404993004: [Android] Switch to DeviceUtils versions of GetMemoryUsageForPid and __str__. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comment from frankf Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 """ 82 """
83 # TODO(jbudorick) Remove once telemetry gets switched over. 83 # TODO(jbudorick) Remove once telemetry gets switched over.
84 if isinstance(device, pylib.android_commands.AndroidCommands): 84 if isinstance(device, pylib.android_commands.AndroidCommands):
85 device = pylib.device.device_utils.DeviceUtils(device) 85 device = pylib.device.device_utils.DeviceUtils(device)
86 if not tool: 86 if not tool:
87 tool = valgrind_tools.CreateTool(None, device) 87 tool = valgrind_tools.CreateTool(None, device)
88 with _FileLock(Forwarder._LOCK_PATH): 88 with _FileLock(Forwarder._LOCK_PATH):
89 instance = Forwarder._GetInstanceLocked(tool) 89 instance = Forwarder._GetInstanceLocked(tool)
90 instance._InitDeviceLocked(device, tool) 90 instance._InitDeviceLocked(device, tool)
91 91
92 device_serial = device.old_interface.Adb().GetSerialNumber() 92 device_serial = str(device)
93 redirection_commands = [ 93 redirection_commands = [
94 ['--serial-id=' + device_serial, '--map', str(device), 94 ['--serial-id=' + device_serial, '--map', str(device),
95 str(host)] for device, host in port_pairs] 95 str(host)] for device, host in port_pairs]
96 logging.info('Forwarding using commands: %s', redirection_commands) 96 logging.info('Forwarding using commands: %s', redirection_commands)
97 97
98 for redirection_command in redirection_commands: 98 for redirection_command in redirection_commands:
99 try: 99 try:
100 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( 100 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
101 [instance._host_forwarder_path] + redirection_command) 101 [instance._host_forwarder_path] + redirection_command)
102 except OSError as e: 102 except OSError as e:
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 Args: 140 Args:
141 device: A DeviceUtils instance. 141 device: A DeviceUtils instance.
142 port_pairs: A list of tuples (device_port, host_port) to unmap. 142 port_pairs: A list of tuples (device_port, host_port) to unmap.
143 """ 143 """
144 # TODO(jbudorick) Remove once telemetry gets switched over. 144 # TODO(jbudorick) Remove once telemetry gets switched over.
145 if isinstance(device, pylib.android_commands.AndroidCommands): 145 if isinstance(device, pylib.android_commands.AndroidCommands):
146 device = pylib.device.device_utils.DeviceUtils(device) 146 device = pylib.device.device_utils.DeviceUtils(device)
147 with _FileLock(Forwarder._LOCK_PATH): 147 with _FileLock(Forwarder._LOCK_PATH):
148 if not Forwarder._instance: 148 if not Forwarder._instance:
149 return 149 return
150 adb_serial = device.old_interface.Adb().GetSerialNumber() 150 adb_serial = str(device)
151 if adb_serial not in Forwarder._instance._initialized_devices: 151 if adb_serial not in Forwarder._instance._initialized_devices:
152 return 152 return
153 port_map = Forwarder._GetInstanceLocked( 153 port_map = Forwarder._GetInstanceLocked(
154 None)._device_to_host_port_map 154 None)._device_to_host_port_map
155 for (device_serial, device_port) in port_map.keys(): 155 for (device_serial, device_port) in port_map.keys():
156 if adb_serial == device_serial: 156 if adb_serial == device_serial:
157 Forwarder._UnmapDevicePortLocked(device_port, device) 157 Forwarder._UnmapDevicePortLocked(device_port, device)
158 # There are no more ports mapped, kill the device_forwarder. 158 # There are no more ports mapped, kill the device_forwarder.
159 tool = valgrind_tools.CreateTool(None, device) 159 tool = valgrind_tools.CreateTool(None, device)
160 Forwarder._KillDeviceLocked(device, tool) 160 Forwarder._KillDeviceLocked(device, tool)
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 constants.GetOutDirectory(), 'forwarder_dist') 217 constants.GetOutDirectory(), 'forwarder_dist')
218 self._InitHostLocked() 218 self._InitHostLocked()
219 219
220 @staticmethod 220 @staticmethod
221 def _UnmapDevicePortLocked(device_port, device): 221 def _UnmapDevicePortLocked(device_port, device):
222 """Internal method used by UnmapDevicePort(). 222 """Internal method used by UnmapDevicePort().
223 223
224 Note that the global lock must be acquired before calling this method. 224 Note that the global lock must be acquired before calling this method.
225 """ 225 """
226 instance = Forwarder._GetInstanceLocked(None) 226 instance = Forwarder._GetInstanceLocked(None)
227 serial = device.old_interface.Adb().GetSerialNumber() 227 serial = str(device)
228 serial_with_port = (serial, device_port) 228 serial_with_port = (serial, device_port)
229 if not serial_with_port in instance._device_to_host_port_map: 229 if not serial_with_port in instance._device_to_host_port_map:
230 logging.error('Trying to unmap non-forwarded port %d' % device_port) 230 logging.error('Trying to unmap non-forwarded port %d' % device_port)
231 return 231 return
232 redirection_command = ['--serial-id=' + serial, '--unmap', str(device_port)] 232 redirection_command = ['--serial-id=' + serial, '--unmap', str(device_port)]
233 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput( 233 (exit_code, output) = cmd_helper.GetCmdStatusAndOutput(
234 [instance._host_forwarder_path] + redirection_command) 234 [instance._host_forwarder_path] + redirection_command)
235 if exit_code != 0: 235 if exit_code != 0:
236 logging.error('%s exited with %d:\n%s' % ( 236 logging.error('%s exited with %d:\n%s' % (
237 instance._host_forwarder_path, exit_code, '\n'.join(output))) 237 instance._host_forwarder_path, exit_code, '\n'.join(output)))
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 Note that the global lock must be acquired before calling this method. This 279 Note that the global lock must be acquired before calling this method. This
280 method kills any existing device_forwarder daemon on the device that could 280 method kills any existing device_forwarder daemon on the device that could
281 be stale, pushes the latest version of the daemon (to the device) and starts 281 be stale, pushes the latest version of the daemon (to the device) and starts
282 it. 282 it.
283 283
284 Args: 284 Args:
285 device: A DeviceUtils instance. 285 device: A DeviceUtils instance.
286 tool: Tool class to use to get wrapper, if necessary, for executing the 286 tool: Tool class to use to get wrapper, if necessary, for executing the
287 forwarder (see valgrind_tools.py). 287 forwarder (see valgrind_tools.py).
288 """ 288 """
289 device_serial = device.old_interface.Adb().GetSerialNumber() 289 device_serial = str(device)
290 if device_serial in self._initialized_devices: 290 if device_serial in self._initialized_devices:
291 return 291 return
292 Forwarder._KillDeviceLocked(device, tool) 292 Forwarder._KillDeviceLocked(device, tool)
293 device.PushChangedFiles( 293 device.PushChangedFiles(
294 self._device_forwarder_path_on_host, 294 self._device_forwarder_path_on_host,
295 Forwarder._DEVICE_FORWARDER_FOLDER) 295 Forwarder._DEVICE_FORWARDER_FOLDER)
296 cmd = '%s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH) 296 cmd = '%s %s' % (tool.GetUtilWrapper(), Forwarder._DEVICE_FORWARDER_PATH)
297 (exit_code, output) = device.old_interface.GetAndroidToolStatusAndOutput( 297 (exit_code, output) = device.old_interface.GetAndroidToolStatusAndOutput(
298 cmd, lib_path=Forwarder._DEVICE_FORWARDER_FOLDER) 298 cmd, lib_path=Forwarder._DEVICE_FORWARDER_FOLDER)
299 if exit_code != 0: 299 if exit_code != 0:
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 338
339 # TODO(pliard): Remove the following call to KillAllBlocking() when we are 339 # TODO(pliard): Remove the following call to KillAllBlocking() when we are
340 # sure that the old version of device_forwarder (not supporting 340 # sure that the old version of device_forwarder (not supporting
341 # 'kill-server') is not running on the bots anymore. 341 # 'kill-server') is not running on the bots anymore.
342 timeout_sec = 5 342 timeout_sec = 5
343 try: 343 try:
344 device.KillAll('device_forwarder', blocking=True, timeout=timeout_sec) 344 device.KillAll('device_forwarder', blocking=True, timeout=timeout_sec)
345 except device_errors.CommandFailedError: 345 except device_errors.CommandFailedError:
346 if device.GetPids('device_forwarder'): 346 if device.GetPids('device_forwarder'):
347 raise 347 raise
OLDNEW
« no previous file with comments | « build/android/pylib/device/device_utils_test.py ('k') | build/android/pylib/gtest/test_package_exe.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698