Android cpu cores reported in /proc/stat

前端 未结 4 1489
遇见更好的自我
遇见更好的自我 2020-12-10 00:32

I am developing an Android application that shows the CPU load per core and memory consumption. For CPU load I am reading /proc/stat and for memory -> /proc/meminfo. However

4条回答
  •  萌比男神i
    2020-12-10 00:42

    The answers of @Torch2424 and @Andre are ok but for my uses they lack several things:

    • I don't want to put a sleep in between the two poll. I prefer to get CPU usage since last function call and decide elsewhere when to call cpuusage function.
    • I think there is a bug in how it counts the cores usage: when a core goes offline it doesn't always assign the core result to the right location of the prev core array.
    • I need a function that returns the global CPU usage.

    Here is the code that hopefully fix correctly this: available as a class or as a simple app.

提交回复
热议问题