Since we now set the top buffer size to be the same as the devlib buffer
size, this effectively halves the maximum available buffer size that can
be set while using devlib. Whatever size is passed as `buffer_size` will
be allocated twice, even if the top buffer is hardly used at all.
This commit separates them into `buffer_size` and `top_buffer_size`. If
the latter is not passed, the behaviour will not change compared to now.
Fixes: e0c53d09990b5501e493d048a5dce067d8990281
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Installing busybox sometimes fails with:
cp: /data/local/tmp/bin/busybox: Text file busy
This happens when trying to modify a binary file while a process is
still running (e.g. unclean previous disconnection).
Fix that by using the -f option, which will remove the destination file
first and retry the copy in case of failure.
Only run the minimal amount of commands, as executing a command can be
costly.
In the sequence reset() -> start(), we only need to get the output of
dmesg upon start() to know what part of the log will be ignored
(everything before the call to start()). There is no need to perform
that upon reset() since the sequence:
reset() -> start() -> stop() -> start() -> stop()
\______1________/ \______2________/
is anyway equivalent to:
reset() -> start() -> stop()
\______2________/
So reset() can essentially be a no-op and the actual reset logic lives
in start().
Change the SurfaceFlingerFrameCollector to match activities by prefix
instead of looking for an exact match. This will allow to account for
activities with variable suffixes.
Raise an error if more than one activity matches the provided view.
Show a warning if no activities match the provided view in order to
avoid silently failing.
Suggested-by: Andriani Mappoura <andriani.mappoura@arm.com>
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
FEATURE
Add a convenience property for AndroidTarget to expose Android's
external storage app directory path.
This path is used for some applications (such as Unity games) to
store persistent application data instead of '/data/data'.
Signed-off-by: Kajetan Puchalski <kajetan.puchalski@arm.com>
Lack of return statement in wait() was making it return None instead of
the exit code. Add appropriate return statement in wait() and other
function to ensure return value is not lost.
* Split TransferManager and TransferHandle:
* TransferManager deals with the generic monitoring. To abort a
transfer, it simply cancels the transfer and raises an exception
from manage().
* TransferHandle provides a way for the manager to query the state
of the transfer and cancel it. It is backend-specific.
* Remove most of the state in TransferManager, along with the associated
background command leak etc
* Use a daemonic monitor thread to behave as excpected on interpreter
shutdown.
* Ensure a transfer manager _always_ exists. When no management is
desired, a noop object is used. This avoids using a None sentinel,
which is invariably mishandled by some code leading to crashes.
* Try to merge more paths in the code to uncover as many issues as
possible in testing.
* Fix percentage for SSHTransferHandle (transferred / (remaining +
transferred) instead of transferred / remaining)
* Rename total_timeout TransferManager parameter and attribute to
total_transfer_timeout to match the connection name parameter.
Make BackgroundCommand.__init__() poll all current BackgroundCommands on
the associated connection so they deregister themselves if they are
completed.
This ensures that a BackgroundCommand-heavy application that also does
not close them properly will not accumulate useless instances forever
and leak associated resources like Popen objects.
Instead of loosely tracking the current BackgroundCommand for a
connection in _current_bg_cmds WeakSet attribute, use a normal set and
make the BackgroundCommand deregister itself upon termination.
This allows canceling any outstanding BackgroundCommand when the
connection is closed. Currently, destroying a BackgroundCommand will not
cancel the command but devlib will simply loose track of it, and some
threads will likely fail in the background if they try to use the now
broken connection.
kick_off() implementation had a number of issue:
* Target specific implementation making testing more difficult.
* Not wrapping the command in sh -c lead to blocking behavior if the
command had multiple parts, e.g. "sleep 42; echo foo"
* nohup sometimes writes to stdout, breaking return code parsing in
adb_shell().
These issues are fixed by a generic implementing of kick_off() that
simply delegates to Target.background().
Fixes https://github.com/ARM-software/devlib/issues/623
trace-cmd start -B devlib -b 42 will set the buffer size for the
"devlib" ftrace instance but will not set the buffer size of the
top-level buffer.
Unfortunately, some events still end up in the top-level buffer
regardless of any configuration such as the "print" event. This can lead
to lost events because the buffer size was too small.
Avoid that by using the buffer size for both top-level and devlib's
instance.
Ensure adb_root() always raises AdbRootError so that the caller can
catch it reliably. This is especially important since adb_root() failing
is ignored and simply triggers a fallback on using `su`. Android
production builds refuse adb root nowadays, so it's important that adb
root failures are handled well.
FtraceCollector.available_events is not memoized anymore as the set of
events supported by the target can change dynamically (e.g. loading a
kernel module).
This means that calling self.available_events is somewhat expensive, so
avoid doing it in a loop. Instead, save the events in a variable and
reuse it in the function to save a substantial amount of time.
Use a buffer named "devlib" instead of using the top-level default
buffer. That will improve interop with other tools trying to collect a
trace at the same time as devlib.
Replaced all references to devlib.Target with devlib.LinuxTarget to correctly
utilise appropriate interface.
Also added relevant functionality to corectly
create the root directories of the CGroup hierarchies, handling any error that
occurs in that case.
The value for `max_async` when creating a target was being ignored
if a connection was not established as part of the __init__ method.
Save this value for use via `connect` if called directly.
Remove the "future" dependency as devlib does not support Python 2
anymore.
Also remove the "from __future__ import division" as this is the default
in Python 3.
* Remove check_output_lock as the issue has been fixed in Python 3.4
* Use Popen process as a context manager. Technically,
Popen.communicate() already achieves those but the context manager
will ensure this is done even if an exception happens at any point.
adb_root() restarts the server, leading to aborting commands ran by
other connections and also apparently leading to command hanging in some
situations.
Therefore, only allow adb_root() when there is only one connection
active. That should not be a big issue as this is typically called by
the first connection ever made when the Target is created.
Add a memoize_method decorator that works for async methods. It will not
leak memory since the memoization cache is held in the instance
__dict__, and it does not rely on hacks to hash unhashable data.
use_governor() was trying to set concurrently both per-cpu and global tunables for
each governor, which lead to a write conflict.
Split the work into the per-governor global tunables and the per-cpu
tunables, and do all that in concurrently. Each task is therefore
responsible of a distinct set of files and all is well.
Also remove @memoized on async functions. It will be reintroduced in a
later commit when there is a safe alternative for async functions.
The conncetion returned by Target.get_connection() does not have its
.busybox attribute initialized. This is expected for the first
connection, but connections created for new threads should have busybox
set.
Currently the cgroups module will pull all available controllers from
/proc/cgroups and then try to mount them, including the disabled ones.
This will result in the entire mount failing.
Lines in /proc/cgroups ending in 0 correspond to disabled controllers.
Filtering those out solves the issue.