public final class CpuMonitor
extends java.lang.Object
CPUs in Android are often "offline", and while this of course means 0 Hz as current frequency, in this state we cannot even get their nominal frequency. We therefore tread carefully, and allow any CPU to be missing. Missing CPUs are assumed to have the same nominal frequency as any close lower-numbered CPU, but as soon as it is online, we'll get their proper frequency and remember it. (Since CPU 0 in practice always seem to be online, this unidirectional frequency inheritance should be no problem in practice.)
Caveats: o No provision made for zany "turbo" mode, common in the x86 world. o No provision made for ARM big.LITTLE; if CPU n can switch behind our back, we might get incorrect estimates. o This is not thread-safe. To call asynchronously, create different CpuMonitor objects.
If we can gather enough info to generate a sensible result, sampleCpuUtilization returns true. It is designed to never through an exception.
sampleCpuUtilization should not be called too often in its present form,
since then deltas would be small and the percent values would fluctuate and
be unreadable. If it is desirable to call it more often than say once per
second, one would need to increase SAMPLE_SAVE_NUMBER and probably use
Queue Known problems:
1. Nexus 7 devices running Kitkat have a kernel which often output an
incorrect 'idle' field in /proc/stat. The value is close to twice the
correct value, and then returns to back to correct reading. Both when
jumping up and back down we might create faulty CPU load readings.
| Constructor and Description |
|---|
CpuMonitor() |
| Modifier and Type | Method and Description |
|---|---|
int |
getCpuAvg3() |
int |
getCpuAvgAll() |
int |
getCpuCurrent() |
int |
getTemp(int ix) |
float |
getTempAve() |
int |
getTempNum() |
boolean |
sampleCpuUtilization()
Re-measure CPU use.
|
public boolean sampleCpuUtilization()
public int getCpuCurrent()
public int getCpuAvg3()
public int getCpuAvgAll()
public int getTempNum()
public int getTemp(int ix)
public float getTempAve()