【问题标题】:How do I get my CPU Governor in an Android App?如何在 Android 应用程序中获取我的 CPU 调控器?
【发布时间】:2017-02-08 06:44:12
【问题描述】:
我正在制作一个行为不同的应用,具体取决于 CPU 调控器的设置(例如性能、节能等)。但是,我不确定如何在应用程序本身中获取其当前设置。有谁知道在 java 类中访问它的命令是什么?
(要在手机上查看,请转至Settings->Performance->Profile 和Settings->Performance->Processor->CPU Governor。)
【问题讨论】:
标签:
java
android
performance
cpu
processor
【解决方案1】:
显然,信息存储在/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 中。如果您阅读该文件,您将得到它的那种调速器。您也可以通过拉取文件 /proc/cpuinfo 来获取更多 cpu 信息,但如果您这样做,则调控器不包含在其中。
private String getGovernor() {
StringBuffer sb = new StringBuffer();
//String file = "/proc/cpuinfo"; // Gets most cpu info (but not the governor)
String file = "/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor"; // Gets governor
if (new File(file).exists()) {
try {
BufferedReader br = new BufferedReader(new FileReader(new File(file)));
String aLine;
while ((aLine = br.readLine()) != null)
sb.append(aLine + "\n");
if (br != null)
br.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}