本文整理汇总了Java中android.os.Debug.MemoryInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Debug.MemoryInfo方法的具体用法?Java Debug.MemoryInfo怎么用?Java Debug.MemoryInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.os.Debug
的用法示例。
在下文中一共展示了Debug.MemoryInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: memoryApp
import android.os.Debug; //导入方法依赖的package包/类
/**
* 打印内存信息
*/
public static void memoryApp(String info) {
if ( !DEBUG_MEMORY) {
return;
}
Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
int dalvikPrivateDirty = memoryInfo.dalvikPrivateDirty;
int dalvikPss = memoryInfo.dalvikPss;
int dalvikSharedDirty = memoryInfo.dalvikSharedDirty;
int nativePrivateDirty = memoryInfo.nativePrivateDirty;
int nativePss = memoryInfo.nativePss;
int nativeSharedDirty = memoryInfo.nativeSharedDirty;
int otherPss = memoryInfo.otherPss;
int otherSharedDirty = memoryInfo.otherSharedDirty;
String content =
info + "-->dalvikPrivateDirty:" + dalvikPrivateDirty + ",dalvikPss:" + dalvikPss + ",dalvikSharedDirty:" + dalvikSharedDirty + ",nativePrivateDirty:" +
nativePrivateDirty + ",nativePss:" + nativePss + ",nativeSharedDirty:" + nativeSharedDirty + ",otherPss:" + otherPss + ",otherSharedDirty:" + otherSharedDirty +
"\n";
Log.d(
content);
}
示例2: MemoryResource
import android.os.Debug; //导入方法依赖的package包/类
public MemoryResource() {
memoryInfoList.clear();
memoryInfoList.add(Runtime.getRuntime().maxMemory());
memoryInfoList.add(Runtime.getRuntime().totalMemory());
memoryInfoList.add(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
memoryInfoList.add(Runtime.getRuntime().freeMemory());
this.natHeapSize = Debug.getNativeHeapSize();
this.natHeapFreeSize = Debug.getNativeHeapFreeSize();
this.pss = Debug.getPss();
this.loadedClassCount = Debug.getLoadedClassCount();
this.memoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memoryInfo);
}
示例3: getPssForService
import android.os.Debug; //导入方法依赖的package包/类
/**
* Get the PSS used by the process hosting a service.
*
* @param packageName Package name of the service to search for.
* @return the PSS in kB of the process hosting a service, or INVALID_PSS.
*/
@VisibleForTesting
static int getPssForService(ComponentName componentName) {
if (componentName == null) return INVALID_PSS;
Context context = ContextUtils.getApplicationContext();
ActivityManager activityManager =
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningServiceInfo> services =
activityManager.getRunningServices(1000);
if (services == null) return INVALID_PSS;
int pid = -1;
for (ActivityManager.RunningServiceInfo info : services) {
if (componentName.equals(info.service)) {
pid = info.pid;
break;
}
}
if (pid == -1) return INVALID_PSS;
Debug.MemoryInfo infos[] = activityManager.getProcessMemoryInfo(new int[] {pid});
if (infos == null || infos.length == 0) return INVALID_PSS;
return infos[0].getTotalPss();
}
示例4: printMemoryStatus
import android.os.Debug; //导入方法依赖的package包/类
/**
* 打印当前内存占用日志,方便外界诊断。注意,这会显著消耗性能(约50ms左右)
*
* @param tag Used to identify the source of a log message. It usually identifies
* the class or activity where the log call occurs.
* @param msg The message you would like logged.
*/
public static int printMemoryStatus(String tag, String msg) {
if (RePluginInternal.FOR_DEV) {
Debug.MemoryInfo mi = new Debug.MemoryInfo();
Debug.getMemoryInfo(mi);
String mit = "desc=, memory_v_0_0_1, process=, " + IPC.getCurrentProcessName() +
", totalPss=, " + mi.getTotalPss() +
", dalvikPss=, " + mi.dalvikPss +
", nativeSize=, " + mi.nativePss +
", otherPss=, " + mi.otherPss + ", ";
return Log.i(tag + "-MEMORY", mit + msg);
}
return -1;
}
示例5: getUsedMemory
import android.os.Debug; //导入方法依赖的package包/类
/** 获取指定包名应用占用的内存,单位为byte */
public static long getUsedMemory(String packageName) {
Context context = UIUtils.getContext();
if (context == null) {
return -1;
}
if (StringUtils.isEmpty(packageName)) {
packageName = context.getPackageName();
}
long size = 0;
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runapps = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo runapp : runapps) { // 遍历运行中的程序
if (packageName.equals(runapp.processName)) {// 得到程序进程名,进程名一般就是包名,但有些程序的进程名并不对应一个包名
// 返回指定PID程序的内存信息,可以传递多个PID,返回的也是数组型的信息
Debug.MemoryInfo[] processMemoryInfo = activityManager.getProcessMemoryInfo(new int[]{runapp.pid});
// 得到内存信息中已使用的内存,单位是K
size = processMemoryInfo[0].getTotalPrivateDirty() * 1024;
}
}
return size;
}
示例6: a
import android.os.Debug; //导入方法依赖的package包/类
public static rgv a(Debug.MemoryInfo paramMemoryInfo)
{
rgv localrgv = new rgv();
localrgv.a = Integer.valueOf(paramMemoryInfo.dalvikPss);
localrgv.b = Integer.valueOf(paramMemoryInfo.nativePss);
localrgv.c = Integer.valueOf(paramMemoryInfo.otherPss);
localrgv.d = Integer.valueOf(paramMemoryInfo.dalvikPrivateDirty);
localrgv.e = Integer.valueOf(paramMemoryInfo.nativePrivateDirty);
localrgv.f = Integer.valueOf(paramMemoryInfo.otherPrivateDirty);
if (Build.VERSION.SDK_INT >= 19)
{
localrgv.g = Integer.valueOf(paramMemoryInfo.getTotalPrivateClean());
localrgv.i = Integer.valueOf(paramMemoryInfo.getTotalSwappablePss());
}
localrgv.h = Integer.valueOf(paramMemoryInfo.getTotalSharedDirty());
return localrgv;
}
示例7: run
import android.os.Debug; //导入方法依赖的package包/类
@Override
public void run() {
ActivityManager.MemoryInfo systemMemInfo = new ActivityManager.MemoryInfo();
am.getMemoryInfo(systemMemInfo);
Debug.MemoryInfo processMemInfo = am.getProcessMemoryInfo(new int[]{Process.myPid()})[0];
memInfo = new MemInfo(systemMemInfo, processMemInfo);
notifyObservers();
handler.postDelayed(memInfoQueryRunnable, interval);
}
示例8: onDataAvailable
import android.os.Debug; //导入方法依赖的package包/类
@Override
public void onDataAvailable(MemInfo data) {
ActivityManager.MemoryInfo systemMemInfo = data.getSystemMemInfo();
Debug.MemoryInfo procMemInfo = data.getProcessMemInfo();
if (DebugOverlay.isDebugLoggingEnabled()) {
Log.d(TAG, "MemTotal(MB):" + DECIMAL_FORMAT.format(systemMemInfo.totalMem / 1048576f));
Log.d(TAG, "MemAvail(MB):" + DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f));
Log.d(TAG, "MemThreshold(MB):" + DECIMAL_FORMAT.format(systemMemInfo.threshold / 1048576f));
Log.d(TAG, "TotalPss(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f));
Log.d(TAG, "TotalPrivateDirty(MB):" + DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));
}
if (memInfoTxtView != null) {
StringBuilder builder = new StringBuilder(HEADER);
builder.append(DECIMAL_FORMAT.format(systemMemInfo.availMem / 1048576f)).append(" ")
.append(DECIMAL_FORMAT.format(procMemInfo.getTotalPss() / 1024f)).append(" ")
.append(DECIMAL_FORMAT.format(procMemInfo.getTotalPrivateDirty() / 1024f));
SpannableStringBuilder spannableBuilder = new SpannableStringBuilder(builder.toString());
if (systemMemInfo.lowMemory) {
spannableBuilder.setSpan(
new TextAppearanceSpan(memInfoTxtView.getContext(), R.style.debugoverlay_LowMemoryTextAppearance),
HEADER.length(),
spannableBuilder.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
}
memInfoTxtView.setText(spannableBuilder);
}
}
示例9: getMemSize
import android.os.Debug; //导入方法依赖的package包/类
private double getMemSize(RunningAppProcessInfo appProcessInfo) {
// 进程 ID 号
int pid = appProcessInfo.pid;
// 获得该进程占用的内存
int[] memPid = new int[] { pid };
// 此 MemoryInfo 位于 android.os.Debug.MemoryInfo 包中,用来统计进程的内存信息
Debug.MemoryInfo[] memoryInfo = mActivityManager.getProcessMemoryInfo(memPid);
// 获取进程占内存用信息 kb 单位
return memoryInfo[0].dalvikPrivateDirty;
}
示例10: getRunningTaskInfos
import android.os.Debug; //导入方法依赖的package包/类
/**
* 获取正在运行的所有进程的信息
*/
public static List<TaskInfo> getRunningTaskInfos(Context context) {
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
PackageManager packageManager = context.getPackageManager();
List<ActivityManager.RunningAppProcessInfo> processInfos = activityManager.getRunningAppProcesses();
List<TaskInfo> taskInfos = new ArrayList<>();
for (ActivityManager.RunningAppProcessInfo processInfo :
processInfos) {
String packagename = processInfo.processName;
TaskInfo taskInfo = new TaskInfo();
taskInfo.setPackageName(packagename);//进程名字
Debug.MemoryInfo[] memoryInfos = activityManager.getProcessMemoryInfo(new int[]{processInfo.pid});
long memsize = memoryInfos[0].getTotalPrivateDirty();
taskInfo.setAppMemory(memsize);
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packagename,0);
Drawable icon = packageInfo.applicationInfo.loadIcon(packageManager);
taskInfo.setIcon(icon);
String appname = packageInfo.applicationInfo.loadLabel(packageManager).toString();
taskInfo.setAppName(appname);
if ((ApplicationInfo.FLAG_SYSTEM & packageInfo.applicationInfo.flags) != 0) {
//系统进程
taskInfo.setUserApp(false);
} else {
//用户进程
taskInfo.setUserApp(true);
}
} catch (Exception e) {
e.printStackTrace();
taskInfo.setAppName(packagename);
taskInfo.setIcon(context.getResources().getDrawable(R.drawable.ic_default));
}
taskInfos.add(taskInfo);
}
return taskInfos;
}
示例11: getAppPssInfo
import android.os.Debug; //导入方法依赖的package包/类
/**
* 获取应用实际占用内存
*
* @param context
* @param pid
* @return 应用pss信息KB
*/
public static PssInfo getAppPssInfo(Context context, int pid) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
Debug.MemoryInfo memoryInfo = am.getProcessMemoryInfo(new int[]{pid})[0];
PssInfo pssInfo = new PssInfo();
pssInfo.totalPss = memoryInfo.getTotalPss();
pssInfo.dalvikPss = memoryInfo.dalvikPss;
pssInfo.nativePss = memoryInfo.nativePss;
pssInfo.otherPss = memoryInfo.otherPss;
return pssInfo;
}
示例12: memoryOK
import android.os.Debug; //导入方法依赖的package包/类
private boolean memoryOK() {
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.getMemoryInfo(mi);
Debug.MemoryInfo md = new Debug.MemoryInfo();
Debug.getMemoryInfo(md);
Runtime rt = Runtime.getRuntime();
long used_memory = md.getTotalPss() / 1024;
long max_memory = rt.maxMemory() / (1024 * 1024);
return true;
//return (max_memory - used_memory) > MEMORY_LIMIT;
}
示例13: QosThread
import android.os.Debug; //导入方法依赖的package包/类
public QosThread(ActivityManager manager, Handler handler,Context context) {
mContext = context;
mHandler = handler;
mCpuStats = new Cpu(mContext.getPackageName());
mActivityManager = manager;
mi = new Debug.MemoryInfo();
mRunning = true;
mQosObject = new QosObject();
}
示例14: QosInfoThread
import android.os.Debug; //导入方法依赖的package包/类
public QosInfoThread(Context context, Handler handler) {
mHandler = handler;
mCpuStats = new CpuInfo();
mi = new Debug.MemoryInfo();
mRunning = true;
mQosObject = new QosBean();
if(context != null)
mPackageName = context.getPackageName();
}
示例15: QosThread
import android.os.Debug; //导入方法依赖的package包/类
public QosThread(Context context, Handler handler) {
mHandler = handler;
mCpuStats = new Cpu();
mi = new Debug.MemoryInfo();
mRunning = true;
mQosObject = new QosObject();
if(context != null)
mPackageName = context.getPackageName();
}