0

我尝试读取当前的 cpu 频率。经过一番研究,我发现了以下代码:

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

但这无济于事。Logcat 在 while 循环之前显示“aha”,但“log”似乎是空的。我看不出我做错了什么:s?

PS:抱歉英语不好。

4

1 回答 1

9

cpuinfo_max_freq 会给你最大频率而不是当前频率。还有另一个值 scaling_cur_freq(位于 /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq)将为您提供当前频率。

我访问 cpuinfo_max_freq 的方式是这样的,也许你可以把它应用到 scaling_cur_freq 上看看它是否有效?

String cpuMaxFreq = "";
    RandomAccessFile reader = new RandomAccessFile("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
    cpuMaxFreq = reader.readLine();
    reader.close();
于 2013-11-08T12:18:14.277 回答