Reputation: 1
I try to read the current cpu frequency. After some research i've found the following code:
public String ReadCPUMhz2() throws IOException
{
String[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"};
ProcessBuilder cmd;
cmd = new ProcessBuilder(args);
Process process = null;
process = cmd.start();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
StringBuilder log=new StringBuilder();
String line;
Log.d("test","aha");
while ((line = bufferedReader.readLine()) != null) {
log.append(line + "\n");
}
Log.d("test",log.toString());
return log.toString();
}
But that doesnt do anything. Logcat shows the "aha" before the while-loop, but "log" seems to be empty. I can't see what i did wrong :s ?
PS: Sorry for the bad English.
Upvotes: 0
Views: 5664
Reputation: 713
cpuinfo_max_freq will give you the maximum frequency not the current one. There is another value, scaling_cur_freq (found at /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq) that will give you the current frequency.
The way I access cpuinfo_max_freq is this, maybe you could apply this to scaling_cur_freq and see if it works?
String cpuMaxFreq = "";
RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
cpuMaxFreq = reader.readLine();
reader.close();
Upvotes: 9