I'm trying to write an Android app that gathers usage statistics of the device (just to learn about Android development, and how things work, I'm pretty new). What I'm trying to get right now is the frequency of the cores of my device (it has 4 cores).
I'm trying to do
cat /sys/devices/system/cpu/cpu*/cpufreq/cpuinfo_cur_freq
OR
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_cur_freq
but after getting the value from cpu0, it doesn't seem to work. I'm not crashing the app, but I have tried a bunch of things, including messing around in the terminal, where it is telling me I am giving it an invalid argument. I'll include the code below, if anyone could help, you'd be awesome!
try {
//Process process = Runtime.getRuntime().exec("su");
RandomAccessFile reader = new RandomAccessFile
("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq", "r");
String load = reader.readLine();
freqs[0] = Integer.parseInt(load);
reader = new RandomAccessFile
("/sys/devices/system/cpu/cpu1/cpufreq/scaling_cur_freq", "r");
load = reader.readLine();
freqs[1] = Integer.parseInt(load);
reader = new RandomAccessFile
("/sys/devices/system/cpu/cpu2/cpufreq/scaling_cur_freq", "r");
load = reader.readLine();
freqs[2] = Integer.parseInt(load);
reader = new RandomAccessFile
("/sys/devices/system/cpu/cpu3/cpufreq/scaling_cur_freq", "r");
load = reader.readLine();
freqs[3] = Integer.parseInt(load);
//A for loop I had tried and failed to implement
/*RandomAccessFile reader = null;
for (i = 0; i < cores; i++){
reader = new RandomAccessFile("/sys/devices/system/cpu/cpu" + i
+ "/cpufreq/cpuinfo_cur_freq", "r");
String load = reader.readLine();
freqs[i] = Integer.parseInt(load);
}*/
} catch (IOException ex) {
ex.printStackTrace();
}
The core0 freq looks correct, the rest read 0, thanks again!