1. dumpsys meminfo PKG_NAME
...
App Summary
Pss(KB)
------
Java Heap: 42868 <--
Native Heap: 52268 <--
Code: 23608
Stack: 96
Graphics: 5084
Private Other: 5620
System: 14900
TOTAL: 144444 <-- TOTAL SWAP PSS: 130
2. in java code
https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/os/Debug.java#640
// this is the value source of dumpsys meminfo
.
Debug.MemoryInfo memInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memInfo);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
String javaMem = memInfo.getMemoryStat("summary.java-heap");
String natiMem = memInfo.getMemoryStat("summary.native-heap");
String totalMem = memInfo.getMemoryStat("summary.total-pss");
//msg2 += "\n" + String.format("%s %s %s", javaMem, natiMem, totalMem);
msg2 += "\n\n"+String.format("java %8s\nnati %8s\ntotal %8s",
formatMB(Integer.parseInt(javaMem)), formatMB(Integer.parseInt(natiMem)), formatMB(Integer.parseInt(totalMem))
);
}
...
String formatMB(double KB){
return String.format("%.1f MB", KB/1024);
}
The other api need lots of calculate,
// you can read them in Debug.java src file.
This is the closest to dumpsys meminfo
or android studio monitor
.