performance - How get average CPU usage in Android? -


I want to get the average CPU usage per 100ms or 500ms. I have tried using top and dumpsys cpuinfo , but none of them tells me the average usage or timestamp. So how do I get the average usage?
I have seen that there is some CPU usage information in / proc / stat , can I calculate the average CPU usage by using / proc / stat Am I

This has already been answered on SO:

  private Float read use (try {try {RandomAccessFile reader = new RandomAccessFile ("/ proc / stat", "r"); String load = reader Readline (); String [] tox = load. Split (""); Long idle1 = long.parsling (tox [5]); Long CPU 1 = Long. Parslong (Toux [2]) + Long. Pars Long (Tox [3]) + Long.Perselong (Tox [4]) + Long.Parceleong (Tox [6]) + Long.Presse Long (Token [7]) + Long.paras long (tox [8]); Try {Thread.sleep (360); } Hold (exception e) {} reader.sec (0); Load = reader.readLine (); reader.close (); Tox = load. Split (""); Long idle2 = long.parsling (tox [5]); Long CPU 2 = Long Parselong (Toux [2]) + Long.Paras Long (Toux [3]) + Long.Perselong (Toco [4]) + Long.Prescent Long (Toux [6]) + Long.Pras Long (Taco [7]) + Long.paras long (tox [8]); Return (Float) (CPU2 - CPU1) / ((CPU-2 + Idol 2) - (CPU 1 + Idol 1)); } Hold (IOException pre) {ex.printStackTrace (); } Return 0; }   

You can view it for more information

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -