Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to limit Android CPU usage?

Tags:

android

I have a phone that is weak, and I want to do some calculations that takes a lot of CPU time.

How do I monitor the app's CPU usage, so I can dynamically set thread priority or executor max threads?

like image 764
theAnonymous Avatar asked May 21 '26 19:05

theAnonymous


1 Answers

Never implemented this before, but got really interested in your question and did some digging.

So from roman10:

private String getInfo() {
StringBuffer sb = new StringBuffer();
sb.append("abi: ").append(Build.CPU_ABI).append("n");
if (new File("/proc/cpuinfo").exists()) {
    try {
        BufferedReader br = new BufferedReader(new FileReader(new File("/proc/cpuinfo")));
        String aLine;
        while ((aLine = br.readLine()) != null) {
            sb.append(aLine + "n");
        }
        if (br != null) {
            br.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } 
}
return sb.toString();
}

There's also this post that might help you out.

like image 125
Charles Li Avatar answered May 26 '26 04:05

Charles Li



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!