MetricUtility

public class MetricUtility
extends Object

java.lang.Object
   ↳ com.android.tradefed.util.MetricUtility


Contains common utility methods for storing the test metrics, aggregating the metrics in similar tests and writing the metrics to a file.

Summary

Nested classes

class MetricUtility.DimensionalIterationData

Helper class to hold dimensional metric file and status for a single test iteration. 

Public constructors

MetricUtility()

Public methods

File aggregateDimensionalMetricsAndWriteToFile(List<MetricUtility.DimensionalIterationData> iterationDataList, Set<Integer> percentiles, String testIterationSeparator)

Reads all stored dimensional metric report files, aggregates the raw values, computes statistics, and writes a new aggregated report file.

Map<String, MetricMeasurement.Metric> aggregateMetrics(Map<String, MetricMeasurement.Metric> rawMetrics)

Aggregate comma separated metrics.

File aggregateStoredTestMetricsAndWriteToFile(String fileName)

Aggregate the metrics collected from multiple iterations of the test and write the aggregated metrics to a test result file.

void buildMetricFilterPatterns(Set<String> strictIncludeRegEx)

Build regular expression patterns to filter the metrics.

Map<String, MetricMeasurement.Metric> filterMetrics(Map<String, MetricMeasurement.Metric> parsedMetrics)

Filter the metrics that matches the pattern.

static Map<String, Double> getStats(List<Double> values, Set<Integer> percentiles, int testIterations)

Compute the stats from the give list of values.

Map<String, List<MetricUtility.IterationData>> getTestIterations()
static boolean isAllDoubleValues(List<String> rawValues)

Checks if all the values in the list are double values.

void setIterationSeparator(String separator)
void setMetricsUseForTestIterations(Set<String> metricsUseForTestIterations)

Sets the regular expressions for metrics that should use passed test iterations for mean calculation during aggregation.

void setPercentiles(Set<Integer> percentiles)
void storeTestMetrics(TestDescription testDescription, Map<String, MetricMeasurement.Metric> testMetrics, boolean testFailed)

Used for storing the individual test metrics and use it for aggregation.

void storeTestMetrics(TestDescription testDescription, Map<String, MetricMeasurement.Metric> testMetrics)

Overloaded version of storeTestMetrics for backward compatibility.

File writeResultsToFile(String testFileSuffix, String testHeaderName, Map<String, String> metrics, File resultsFile)

Write metrics to a file.

Public constructors

MetricUtility

public MetricUtility ()

Public methods

aggregateDimensionalMetricsAndWriteToFile

public File aggregateDimensionalMetricsAndWriteToFile (List<MetricUtility.DimensionalIterationData> iterationDataList, 
                Set<Integer> percentiles, 
                String testIterationSeparator)

Reads all stored dimensional metric report files, aggregates the raw values, computes statistics, and writes a new aggregated report file.

Parameters
iterationDataList List

percentiles Set: The percentiles to compute.

testIterationSeparator String: The separator for test iterations.

Returns
File A File containing the aggregated report, or null if no aggregation was performed.

aggregateMetrics

public Map<String, MetricMeasurement.Metric> aggregateMetrics (Map<String, MetricMeasurement.Metric> rawMetrics)

Aggregate comma separated metrics.

Parameters
rawMetrics Map: metrics collected during the test run.

Returns
Map<String, MetricMeasurement.Metric> aggregated metrics.

aggregateStoredTestMetricsAndWriteToFile

public File aggregateStoredTestMetricsAndWriteToFile (String fileName)

Aggregate the metrics collected from multiple iterations of the test and write the aggregated metrics to a test result file.

Parameters
fileName String: file name to use while writing the metrics.

Returns
File

buildMetricFilterPatterns

public void buildMetricFilterPatterns (Set<String> strictIncludeRegEx)

Build regular expression patterns to filter the metrics.

Parameters
strictIncludeRegEx Set

filterMetrics

public Map<String, MetricMeasurement.Metric> filterMetrics (Map<String, MetricMeasurement.Metric> parsedMetrics)

Filter the metrics that matches the pattern.

Parameters
parsedMetrics Map

Returns
Map<String, MetricMeasurement.Metric>

getStats

public static Map<String, Double> getStats (List<Double> values, 
                Set<Integer> percentiles, 
                int testIterations)

Compute the stats from the give list of values.

Parameters
values List: raw values to compute the aggregation.

percentiles Set: stats to include in the final metrics.

testIterations int: number of iterations to use as the divisor for the mean. If 0, mean is calculated using the size of the 'values' list.

Returns
Map<String, Double> aggregated values.

getTestIterations

public Map<String, List<MetricUtility.IterationData>> getTestIterations ()

Returns
Map<String, List<MetricUtility.IterationData>>

isAllDoubleValues

public static boolean isAllDoubleValues (List<String> rawValues)

Checks if all the values in the list are double values.

Parameters
rawValues List: list of values to check.

Returns
boolean true if all the values are double values, false otherwise.

setIterationSeparator

public void setIterationSeparator (String separator)

Parameters
separator String

setMetricsUseForTestIterations

public void setMetricsUseForTestIterations (Set<String> metricsUseForTestIterations)

Sets the regular expressions for metrics that should use passed test iterations for mean calculation during aggregation.

Parameters
metricsUseForTestIterations Set: A set of regular expression strings.

setPercentiles

public void setPercentiles (Set<Integer> percentiles)

Parameters
percentiles Set

storeTestMetrics

public void storeTestMetrics (TestDescription testDescription, 
                Map<String, MetricMeasurement.Metric> testMetrics, 
                boolean testFailed)

Used for storing the individual test metrics and use it for aggregation.

Parameters
testDescription TestDescription: contains the test details like class name and test name.

testMetrics Map: metrics collected for the test.

testFailed boolean: whether the test has failed.

storeTestMetrics

public void storeTestMetrics (TestDescription testDescription, 
                Map<String, MetricMeasurement.Metric> testMetrics)

Overloaded version of storeTestMetrics for backward compatibility. Defaults testFailed to false.

Parameters
testDescription TestDescription

testMetrics Map

writeResultsToFile

public File writeResultsToFile (String testFileSuffix, 
                String testHeaderName, 
                Map<String, String> metrics, 
                File resultsFile)

Write metrics to a file.

Parameters
testFileSuffix String: is used as suffix in the test metric file name.

testHeaderName String: metrics will be written under the test header name.

metrics Map: to write in the file.

resultsFile File: if null create a new file and write the metrics otherwise append the test header name and metric to the file.

Returns
File file with the metric.