theAnonymous
theAnonymous

Reputation: 1804

How to limit Android CPU usage?

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?

Upvotes: 3

Views: 2950

Answers (1)

Charles Li
Charles Li

Reputation: 1925

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.

Upvotes: 1

Related Questions