public class

CpuStatsCollector

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

Class Overview

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. 
[Expand]
Inherited Constants
From class java.lang.Thread
Public Constructors
CpuStatsCollector(ITestDevice testDevice)
CpuStatsCollector(ITestDevice testDevice, int delay)
Create a CpuStatsCollector with a delay specified.
Public Methods
synchronized 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.
synchronized boolean isCancelled()
Gets whether the cpustats command is canceled.
void logToFile(File logFile)
Specify a file to log output to.
void run()
[Expand]
Inherited Methods
From class java.lang.Thread
From class java.lang.Object
From interface java.lang.Runnable

Public Constructors

public CpuStatsCollector (ITestDevice testDevice)

Parameters
testDevice The test device

public CpuStatsCollector (ITestDevice testDevice, int delay)

Create a CpuStatsCollector with a delay specified.

Parameters
testDevice The test device
delay The delay time in seconds

Public Methods

public synchronized void cancel ()

Cancels the cpustats command.

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

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

Returns
  • a mapping of labels to lists of CpuStatsCollector.CpuStats instances. The labels will include "Total" and "cpu0"..."cpuN" for each CPU on the device.

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

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

Parameters
cpuStats the list of CpuStatsCollector.CpuStats
Returns
  • The average estimated MHz in MHz.

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

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

Parameters
cpuStats the list of CpuStatsCollector.CpuStats
Returns
  • The average usage as a percentage (0 to 100).

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 the list of CpuStatsCollector.CpuStats
Returns
  • The average usage as a percentage (0 to 100).

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

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

Parameters
cpuStats the list of CpuStatsCollector.CpuStats
Returns
  • The average usage as a percentage (0 to 100).

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

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

Parameters
cpuStats the list of CpuStatsCollector.CpuStats
Returns
  • The average usage as a percentage (0 to 100).

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

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

Parameters
cpuStats the list of CpuStatsCollector.CpuStats
Returns
  • The average used MHz as a percentage (0 to 100).

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 the list of CpuStatsCollector.CpuStats
Returns
  • The average usage as a percentage (0 to 100).

public synchronized boolean isCancelled ()

Gets whether the cpustats command is canceled.

Returns
  • if the cpustats command is canceled.

public void logToFile (File logFile)

Specify a file to log output to.

Parameters
logFile the file to log output to.

public void run ()