adb shell dumpsys meminfo package_name or pid
eg
adb shell dumpsys meminfo com.android.systemui
adb shell dumpsys meminfo com.android.settings
View the total pss column, which indicates how much memory is used
Generally speaking, the memory footprint has the following rules: VSS >= RSS >= PSS >= USS
VSS-Virtual Set Size virtual memory consumption (including memory occupied by shared libraries)
RSS-Resident Set Size actual physical memory used (including memory occupied by shared libraries)
PSS-Proportional Set Size physical memory actually used (occupied by shared libraries) Memory)
USS-Unique Set Size physical memory occupied by the process alone (not including the memory occupied by shared libraries)
adb shell dumpsys meminfo | grep package_name
adb shell dumpsys meminfo | grep com.android.settings
adb shell dumpsys meminfo | grep com.android.systemui
ps -A | grep -i cameraserver
ps -A | grep -i com.android.systemui
adb shell cat /proc/meminfo
MemFree: The number of free memory, which means the unused memory of the system. MemUsed=MemTotal-MemFree is the memory that has been used.
MemAvailable: The number of available memory, the number of available memory for the application. Although some memory in the system has been used, it can be recycled. For example, cache/buffer and slab can be recycled, so MemFree cannot represent all available memory. This part of reclaimable memory plus MemFree is the memory available to the system. That is: MemAvailable≈MemFree+Buffers+Cached , which is calculated by the kernel using a specific algorithm and is an estimated value. The key difference between it and MemFree is that MemFree refers to the system level and MemAvailable refers to the application level.
MemoryInfo memoryInfo = new MemoryInfo() ;
private ActivityManager mActivityManager = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
//private ActivityManager mActivityManager = = (ActivityManager)getInstrumentation().getTargetContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo memoryInfo = new ActivityManager.MemoryInfo();
mActivityManager.getMemoryInfo(memoryInfo) ;
long availMem = memoryInfo.availMem/1024/1024 ;
long totalMem = memoryInfo.totalMem/1024/1024;
long threshold = memoryInfo.threshold/1024/1024;
Log.i(TAG, "totalMem ="+totalMem +" availMem="+availMem+" threshold ="+threshold);
private void getProcessMemroy() {
//ActivityManager am = (ActivityManager) getInstrumentation()
// .getContext().getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager am = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> apps = am.getRunningAppProcesses();
for (RunningAppProcessInfo proc : apps) {
Log.i(TAG, "process:"+proc.processName);
if (!proc.processName.contains("com.android.settings")) {
continue;
}
int[] pids = new int[1];
pids[0]=proc.pid;
MemoryInfo meminfo = am.getProcessMemoryInfo(pids)[0];
Log.i(TAG, "pid="+proc.pid+" totalPSS="+meminfo.getTotalPss()/1024+" nativePSS="+meminfo.nativePss/1024+" dalvikPSS="+meminfo.dalvikPss/1024);
}
import java.lang.Process;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
String cmd = "adb shell dumpsys meminfo com.android.settings";
int mem_result = 0;
try {
Process p = Runtime.getRuntime().exec(cmd);
InputStream input = p.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
String line = "";
while ((line = reader.readLine()) != null) {
if (line.startsWith(" TOTAL")) {
Log.i(TAG, line.trim());
break;
}
}
reader.close();
input.close();
} catch (IOException e) {
Log.e(TAG, "dumpsys meminfo failed "+e);
}
#!/bin/bash
adb root
adb wait-for-device
adb shell setenforce 0
for (( i = 1; i < 10; i++));
do
time1=$(date "+%Y%m%d-%H%M%S")
echo $time1 >> ./log.txt
adb shell dumpsys meminfo >> ./log.txt
sleep 20s
done