How to read cpu frequency on android device [closed]

試著忘記壹切 提交于 2020-01-08 20:06:10

问题


Is there any Java API for that? How can I read this information.


回答1:


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.




回答2:


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;
 }



回答3:


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.



来源:https://stackoverflow.com/questions/3021054/how-to-read-cpu-frequency-on-android-device

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!