Host-driven metrics collectors

Host-driven metrics collectors run on the host and not on the device side. They interact with the device from the host side to collect the metrics they are targeting.

Metrics collector design

The base class that all collectors extend is BaseDeviceMetricCollector, which helps provide the same shared basic functionalities:

  • Filtering
  • Disabling
  • Collection on test cases versus test runs

Collectors follow a result reporter model because they synchronize with the test execution on the host. In other words, if tests are host-driven, collectors are executed before the test proceeds to the next execution step.

For example, if the collector executes on testEnded, the collectors execute before the execution proceeds to the next test with testStart.

Implement a host-driven metrics collector

When implementing on top of the base class BaseDeviceMetricCollector you can decide when to collect your metrics during the lifecycle:

  • When a test run starts: onTestRunStart
  • When a test case starts: onTestStart
  • When a test case ends: onTestEnd
  • When a test run ends: onTestRunEnd

Perform asynchronous collection

In addition to the synchronous methods, TF provides a base class to implement that performs periodic asynchronous collection, ScheduledDeviceMetricCollector, which provides a collect method to be implemented that runs periodically.

The period is customizable by options.

XML configuration

The object tag is metrics_collector, for example:

<metrics_collector class="com.android.tradefed.device.metric.AtraceCollector">
    <option name="categories" value="freq"/>
</metrics_collector>

Recommendations

Look at the existing list of collectors to ensure you aren't duplicating work. We try to ensure maximum reusability, so having each collector performing a single type of collection allows more mixing and matching of different collectors during test execution.