|
| 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 |
0 commit comments