Skip to content

Commit b72fb47

Browse files
committed
docs: Update to include Collector information
1 parent a4fd57f commit b72fb47

File tree

5 files changed

+179
-17
lines changed

5 files changed

+179
-17
lines changed

doc/collectors.rst

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
.. _collector:
2+
3+
Collectors
4+
==========
5+
6+
The ``Collector`` API provide a consistent way of collecting arbitrary data from
7+
a target. Data is collected via an instance of a class derived from
8+
:class:`CollectorBase`.
9+
10+
11+
Example
12+
-------
13+
14+
The following example shows how to use a collector to read the logcat output
15+
from an Android target.
16+
17+
.. code-block:: python
18+
19+
# import and instantiate the Target and the collector
20+
# (note: this assumes exactly one android target connected
21+
# to the host machine).
22+
In [1]: from devlib import AndroidTarget, LogcatCollector
23+
24+
In [2]: t = AndroidTarget()
25+
26+
# Set up the collector on the Target.
27+
28+
In [3]: collector = LogcatCollector(t)
29+
30+
# Configure the output file path for the collector to use.
31+
In [4]: collector.set_output('adb_log.txt')
32+
33+
# Reset the Collector to preform any required configuration or preparation.
34+
In [5]: collector.reset()
35+
36+
# Start Collecting
37+
In [6]: collector.start()
38+
39+
# Wait for some output to be generated
40+
In [7]: sleep(10)
41+
42+
# Stop Collecting
43+
In [8]: collector.stop()
44+
45+
# Retrieved the collected data
46+
In [9]: output = collector.get_data()
47+
48+
# Display the returned ``CollectorOutput`` Object.
49+
In [10]: output
50+
Out[10]: [<adb_log.txt (file)>]
51+
52+
In [11] log_file = output[0]
53+
54+
# Get the path kind of the the returned CollectorOutputEntry.
55+
In [12]: log_file.path_kind
56+
Out[12]: 'file'
57+
58+
# Get the path of the returned CollectorOutputEntry.
59+
In [13]: log_file.path
60+
Out[13]: 'adb_log.txt'
61+
62+
# Find the full path to the log file.
63+
In [14]: os.path.join(os.getcwd(), logfile)
64+
Out[14]: '/tmp/adb_log.txt'
65+
66+
67+
API
68+
---
69+
.. collector:
70+
71+
.. module:: devlib.collector
72+
73+
74+
CollectorBase
75+
~~~~~~~~~~~~~
76+
77+
.. class:: CollectorBase(target, \*\*kwargs)
78+
79+
A ``CollectorBase`` is the the base class and API that should be
80+
implemented to allowing collecting various data from a traget e.g. traces,
81+
logs etc.
82+
83+
.. method:: Collector.setup(\*args, \*\*kwargs)
84+
85+
This will set up the collector on the target. Parameters this method takes
86+
are particular to subclasses (see documentation for specific collectors
87+
below). What actions are performed by this method are also
88+
collector-specific. Usually these will be things like installing
89+
executables, starting services, deploying assets, etc. Typically, this method
90+
needs to be invoked at most once per reboot of the target (unless
91+
``teardown()`` has been called), but see documentation for the collector
92+
you're interested in.
93+
94+
.. method:: CollectorBase.reset()
95+
96+
This can be used to configure a collector for collection. This must be invoked
97+
before ``start()`` is called to begin collection.
98+
99+
.. method:: CollectorBase.start()
100+
101+
Starts collecting from the target.
102+
103+
.. method:: CollectorBase.stop()
104+
105+
Stops collecting from target. Must be called after
106+
:func:`start()`.
107+
108+
109+
.. method:: CollectorBase.set_output(output_path)
110+
111+
Configure the output path for the particular collector. This will be either
112+
a directory or file path which will be used when storing the data. Please see
113+
the individual Collector documentation for more information.
114+
115+
116+
.. method:: CollectorBase.get_data()
117+
118+
The collected data will be return via the previously specified output_path.
119+
This method will return a ``CollectorOutput`` object which is a subclassed
120+
list object containing individual ``CollectorOutputEntry`` objects with details
121+
about the individual output entry.
122+
123+
124+
CollectorOutputEntry
125+
~~~~~~~~~~~~~~~~~~~~
126+
127+
This object is designed to allow for the output of a collector to be processed
128+
generically. The object will behave as a regular string containing the path to
129+
underlying output path and can be used directly in ``os.path`` operations.
130+
131+
.. attribute:: CollectorOutputEntry.path
132+
133+
The file path for the corresponding output item.
134+
135+
.. attribute:: CollectorOutputEntry.path_kind
136+
137+
The type of output the is specified in the ``path`` attribute. Current valid
138+
kinds are: ``file`` and ``directory``.
139+
140+
.. method:: CollectorOutputEntry.__init__(path, path_kind)
141+
142+
Initialises a ``CollectorOutputEntry`` object with the desired file path and
143+
kind of file path specified.
144+
145+
146+
.. collectors:
147+
148+
Available Collectors
149+
---------------------
150+
151+
This section lists collectors that are currently part of devlib.
152+
153+
.. todo:: Add collectors

doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Contents:
1919
target
2020
modules
2121
instrumentation
22+
collectors
2223
derived_measurements
2324
platform
2425
connection

doc/instrumentation.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _instrumentation:
2+
13
Instrumentation
24
===============
35

doc/overview.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ There are currently four target interfaces:
66

77
- :class:`LinuxTarget` for interacting with Linux devices over SSH.
88
- :class:`AndroidTarget` for interacting with Android devices over adb.
9-
- :class:`ChromeOsTarget`: for interacting with ChromeOS devices over SSH, and
10-
their Android containers over adb.
9+
- :class:`ChromeOsTarget`: for interacting with ChromeOS devices over SSH, and their Android containers over adb.
1110
- :class:`LocalLinuxTarget`: for interacting with the local Linux host.
1211

1312
They all work in more-or-less the same way, with the major difference being in
@@ -240,17 +239,17 @@ complete. Retrying it or bailing out is therefore a responsability of the caller
240239
The hierarchy is as follows:
241240

242241
- :class:`DevlibError`
243-
242+
244243
- :class:`WorkerThreadError`
245244
- :class:`HostError`
246245
- :class:`TargetError`
247-
246+
248247
- :class:`TargetStableError`
249248
- :class:`TargetTransientError`
250249
- :class:`TargetNotRespondingError`
251-
250+
252251
- :class:`DevlibStableError`
253-
252+
254253
- :class:`TargetStableError`
255254

256255
- :class:`DevlibTransientError`
@@ -307,12 +306,22 @@ has been successfully installed on a target, you can use ``has()`` method, e.g.
307306
308307
Please see the modules documentation for more detail.
309308

309+
Instruments and Collectors
310+
--------------------------
310311

311-
Measurement and Trace
312-
---------------------
312+
You can retrieve multiple types of data from a target. There are two categories
313+
of classes that allow for this:
313314

314-
You can collected traces (currently, just ftrace) using
315-
:class:`TraceCollector`\ s. For example
315+
316+
- An :class:`Instrument` which may be used to collect measurements (such as power) from
317+
targets that support it. Please see the
318+
:ref:`instruments documentation <Instrumentation>` for more details.
319+
320+
- A :class:`Collector` may be used to collect arbitary data from a ``Target`` varying
321+
from screenshots to trace data. Please see the
322+
:ref:`collectors documentation <collector>` for more details.
323+
324+
An example workflow using :class:`FTraceCollector` is as follows:
316325

317326
.. code:: python
318327
@@ -326,23 +335,19 @@ You can collected traces (currently, just ftrace) using
326335
# As a context manager, clear ftrace buffer using trace.reset(),
327336
# start trace collection using trace.start(), then stop it Using
328337
# trace.stop(). Using a context manager brings the guarantee that
329-
# tracing will stop even if an exception occurs, including
338+
# tracing will stop even if an exception occurs, including
330339
# KeyboardInterrupt (ctr-C) and SystemExit (sys.exit)
331340
with trace:
332341
# Perform the operations you want to trace here...
333342
import time; time.sleep(5)
334343
335344
# extract the trace file from the target into a local file
336-
trace.get_trace('/tmp/trace.bin')
345+
trace.get_data('/tmp/trace.bin')
337346
338347
# View trace file using Kernelshark (must be installed on the host).
339348
trace.view('/tmp/trace.bin')
340349
341350
# Convert binary trace into text format. This would normally be done
342-
# automatically during get_trace(), unless autoreport is set to False during
351+
# automatically during get_data(), unless autoreport is set to False during
343352
# instantiation of the trace collector.
344353
trace.report('/tmp/trace.bin', '/tmp/trace.txt')
345-
346-
In a similar way, :class:`Instrument` instances may be used to collect
347-
measurements (such as power) from targets that support it. Please see
348-
instruments documentation for more details.

doc/target.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ Target
546546
:returns: ``True`` if internet seems available, ``False`` otherwise.
547547

548548
.. method:: Target.install_module(mod, **params)
549+
549550
:param mod: The module name or object to be installed to the target.
550551
:param params: Keyword arguments used to instantiate the module.
551552

0 commit comments

Comments
 (0)