I'm trying to have my app show time spent by the CPU at each frequency. The main issue is when a CPU goes offline (due to hotplugging or deep sleep) the file /CPUN/cpufreq/stats/time_in_state
gets removed and times reset to all 0s.
So this limits me to only be able to show the times on CPU 0.
What I've Tried
- Use FileObserver service to monitor the creation/deletion of the file This should work in theory but for whatever reason when the device goes into deep sleep it fails to report the deleting of those files. Same for when waking, the files must be created before the FileObserver is able to resume monitoring.
So short of a wakelock, is it at all possible to monitor the times from those CPUs that go offline, clearing time_in_state
files?
Try this:
You can use a for loop to get all CPUs. To get Number of available use:
int cores = Runtime.getRuntime().availableProcessors()
So the for goes from
0
tocores - 1