mirror of
https://github.com/ARM-software/devlib.git
synced 2025-01-31 02:00:45 +00:00
docs: Update to include Collector information
This commit is contained in:
parent
a4fd57f023
commit
b72fb470e7
153
doc/collectors.rst
Normal file
153
doc/collectors.rst
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
.. _collector:
|
||||||
|
|
||||||
|
Collectors
|
||||||
|
==========
|
||||||
|
|
||||||
|
The ``Collector`` API provide a consistent way of collecting arbitrary data from
|
||||||
|
a target. Data is collected via an instance of a class derived from
|
||||||
|
:class:`CollectorBase`.
|
||||||
|
|
||||||
|
|
||||||
|
Example
|
||||||
|
-------
|
||||||
|
|
||||||
|
The following example shows how to use a collector to read the logcat output
|
||||||
|
from an Android target.
|
||||||
|
|
||||||
|
.. code-block:: python
|
||||||
|
|
||||||
|
# import and instantiate the Target and the collector
|
||||||
|
# (note: this assumes exactly one android target connected
|
||||||
|
# to the host machine).
|
||||||
|
In [1]: from devlib import AndroidTarget, LogcatCollector
|
||||||
|
|
||||||
|
In [2]: t = AndroidTarget()
|
||||||
|
|
||||||
|
# Set up the collector on the Target.
|
||||||
|
|
||||||
|
In [3]: collector = LogcatCollector(t)
|
||||||
|
|
||||||
|
# Configure the output file path for the collector to use.
|
||||||
|
In [4]: collector.set_output('adb_log.txt')
|
||||||
|
|
||||||
|
# Reset the Collector to preform any required configuration or preparation.
|
||||||
|
In [5]: collector.reset()
|
||||||
|
|
||||||
|
# Start Collecting
|
||||||
|
In [6]: collector.start()
|
||||||
|
|
||||||
|
# Wait for some output to be generated
|
||||||
|
In [7]: sleep(10)
|
||||||
|
|
||||||
|
# Stop Collecting
|
||||||
|
In [8]: collector.stop()
|
||||||
|
|
||||||
|
# Retrieved the collected data
|
||||||
|
In [9]: output = collector.get_data()
|
||||||
|
|
||||||
|
# Display the returned ``CollectorOutput`` Object.
|
||||||
|
In [10]: output
|
||||||
|
Out[10]: [<adb_log.txt (file)>]
|
||||||
|
|
||||||
|
In [11] log_file = output[0]
|
||||||
|
|
||||||
|
# Get the path kind of the the returned CollectorOutputEntry.
|
||||||
|
In [12]: log_file.path_kind
|
||||||
|
Out[12]: 'file'
|
||||||
|
|
||||||
|
# Get the path of the returned CollectorOutputEntry.
|
||||||
|
In [13]: log_file.path
|
||||||
|
Out[13]: 'adb_log.txt'
|
||||||
|
|
||||||
|
# Find the full path to the log file.
|
||||||
|
In [14]: os.path.join(os.getcwd(), logfile)
|
||||||
|
Out[14]: '/tmp/adb_log.txt'
|
||||||
|
|
||||||
|
|
||||||
|
API
|
||||||
|
---
|
||||||
|
.. collector:
|
||||||
|
|
||||||
|
.. module:: devlib.collector
|
||||||
|
|
||||||
|
|
||||||
|
CollectorBase
|
||||||
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
.. class:: CollectorBase(target, \*\*kwargs)
|
||||||
|
|
||||||
|
A ``CollectorBase`` is the the base class and API that should be
|
||||||
|
implemented to allowing collecting various data from a traget e.g. traces,
|
||||||
|
logs etc.
|
||||||
|
|
||||||
|
.. method:: Collector.setup(\*args, \*\*kwargs)
|
||||||
|
|
||||||
|
This will set up the collector on the target. Parameters this method takes
|
||||||
|
are particular to subclasses (see documentation for specific collectors
|
||||||
|
below). What actions are performed by this method are also
|
||||||
|
collector-specific. Usually these will be things like installing
|
||||||
|
executables, starting services, deploying assets, etc. Typically, this method
|
||||||
|
needs to be invoked at most once per reboot of the target (unless
|
||||||
|
``teardown()`` has been called), but see documentation for the collector
|
||||||
|
you're interested in.
|
||||||
|
|
||||||
|
.. method:: CollectorBase.reset()
|
||||||
|
|
||||||
|
This can be used to configure a collector for collection. This must be invoked
|
||||||
|
before ``start()`` is called to begin collection.
|
||||||
|
|
||||||
|
.. method:: CollectorBase.start()
|
||||||
|
|
||||||
|
Starts collecting from the target.
|
||||||
|
|
||||||
|
.. method:: CollectorBase.stop()
|
||||||
|
|
||||||
|
Stops collecting from target. Must be called after
|
||||||
|
:func:`start()`.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: CollectorBase.set_output(output_path)
|
||||||
|
|
||||||
|
Configure the output path for the particular collector. This will be either
|
||||||
|
a directory or file path which will be used when storing the data. Please see
|
||||||
|
the individual Collector documentation for more information.
|
||||||
|
|
||||||
|
|
||||||
|
.. method:: CollectorBase.get_data()
|
||||||
|
|
||||||
|
The collected data will be return via the previously specified output_path.
|
||||||
|
This method will return a ``CollectorOutput`` object which is a subclassed
|
||||||
|
list object containing individual ``CollectorOutputEntry`` objects with details
|
||||||
|
about the individual output entry.
|
||||||
|
|
||||||
|
|
||||||
|
CollectorOutputEntry
|
||||||
|
~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
This object is designed to allow for the output of a collector to be processed
|
||||||
|
generically. The object will behave as a regular string containing the path to
|
||||||
|
underlying output path and can be used directly in ``os.path`` operations.
|
||||||
|
|
||||||
|
.. attribute:: CollectorOutputEntry.path
|
||||||
|
|
||||||
|
The file path for the corresponding output item.
|
||||||
|
|
||||||
|
.. attribute:: CollectorOutputEntry.path_kind
|
||||||
|
|
||||||
|
The type of output the is specified in the ``path`` attribute. Current valid
|
||||||
|
kinds are: ``file`` and ``directory``.
|
||||||
|
|
||||||
|
.. method:: CollectorOutputEntry.__init__(path, path_kind)
|
||||||
|
|
||||||
|
Initialises a ``CollectorOutputEntry`` object with the desired file path and
|
||||||
|
kind of file path specified.
|
||||||
|
|
||||||
|
|
||||||
|
.. collectors:
|
||||||
|
|
||||||
|
Available Collectors
|
||||||
|
---------------------
|
||||||
|
|
||||||
|
This section lists collectors that are currently part of devlib.
|
||||||
|
|
||||||
|
.. todo:: Add collectors
|
@ -19,6 +19,7 @@ Contents:
|
|||||||
target
|
target
|
||||||
modules
|
modules
|
||||||
instrumentation
|
instrumentation
|
||||||
|
collectors
|
||||||
derived_measurements
|
derived_measurements
|
||||||
platform
|
platform
|
||||||
connection
|
connection
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
.. _instrumentation:
|
||||||
|
|
||||||
Instrumentation
|
Instrumentation
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
@ -6,8 +6,7 @@ There are currently four target interfaces:
|
|||||||
|
|
||||||
- :class:`LinuxTarget` for interacting with Linux devices over SSH.
|
- :class:`LinuxTarget` for interacting with Linux devices over SSH.
|
||||||
- :class:`AndroidTarget` for interacting with Android devices over adb.
|
- :class:`AndroidTarget` for interacting with Android devices over adb.
|
||||||
- :class:`ChromeOsTarget`: for interacting with ChromeOS devices over SSH, and
|
- :class:`ChromeOsTarget`: for interacting with ChromeOS devices over SSH, and their Android containers over adb.
|
||||||
their Android containers over adb.
|
|
||||||
- :class:`LocalLinuxTarget`: for interacting with the local Linux host.
|
- :class:`LocalLinuxTarget`: for interacting with the local Linux host.
|
||||||
|
|
||||||
They all work in more-or-less the same way, with the major difference being in
|
They all work in more-or-less the same way, with the major difference being in
|
||||||
@ -307,12 +306,22 @@ has been successfully installed on a target, you can use ``has()`` method, e.g.
|
|||||||
|
|
||||||
Please see the modules documentation for more detail.
|
Please see the modules documentation for more detail.
|
||||||
|
|
||||||
|
Instruments and Collectors
|
||||||
|
--------------------------
|
||||||
|
|
||||||
Measurement and Trace
|
You can retrieve multiple types of data from a target. There are two categories
|
||||||
---------------------
|
of classes that allow for this:
|
||||||
|
|
||||||
You can collected traces (currently, just ftrace) using
|
|
||||||
:class:`TraceCollector`\ s. For example
|
- An :class:`Instrument` which may be used to collect measurements (such as power) from
|
||||||
|
targets that support it. Please see the
|
||||||
|
:ref:`instruments documentation <Instrumentation>` for more details.
|
||||||
|
|
||||||
|
- A :class:`Collector` may be used to collect arbitary data from a ``Target`` varying
|
||||||
|
from screenshots to trace data. Please see the
|
||||||
|
:ref:`collectors documentation <collector>` for more details.
|
||||||
|
|
||||||
|
An example workflow using :class:`FTraceCollector` is as follows:
|
||||||
|
|
||||||
.. code:: python
|
.. code:: python
|
||||||
|
|
||||||
@ -333,16 +342,12 @@ You can collected traces (currently, just ftrace) using
|
|||||||
import time; time.sleep(5)
|
import time; time.sleep(5)
|
||||||
|
|
||||||
# extract the trace file from the target into a local file
|
# extract the trace file from the target into a local file
|
||||||
trace.get_trace('/tmp/trace.bin')
|
trace.get_data('/tmp/trace.bin')
|
||||||
|
|
||||||
# View trace file using Kernelshark (must be installed on the host).
|
# View trace file using Kernelshark (must be installed on the host).
|
||||||
trace.view('/tmp/trace.bin')
|
trace.view('/tmp/trace.bin')
|
||||||
|
|
||||||
# Convert binary trace into text format. This would normally be done
|
# Convert binary trace into text format. This would normally be done
|
||||||
# automatically during get_trace(), unless autoreport is set to False during
|
# automatically during get_data(), unless autoreport is set to False during
|
||||||
# instantiation of the trace collector.
|
# instantiation of the trace collector.
|
||||||
trace.report('/tmp/trace.bin', '/tmp/trace.txt')
|
trace.report('/tmp/trace.bin', '/tmp/trace.txt')
|
||||||
|
|
||||||
In a similar way, :class:`Instrument` instances may be used to collect
|
|
||||||
measurements (such as power) from targets that support it. Please see
|
|
||||||
instruments documentation for more details.
|
|
||||||
|
@ -546,6 +546,7 @@ Target
|
|||||||
:returns: ``True`` if internet seems available, ``False`` otherwise.
|
:returns: ``True`` if internet seems available, ``False`` otherwise.
|
||||||
|
|
||||||
.. method:: Target.install_module(mod, **params)
|
.. method:: Target.install_module(mod, **params)
|
||||||
|
|
||||||
:param mod: The module name or object to be installed to the target.
|
:param mod: The module name or object to be installed to the target.
|
||||||
:param params: Keyword arguments used to instantiate the module.
|
:param params: Keyword arguments used to instantiate the module.
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user