I develop an Android application to get the device information. For the Total CPU usage currently, I am using the code in this thread.
But I wanted is the CPU frequency for each core. So I tried to modify the code to get the usage of cpu0. But I did not succeed. So, anyone has this problem. How did you overcome it?
UPDATE
I tried achieved this by getting the values from "scaling_cur_freq" file. This file contains the current frequency of each core. So here's my code, in-case anyone needs it.
try {
double currentFreq;
RandomAccessFile readerCurFreq;
readerCurFreq = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
String curfreg = readerCurFreq.readLine();
currentFreq = Double.parseDouble(curfreg) / 1000;
readerCurFreq.close();
String finalfre = "Curent Frequency of Core 0 is" + currentFreq;
} catch (IOException ex) {
String finalfre = "Core is Idle";
ex.printStackTrace();
}
You can loop this through the number of cores. So that you can get the frequency for all the cores. Some times if the core is idle or stopped, this code may produce an exception. handle it, and you're good to go