簡體   English   中英

如何在Android App中獲得CPU調速器?

[英]How do I get my CPU Governor in an Android App?

我正在制作一個根據CPU調控器設置為不同而表現不同的應用程序(例如,性能,節能等)。 但是,我不確定如何在應用程序本身中獲取其當前設置。 有誰知道在Java類中訪問該命令的命令是什么?

(要在手機上查看它,請轉到Settings->Performance->Profile ”以及“ Settings->Performance->Processor->CPU Governor 。)

因此,顯然該信息存儲在/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor 如果讀入文件,您將得到它的那種調控器。 您也可以通過拉文件/proc/cpuinfo來獲取更多cpu信息,但是如果您這樣做,則不包含/proc/cpuinfo器。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM