this is my first time asking a question here. I tried to be well researched, so I apologize in advance if I overlooked a post for this question before. I'm looking to see if I can get the usage statistics for my app while it's running. I'm running some relatively high performance programs, and I'm interested in seeing how well the computing is being distributed between the cores (and displaying this information in the program itself).

Again, sorry if this post is riddled with ignorance!

有帮助吗?

解决方案

You can check the number of CPU cores by looking at the files under the directory - /sys/devices/system/cpu/. This is also possible on non-rooted phones. Here is a function that can give you the number of cores on the device -

    public int getNumOfCpus() {

    class CPUFilter implements FileFilter {
        @Override
        public boolean accept(File pathname) {
            // Check if filename is "cpu0", "cpu1,...
            if (Pattern.matches("cpu[0-9]", pathname.getName())) {
                return true;
            }
            return false;
        }
    }

    try {
        // Get directory containing CPU info
        File dir = new File("/sys/devices/system/cpu/");
        File[] files = dir.listFiles(new CPUFilter());
        // Return the number of cores 
        return files.length;
    } catch (Exception e) {
        e.printStackTrace();
        return 1;
    }

}

You can then get the CPU utilization per core by modifying function mentioned in the answer here - Get Memory Usage in Android

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top