Jak uzyskać wykorzystanie każdego rdzenia procesora na Androida

Opracowuję widżet na Androida, który wyświetla wiele przydatnych informacji.

Próbuję zmodyfikować tę metodę, aby zwrócić procent wykorzystania jednego rdzenia procesora, aby mieć procent wykorzystania każdego rdzenia !!!

W moim HTC One X mam „/ proc / stat”:

cpu  183549 10728 236016 3754379 7530 41 1013 0 0 0
cpu0 141962 5990 196956 720894 3333 41 970 0 0 0
cpu1 23400 2550 23158 980901 2211 0 23 0 0 0
cpu2 13602 1637 12561 1019126 1216 0 18 0 0 0
cpu3 4585 551 3341 1033458 770 0 2 0 0 0

Korzystam z tej metody, aby zwrócić procent wykorzystania całego rdzenia procesora.

public float readUsage() {
    try {

        RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
        String load = reader.readLine();


        String[] toks = load.split(" ");

        long idle1 = Long.parseLong(toks[5]);
        long cpu1 = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
              + Long.parseLong(toks[6]) + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        try {
            Thread.sleep(800);
        } catch (Exception e) {}

        reader.seek(0);
        load = reader.readLine();
        reader.close();

        toks = load.split(" ");

        long idle2 = Long.parseLong(toks[5]);
        long cpu2 = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
            + Long.parseLong(toks[6]) + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        return (float)(cpu2 - cpu1) / ((cpu2 + idle2) - (cpu1 + idle1));

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return 0;
} 

Próbuję uzyskać dostęp do cpu1, ale to nie działa:

public float readUsageCPU0() {
    try {

        RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
        reader.seek(0);
        String load = reader.readLine();
        load = reader.readLine();
        load = reader.readLine();


        String[] toks = load.split(" ");

        long idle1 = Long.parseLong(toks[5]);
        long cpu1 = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
              + Long.parseLong(toks[6]) + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        try {
            Thread.sleep(500);
        } catch (Exception e) {}

        reader.seek(0);
        load = reader.readLine();
        load = reader.readLine();
        load = reader.readLine();
        reader.close();

        toks = load.split(" ");

        long idle2 = Long.parseLong(toks[5]);
        long cpu2 = Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[4])
            + Long.parseLong(toks[6]) + Long.parseLong(toks[7]) + Long.parseLong(toks[8]);

        return (float)(cpu2 - cpu1) / ((cpu2 + idle2) - (cpu1 + idle1));

    } catch (IOException ex) {
        ex.printStackTrace();
    }

    return 0;
}

Pozwala to odczytać jedną linię, a kursor pozostanie na końcu linii:

String load = reader.readLine();

Próbowałem więc użyć go dwa razy, aby użyć CPU0 i trzeciego, aby uzyskać CPU1. Ale wynik zawsze wynosi 0 lub 100 ... Nie rozumiem!

Czy używam właściwej drogi? Czy korzystam z właściwego pliku? Czy ten wynik jest normalny?

Proszę pomóż !!!

questionAnswers(3)

yourAnswerToTheQuestion