Is there any Java API for that? How can I read this information.
How to read cpu frequency on android device [closed]
To have frequency on Android, just read these special files in /sys directory:
#cat "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"
#cat "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"
You will have current, min and max Frequency allowed.
Awesome answer Ellis, you really helped me a lot. One thing that I found in investigating this was that scaling_cur_freq is not necessarily the current CPU frequency, but rather what the kernel thinks the frequency is. To get the real frequency, you need root access to read cpuinfo_cur_freq. Also, gaining root access allows you to set the cpu speed, which is quite useful for profiling under best/worst case conditions. –
Hood
Hummm It seems to me that even with root access you can't edit the cpuinfo_* files.. –
Uruguay
How can we get CPU load or utilization? –
Build
How can these files be read from within an app? –
Lashelllasher
I notice subdirectory
policyX
under /sys/devices/system/cpu/cpufreq/
, what is that? –
Jablonski not MHz, but at least something. bogoMIPS value can be useful for you.
private String ReadCPUinfo()
{
ProcessBuilder cmd;
String result="";
try{
String[] args = {"/system/bin/cat", "/proc/cpuinfo"};
cmd = new ProcessBuilder(args);
Process process = cmd.start();
InputStream in = process.getInputStream();
byte[] re = new byte[1024];
while(in.read(re) != -1){
System.out.println(new String(re));
result = result + new String(re);
}
in.close();
} catch(IOException ex){
ex.printStackTrace();
}
return result;
}
Thanks, but is there any way to convert it to MHz or read it somewhere? –
Beagle
Any reason you're not just opening /proc/cpuinfo as a file and reading it directly? –
Saponify
michael, read a wiki page about bogoMIPS, there's a formula. fadden, I'm not sure that file could be simply read from java, just found this code laying around. –
Darendaresay
If you are interested in how long your system spent in what state, check out the file
/sys/devices/system/cpu/cpu0/cpufreq/stats/time_in_state
I'm not sure, whether root access is necessary for that.
Root access seems not to be neccesary, unlike for
cpuinfo_cur_freq
. –
Nafis © 2022 - 2024 — McMap. All rights reserved.