3

My actual goal is to the calculate CPU load of the phone. But this seems not possible on Android 8+ devices. Because the access to /proc/stat is restricted on API 26.

So I am trying to calculate my app's CPU load in my app. This can also work on my case. I can access and read /proc/self/stat without any problem. But every post I saw on the internet for calculations needed proc/uptime. Unfortunately, it is also restricted. So the question is the CPU load calculations possible anymore?

Mustafa Kuloğlu
  • 1,122
  • 1
  • 8
  • 16

1 Answers1

1

This is how neofetch does it, at least in the version I'm using 7.1.0:

cpu_usage="$(ps aux | awk 'BEGIN {sum=0} {sum+=$3}; END {print sum}')"
cpu_usage="$((${cpu_usage/\.*} / ${cores:-1}))"
timblaktu
  • 375
  • 3
  • 11