如何在Android设备上读取CPU频率

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3021054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:20:26  来源:igfitidea点击:

How to read cpu frequency on android device

androidapicpu

提问by michael

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

是否有任何 Java API?我怎样才能阅读这些信息。

回答by Ellis

To have frequency on Android, just read these special files in /sys directory:

要在 Android 上获得频率,只需读取 /sys 目录中的这些特殊文件:

#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.

您将拥有当前、最小和最大频率允许。

回答by zed_0xff

not MHz, but at least something. bogoMIPSvalue can be useful for you.

不是 MHz,但至少是某些东西。bogoMIPS值对您很有用。

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

回答by Michael Kopp

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 访问权限。