Skip to content

Commit 18ab9f8

Browse files
douglas-raillard-armmarcbonnici
authored andcommitted
target: Expose Target(max_async=50) parameter
Allow the user to set a maximum number of conrruent connections used to dispatch non-blocking commands when using the async API.
1 parent 92f58e4 commit 18ab9f8

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

devlib/target.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,11 @@ def __init__(self,
306306
load_default_modules=True,
307307
shell_prompt=DEFAULT_SHELL_PROMPT,
308308
conn_cls=None,
309-
is_container=False
309+
is_container=False,
310+
max_async=50,
310311
):
311312
self._async_pool = None
313+
self._async_pool_size = None
312314
self._unused_conns = set()
313315

314316
self._is_rooted = None
@@ -352,7 +354,7 @@ def __init__(self,
352354
self.modules = merge_lists(*module_lists, duplicates='first')
353355
self._update_modules('early')
354356
if connect:
355-
self.connect()
357+
self.connect(max_async=max_async)
356358

357359
def __getstate__(self):
358360
# tls_property will recreate the underlying value automatically upon
@@ -363,12 +365,25 @@ def __getstate__(self):
363365
for k, v in inspect.getmembers(self.__class__)
364366
if isinstance(v, _BoundTLSProperty)
365367
}
368+
ignored.update((
369+
'_async_pool',
370+
'_unused_conns',
371+
))
366372
return {
367373
k: v
368374
for k, v in self.__dict__.items()
369375
if k not in ignored
370376
}
371377

378+
def __setstate__(self, dct):
379+
self.__dict__ = dct
380+
pool_size = self._async_pool_size
381+
if pool_size is None:
382+
self._async_pool = None
383+
else:
384+
self._async_pool = ThreadPoolExecutor(pool_size)
385+
self._unused_conns = set()
386+
372387
# connection and initialization
373388

374389
@asyn.asyncf
@@ -433,6 +448,7 @@ def make_conn(_):
433448
max_conns = len(conns)
434449

435450
self.logger.debug(f'Detected max number of async commands: {max_conns}')
451+
self._async_pool_size = max_conns
436452
self._async_pool = ThreadPoolExecutor(max_conns)
437453

438454
@asyn.asyncf
@@ -1547,6 +1563,7 @@ def __init__(self,
15471563
shell_prompt=DEFAULT_SHELL_PROMPT,
15481564
conn_cls=SshConnection,
15491565
is_container=False,
1566+
max_async=50,
15501567
):
15511568
super(LinuxTarget, self).__init__(connection_settings=connection_settings,
15521569
platform=platform,
@@ -1557,7 +1574,8 @@ def __init__(self,
15571574
load_default_modules=load_default_modules,
15581575
shell_prompt=shell_prompt,
15591576
conn_cls=conn_cls,
1560-
is_container=is_container)
1577+
is_container=is_container,
1578+
max_async=max_async)
15611579

15621580
def wait_boot_complete(self, timeout=10):
15631581
pass
@@ -1752,6 +1770,7 @@ def __init__(self,
17521770
conn_cls=AdbConnection,
17531771
package_data_directory="/data/data",
17541772
is_container=False,
1773+
max_async=50,
17551774
):
17561775
super(AndroidTarget, self).__init__(connection_settings=connection_settings,
17571776
platform=platform,
@@ -1762,7 +1781,8 @@ def __init__(self,
17621781
load_default_modules=load_default_modules,
17631782
shell_prompt=shell_prompt,
17641783
conn_cls=conn_cls,
1765-
is_container=is_container)
1784+
is_container=is_container,
1785+
max_async=max_async)
17661786
self.package_data_directory = package_data_directory
17671787
self._init_logcat_lock()
17681788

@@ -2823,6 +2843,7 @@ def __init__(self,
28232843
shell_prompt=DEFAULT_SHELL_PROMPT,
28242844
conn_cls=LocalConnection,
28252845
is_container=False,
2846+
max_async=50,
28262847
):
28272848
super(LocalLinuxTarget, self).__init__(connection_settings=connection_settings,
28282849
platform=platform,
@@ -2833,7 +2854,8 @@ def __init__(self,
28332854
load_default_modules=load_default_modules,
28342855
shell_prompt=shell_prompt,
28352856
conn_cls=conn_cls,
2836-
is_container=is_container)
2857+
is_container=is_container,
2858+
max_async=max_async)
28372859

28382860
def _resolve_paths(self):
28392861
if self.working_directory is None:
@@ -2906,7 +2928,8 @@ def __init__(self,
29062928
load_default_modules=True,
29072929
shell_prompt=DEFAULT_SHELL_PROMPT,
29082930
package_data_directory="/data/data",
2909-
is_container=False
2931+
is_container=False,
2932+
max_async=50,
29102933
):
29112934

29122935
self.supports_android = None
@@ -2932,7 +2955,8 @@ def __init__(self,
29322955
load_default_modules=load_default_modules,
29332956
shell_prompt=shell_prompt,
29342957
conn_cls=SshConnection,
2935-
is_container=is_container)
2958+
is_container=is_container,
2959+
max_async=max_async)
29362960

29372961
# We can't determine if the target supports android until connected to the linux host so
29382962
# create unconditionally.

doc/target.rst

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Target
44
======
55

6-
.. class:: Target(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=None)
6+
.. class:: Target(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=None, max_async=50)
77

88
:class:`~devlib.target.Target` is the primary interface to the remote
99
device. All interactions with the device are performed via a
@@ -76,6 +76,9 @@ Target
7676
:param conn_cls: This is the type of connection that will be used to
7777
communicate with the device.
7878

79+
:param max_async: Maximum number of opened connections to the target used to
80+
issue non-blocking commands when using the async API.
81+
7982
.. attribute:: Target.core_names
8083

8184
This is a list containing names of CPU cores on the target, in the order in
@@ -606,7 +609,7 @@ Target
606609
Linux Target
607610
------------
608611

609-
.. class:: LinuxTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=SshConnection, is_container=False,)
612+
.. class:: LinuxTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=SshConnection, is_container=False, max_async=50)
610613

611614
:class:`LinuxTarget` is a subclass of :class:`~devlib.target.Target`
612615
with customisations specific to a device running linux.
@@ -615,7 +618,7 @@ Linux Target
615618
Local Linux Target
616619
------------------
617620

618-
.. class:: LocalLinuxTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=SshConnection, is_container=False,)
621+
.. class:: LocalLinuxTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=SshConnection, is_container=False, max_async=50)
619622

620623
:class:`LocalLinuxTarget` is a subclass of
621624
:class:`~devlib.target.LinuxTarget` with customisations specific to using
@@ -625,7 +628,7 @@ Local Linux Target
625628
Android Target
626629
---------------
627630

628-
.. class:: AndroidTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=AdbConnection, package_data_directory="/data/data")
631+
.. class:: AndroidTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, conn_cls=AdbConnection, package_data_directory="/data/data", max_async=50)
629632

630633
:class:`AndroidTarget` is a subclass of :class:`~devlib.target.Target` with
631634
additional features specific to a device running Android.
@@ -773,7 +776,7 @@ Android Target
773776
ChromeOS Target
774777
---------------
775778

776-
.. class:: ChromeOsTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, android_working_directory=None, android_executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, package_data_directory="/data/data")
779+
.. class:: ChromeOsTarget(connection_settings=None, platform=None, working_directory=None, executables_directory=None, android_working_directory=None, android_executables_directory=None, connect=True, modules=None, load_default_modules=True, shell_prompt=DEFAULT_SHELL_PROMPT, package_data_directory="/data/data", max_async=50)
777780

778781
:class:`ChromeOsTarget` is a subclass of :class:`LinuxTarget` with
779782
additional features specific to a device running ChromeOS for example,

0 commit comments

Comments
 (0)