4

I'm looking at the out of the following command "adb shell dumpsys cpuinfo" where I want to know if these reported values are averages over previous time ?

    D:\Android_Dev\Android_sdk\platform-tools>adb shell dumpsys cpuinfo
Load: 4.03 / 3.43 / 2.44
CPU usage from 23770ms to 16630ms ago:
  58% 1844/logd: 58% user + 0% kernel / faults: 3 minor
  50% 3895/com.google.android.wearable.app:ui: 41% user + 9.3% kernel / faults: 1798 minor
  26% 1864/adbd: 2.8% user + 23% kernel / faults: 1243 minor
  22% 4880/logcat: 7.8% user + 15% kernel
  9.7% 7834/kworker/0:2: 0% user + 9.7% kernel
  4.9% 2198/system_server: 2.6% user + 2.2% kernel / faults: 76 minor

My questions are as follows:

  1. what does faults represent here ?
  2. what does these percentage values represent because they don't add up to 100 ?
  3. are these percentage values averages of the respective processes such as as 58% for logd?
  4. CPU usage from 23770ms to 16630ms ago: what does this mean ? does it mean that these values are the average from last 23 to 16 seconds ?
utengr
  • 3,225
  • 3
  • 29
  • 68
  • Possible duplicate of [interpreting dumpsys cpuinfo](http://stackoverflow.com/questions/24612982/interpreting-dumpsys-cpuinfo) – Toris Oct 21 '16 at 22:55
  • 1
    @Toris Its not a duplicate of that question. I have already that. There is no explanation over there for all these 4 questions. I have thoroughly gone through the links mentioned there. That's why I removed the load part as its explained there. – utengr Oct 21 '16 at 22:58

1 Answers1

9
adb shell dumpsys cpuinfo

shows info from /proc/stat and /proc/(pid)/stat

1.what does faults represent here ?

Page faults.
"minor" for minor faults.

from ProcessCpuTracker.java

collectStats(...) {
  ...
  final long[] procStats = mProcessStatsData;
  if (!Process.readProcFile(st.statFile.toString(),
  PROCESS_STATS_FORMAT, null, procStats, null)) {
  continue;
  }
  ...
  final long minfaults = procStats[PROCESS_STAT_MINOR_FAULTS];
  final long majfaults = procStats[PROCESS_STAT_MAJOR_FAULTS];
}

private static final int[] PROCESS_STATS_FORMAT = new int[] {
  ...
  PROC_SPACE_TERM|PROC_OUT_LONG,                  // 10: minor faults
  ...
  PROC_SPACE_TERM|PROC_OUT_LONG,                  // 12: major faults
  ...
};

They are /proc/(pid)/stat data[9] and data[11].


2.they don't add up to 100

http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages
(Linked page from interpreting dumpsys cpuinfo)

With multi-processor system, sum can be more than 100%.


3.are these percentage values averages of the respective processes

from ProcessCpuTracker.java

printProcessCPU(...) {
  ...
  printRatio(pw, user+system+iowait+irq+softIrq, totalTime);
  ...
}

2nd parameter(user+...) / 3rd parameter(totalTime) is printed.


4.CPU usage from 23770ms to 16630ms ago

Times are based on times when stat data cached by ProcessCpuTracker is updated.

from ProcessCpuTracker.java

update() {
  final long nowUptime = SystemClock.uptimeMillis();
  ...
  mLastSampleTime = mCurrentSampleTime;
  mCurrentSampleTime = nowUptime;
  ...
}

[Related sources]
https://android.googlesource.com/platform/frameworks/native/+/master/cmds/dumpsys/dumpsys.cpp
main() => service->dump()

https://github.com/android/platform_frameworks_base/blob/master/services/core/java/com/android/server/am/ActivityManagerService.java
CpuBinder.dump() is called
mProcessCpuThread updates stat cache. (updateCpuStatsNow() is called)

https://github.com/android/platform_frameworks_base/blob/master/core/java/com/android/internal/os/ProcessCpuTracker.java
printCurrentLoad() prints CPU load
printCurrentState() prints per process stats

Community
  • 1
  • 1
Toris
  • 2,348
  • 13
  • 16
  • Thanks a lot Toris. That's what I was looking for. – utengr Oct 23 '16 at 23:45
  • I am still wondering if I can somehow change the time of these states such last dumpsys for the last 5 minutes etc. – utengr Oct 23 '16 at 23:49
  • @zub12 if dumpsys has such option, it's the best, but calculate from outputs or take info from /proc/(pid)/stat is the answer for now, I think. – Toris Oct 24 '16 at 00:30