How to find CPU load of any Android device programmatically

后端 未结 4 1270
南方客
南方客 2020-12-05 20:51

I want to have the same details in my android app. Anybody having any solution?

4条回答
  •  隐瞒了意图╮
    2020-12-05 21:49

    Use this function to get CPU details.

    public static String getCPUDetails(){
    
        /*
         *Created By Atiar Talukdar
         * 01/01/2018
         * contact@atiar.info
         */
    
        ProcessBuilder processBuilder;
        String cpuDetails = "";
        String[] DATA = {"/system/bin/cat", "/proc/cpuinfo"};
        InputStream is;
        Process process ;
        byte[] bArray ;
        bArray = new byte[1024];
    
        try{
            processBuilder = new ProcessBuilder(DATA);
    
            process = processBuilder.start();
    
            is = process.getInputStream();
    
            while(is.read(bArray) != -1){
                cpuDetails = cpuDetails + new String(bArray);   //Stroing all the details in cpuDetails
            }
            is.close();
    
        } catch(IOException ex){
            ex.printStackTrace();
        }
    
        return cpuDetails;
    }
    

    Expected Output like - (I Used Emulator to generate output)

    vendor_id   : GenuineIntel
    cpu family  : 6
    model       : 61
    model name  : Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    stepping    : 4
    cpu MHz     : 2699.883
    cache size  : 3072 KB
    physical id : 0
    siblings    : 2
    core id     : 0
    cpu cores   : 1
    apicid      : 0
    initial apicid  : 0
    fpu     : yes
    fpu_exception   : yes
    cpuid level : 13
    wp      : yes
    flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat 
    pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm 
    constant_tsc pebs bts rep_good nopl eagerfpu pni pclmulqdq dtes64 ds_cpl ssse3 
    sdbg fma cx16 xtpr pdcm movbe popcnt aes xsave avx f16c rdrand hypervisor 
    lahf_lm retpoline fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms xsaveopt
    bugs        : cpu_meltdown spectre_v1 spectre_v2
    bogomips    : 5399.76
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 39 bits physical, 48 bits virtual
    power management:
    
    processor   : 1
    vendor_id   : GenuineIntel
    cpu family  : 6
    model       : 61
    model name  : Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    stepping    : 4
    cpu MHz     : 2699.883
    cache size  : 3072 KB
    physical id : 0
    siblings    : 2
    core id     : 0
    cpu cores   : 1
    apicid      : 1
    initial apicid  : 1
    fpu     : yes
    fpu_exception   : yes
    cpuid level : 13
    wp      : yes
    flags       : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat 
    pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx lm 
    constant_tsc pebs bts rep_good nopl eagerfpu pni pclmulqdq dtes64 ds_cpl ssse3 
    sdbg fma cx16 xtpr pdcm movbe popcnt aes xsave avx f16c rdrand hypervisor 
    lahf_lm retpoline fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms xsaveopt
    
    bugs        : cpu_meltdown spectre_v1 spectre_v2
    bogomips    : 5399.76
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 39 bits physical, 48 bits virtual
    power management:
    
    s       : cpu_meltdown spectre_v1 spectre_v2
    bogomips    : 5399.76
    clflush size    : 64
    cache_alignment : 64
    address sizes   : 39 bits physical, 48 bits virtual
    power management:
    
    processor   : 1
    vendor_id   : GenuineIntel
    cpu family  : 6
    model       : 61
    model name  : Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
    stepping    : 4
    cpu MHz     : 2699.883
    cache size  : 3
    

提交回复
热议问题