CpuStatsCollector

public class CpuStatsCollector
extends Thread

java.lang.Object
   ↳ java.lang.Thread
     ↳ com.android.tradefed.device.CpuStatsCollector


Helper class which runs cpustats continuously on an ITestDevice and parses the output.

Provides a method to record the output of cpustats and get all the cpu usage measurements as well methods for performing calculations on that data to find the mean of the cpu workload, the approximate cpu frequency, and the percentage of used cpu frequency.

This is meant to be a replacement for TopHelper, which does not provide stats about cpu frequency and has a higher overhead due to measuring processes/threads.

The cpustats command was added in the Jellybean release, so this collector should only be used for new tests.

See also:

Summary

Nested classes

class CpuStatsCollector.CpuStats

Class for holding parsed output data for a single cpustats output. 

class CpuStatsCollector.CpuStatsReceiver

Receiver which parses the output from cpustats and optionally logs to a file. 

enum CpuStatsCollector.TimeCategory

Used to distinguish between the different CPU time categories. 

Public constructors

CpuStatsCollector(ITestDevice testDevice)

Create a CpuStatsCollector.

CpuStatsCollector(ITestDevice testDevice, int delay)

Create a CpuStatsCollector with a delay specified.

Public methods

void cancel()

Cancels the cpustats command.

Map<String, List<CpuStatsCollector.CpuStats>> getCpuStats()

Get the mapping of labels to lists of CpuStatsCollector.CpuStats instances.

static Double getEstimatedMhzMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the estimated MHz for a list of CpuStatsCollector.CpuStats.

static Double getIowPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the iow CPU usage for a list of CpuStatsCollector.CpuStats.

static Double getIrqPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the IRQ and SIRQ CPU usage for a list of CpuStatsCollector.CpuStats.

static Double getSystemPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the system CPU usage for a list of CpuStatsCollector.CpuStats.

static Double getTotalPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the total CPU usage for a list of CpuStatsCollector.CpuStats.

static Double getUsedMhzPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the used MHz for a list of CpuStatsCollector.CpuStats.

static Double getUserPercentageMean(List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the user and nice CPU usage for a list of CpuStatsCollector.CpuStats.

boolean isCancelled()

Gets whether the cpustats command is canceled.

void logToFile(File logFile)

Specify a file to log output to.

void run()

Public constructors

CpuStatsCollector

public CpuStatsCollector (ITestDevice testDevice)

Create a CpuStatsCollector.

Parameters
testDevice ITestDevice: The test device

CpuStatsCollector

public CpuStatsCollector (ITestDevice testDevice, 
                int delay)

Create a CpuStatsCollector with a delay specified.

Parameters
testDevice ITestDevice: The test device

delay int: The delay time in seconds

Public methods

cancel

public void cancel ()

Cancels the cpustats command.

getCpuStats

public Map<String, List<CpuStatsCollector.CpuStats>> getCpuStats ()

Get the mapping of labels to lists of CpuStatsCollector.CpuStats instances.

Returns
Map<String, List<CpuStatsCollector.CpuStats>> a mapping of labels to lists of CpuStatsCollector.CpuStats instances. The labels will include "Total" and "cpu0"..."cpuN" for each CPU on the device.

getEstimatedMhzMean

public static Double getEstimatedMhzMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the estimated MHz for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average estimated MHz in MHz.

getIowPercentageMean

public static Double getIowPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the iow CPU usage for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average usage as a percentage (0 to 100).

getIrqPercentageMean

public static Double getIrqPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the IRQ and SIRQ CPU usage for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average usage as a percentage (0 to 100).

getSystemPercentageMean

public static Double getSystemPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the system CPU usage for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average usage as a percentage (0 to 100).

getTotalPercentageMean

public static Double getTotalPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the total CPU usage for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average usage as a percentage (0 to 100).

getUsedMhzPercentageMean

public static Double getUsedMhzPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the used MHz for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average used MHz as a percentage (0 to 100).

getUserPercentageMean

public static Double getUserPercentageMean (List<CpuStatsCollector.CpuStats> cpuStats)

Get the mean of the user and nice CPU usage for a list of CpuStatsCollector.CpuStats.

Parameters
cpuStats List: the list of CpuStatsCollector.CpuStats

Returns
Double The average usage as a percentage (0 to 100).

isCancelled

public boolean isCancelled ()

Gets whether the cpustats command is canceled.

Returns
boolean if the cpustats command is canceled.

logToFile

public void logToFile (File logFile)

Specify a file to log output to.

Parameters
logFile File: the file to log output to.

run

public void run ()