Common commands for checking memory
dumpsys meminfo
Memory Index Concept Item Full Description Equivalent USS Unique Set Size PSS Proportional Set Size Of physical memory processes PSS= USS+ RSS Resident Set that contains the shared library proportionately Size Physical memory RSS= USS+ Contains shared library VSS Virtual Set Size Virtual memory VSS= RSS+ No actual physical memory is allocated
When we look at PSS, this item actually reflects how much memory the process is occupying. This directive lists the PSS of each process sorted by various metrics
- Total PSS by process
Sort by the amount of memory occupied by different processes
- Total PSS by OOM adjustment
According to the priority of the process in OOM, when the process needs to be killed to leave space, kill the process from the bottom to the top of the list
Kill process OOM priority that android/frameworks/base/services/core/Java/com/android/server/am/the ProcessList. Java
// (Generally this is something that is going to be cached, but we
// don't know the exact value in the cached range to assign yet.)
static final int UNKNOWN_ADJ = 1001;
// This is a process only hosting activities that are not visible,
// so it can be killed without any disruption.
static final int CACHED_APP_MAX_ADJ = 906;
static final int CACHED_APP_MIN_ADJ = 900;
// The B list of SERVICE_ADJ -- these are the old and decrepit
// services that aren't as shiny and interesting as the ones in the A list.
static final int SERVICE_B_ADJ = 800;
// This is the process of the previous application that the user was in.
// This process is kept above other things, because it is very common to
// switch back to the previous app. This is important both for recent
// task switch (toggling between the two top recent apps) as well as normal
// UI flow such as clicking on a URI in the e-mail app to view in the browser,
// and then pressing back to return to e-mail.
static final int PREVIOUS_APP_ADJ = 700;
// This is a process holding the home application -- we want to try
// avoiding killing it, even if it would normally be in the background,
// because the user interacts with it so much.
static final int HOME_APP_ADJ = 600;
// This is a process holding an application service -- killing it will not
// have much of an impact as far as the user is concerned.
static final int SERVICE_ADJ = 500;
// This is a process with a heavy-weight application. It is in the
// background, but we want to try to avoid killing it. Value set in
// system/rootdir/init.rc on startup.
static final int HEAVY_WEIGHT_APP_ADJ = 400;
// This is a process currently hosting a backup operation. Killing it
// is not entirely fatal but is generally a bad idea.
static final int BACKUP_APP_ADJ = 300;
// This is a process only hosting components that are perceptible to the
// user, and we really want to avoid killing them, but they are not
// immediately visible. An example is background music playback.
static final int PERCEPTIBLE_APP_ADJ = 200;
// This is a process only hosting activities that are visible to the
// user, so we'd prefer they don't disappear.
static final int VISIBLE_APP_ADJ = 100;
// This is the process running the current foreground app. We'd really
// rather not kill it!
static final int FOREGROUND_APP_ADJ = 0;
// This is a process that the system or a persistent process has bound to,
// and indicated it is important.
static final int PERSISTENT_SERVICE_ADJ = -700;
// This is a system persistent process, such as telephony. Definitely
// don't want to kill it, but doing so is not completely fatal.
static final int PERSISTENT_PROC_ADJ = -800;
// The system process runs at the default adjustment.
static final int SYSTEM_ADJ = -900;
// Special code for native processes that are not being managed by the system (so
// don't have an oom adj assigned by the system).
static final int NATIVE_ADJ = -1000;
Copy the code
- Total PSS by category
Under this label, the total memory occupied by all processes in the system for each category is counted. The specific meaning of each category is explained by APP.
- Finally, the overall memory usage information is summarized
The process under the Cached TAB of the Total PSS by OOM Adjustment list is a cache process that can reclaim memory at any time, so its memory will be counted in the Free RAM field later
You can see the memory usage of the specified process by adding -package “package name” to the command
The Dalvik Heap Size in the upper right corner represents the total Heap Size occupied by the process, and the total item in the bottom. Detailed parameter descriptions are as follows:
- Pss Total: indicates the actual memory used by a process. This method includes proportional allocation of the memory used by a shared library. If three processes share a shared library, the memory used by the shared library is evenly allocated. One thing to note about the PssTotal method is that if a process using a shared library is killed, the memory footprint of the shared library is proportionally allocated to other processes that share the library, rather than returning memory resources to the system, in which case PssTotal does not accurately represent memory returned to the system.
- Private Dirty: The size of a process’s Private Dirty page memory. This method only includes the process’s Private memory that has been modified.
- Private Clear: The size of the process’s Private clean page memory. This measure only includes the process’s Private memory that has not been modified.
- Swapped Dirty: The size of Dirty page memory Swapped, which is shared with other processes. Private Dirty + private Clean = Uss, the value is the private memory size used by a process, that is, the memory is uniquely owned by the process. This statistical method really describes the memory required to run a process and the memory released by killing a process, and is the best statistical method to suspect memory leaks. Sharing_proportion = (Pss Total – private_clean – private_dirty) /(shared_clean+shared_dirty) Memory that can be shared: swappable_pss = (sharing_proportion * shared_clean) + private_clean
- Native Heap: memory used by the local Heap, including memory allocated on the Heap by C/C++
- Dalvik Heap: the memory used by the Dalvik VM
- Dalvik Other: Allocated memory other than Dalvik and Native, including C/C++ allocated non-heap memory
- Cursor: Memory occupied by a database Cursor file
- Ashmem: Anonymous shared memory
- Stack: Memory occupied by Dalvik Stack
- Other dev: memory occupied by Other devs
- .so mmap: the memory occupied by the so library
- Jar mmap: memory occupied by the. Jar file
- Apk mmap: memory occupied by. Apk files
- .ttf mmap: memory occupied by.ttf files
- Dex mmap: indicates the memory occupied by the. Dex file
- Image mmap: Memory occupied by image files
- Code mmap: Memory occupied by code files
- Other mmap: memory occupied by Other files
- Graphics: Memory used by the GPU to use images
- GL: memory used by the GPU when drawing with GL
- Memtrack: memory used by the GPU to use multimedia and camera
- Unknown: Indicates the Unknown memory consumption
- Heap Size: the total memory Size of the Heap
- Heap Alloc: The size of memory allocated by the Heap
- Heap Free: size of memory to be allocated in the Heap
- Native Heap | Heap Size: from mallinfo usmblks won, the current process of Native Heap of maximum total allocate memory
- Native Heap | Heap Alloc: from mallinfo uorblks won, the current process navtive Heap allocated memory in total
- Native Heap | Heap Free: from mallinfo fordblks won, the current process the rest of the Native Heap memory
- Native Heap Size ≈ Native Heap Alloc + Native Heap Free
- Mallinfo is a C library, and the mallinfo() function provides various statistics on memory allocated by the malloc() function
- Dalvik Heap | Heap Size: from the Runtime totalMemory () to obtain, Dalvik Heap a total memory Size
- Dalvik Heap | Heap Alloc: from the Runtime totalMemory () – freeMemory () to obtain, Dalvik Heap allocated memory size
- Dalvik Heap | Heap Free : Dalvik Heap Size = Dalvik Heap Alloc + Dalvik Heap Free
The number of objects in the current process of Obejcts
- Views: Number of View objects instantiated in the current process
- ViewRootImpl: The number of view root ViewRootImpl objects instantiated in the current process, representing a window
- AppContexts: Number of Application context ContextImpl objects instantiated in the current process
- Activities: The number of Activity objects instantiated in the current process
- Assets: indicates the total number of global Assets of the current process
- AssetManagers: The number of global assets managed by the current process
- Local Binders: the number of Local binder objects valid for the current process
- Proxy Binders: Number of remote Binder objects referenced in the current process
- Death Recipients: The number of invalid links between the current process and the binder
- OpenSSL Sockets: Number of secure socket objects
SQL
- MEMORY_USED: Indicates the amount of memory (KB) used by the database in the current process
- PAGECACHE_OVERFLOW: The number of bytes that the page cache configuration cannot meet
- MALLOC_SIZE: the maximum memory allocation requested to SQlite3, in KB
DATABASES
- PGSZ: indicates the page size of the database
- DBSZ: indicates the database size
- Lookaside(b): Size of memory used for backup
- Cache: data cache status
- Dbname: indicates the name of a database table
- Asset Allocations Resource path and resource size
Knowing what these parameters mean, what is our usual way of analyzing memory leaks? You can simply execute a suspicious use case over and over again, and then observe the heap size shown in the dumpsys meminfo instruction result. If the heap size keeps increasing, it’s probably a memory leak, or specify the package name, and observe the number of activities in the dumpsys meminfo instruction result. If the number keeps increasing, It is likely that the activity has a memory leak.
procrank
Gets a ranking of memory usage for all processes, sorted by Pss size. The procrank command outputs more detailed VSS/RSS/PSS/USS memory metrics than the dumpsys meminfo command.
cat /proc/meminfo
Can you view more detailed memory information
free
View available memory. The default unit is KB. This command is simple and lightweight, and focuses on checking the remaining memory.
showmap
vmstat
conclusion
- Dumpsys meminfo can be used to check the oom ADJ, dalvik/native area memory, or the memory status of a process or APK.
- For scenarios where the VSS/RSS/PSS/USS memory metrics for a process can be viewed;
- Cat /proc/meminfo Application scenario: View detailed system memory information, including the kernel information.
- Free Only the available memory of the system is displayed.
- Showmap applies to the following scenarios: View the memory allocation of the virtual address space of a process.
- Vmstat applies to the following scenarios: The system displays the running queue of processes, system switchover, and CPU time ratio periodically.
Reference mosquito-repellent incense: www.jianshu.com/p/37539308f…