本文整理汇总了Java中android.os.Debug.MemoryInfo类的典型用法代码示例。如果您正苦于以下问题:Java MemoryInfo类的具体用法?Java MemoryInfo怎么用?Java MemoryInfo使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MemoryInfo类属于android.os.Debug包,在下文中一共展示了MemoryInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPSS
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* 获取进程内存PSS数据
*
* @param context Android上下文
* @param pid 进程ID
* @return {nativePss,dalvikPss,TotalPss}
*/
public static long[] getPSS(Context context, int pid) {
long[] value = new long[3]; // Natvie Dalvik Total
if (pid >= 0) {
int[] pids = new int[1];
pids[0] = pid;
ActivityManager mAm = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids);
MemoryInfo pidMemoryInfo = memoryInfoArray[0];
value[0] = pidMemoryInfo.nativePss;
value[1] = pidMemoryInfo.dalvikPss;
value[2] = pidMemoryInfo.getTotalPss();
} else {
value[0] = 0;
value[1] = 0;
value[2] = 0;
}
return value;
}
示例2: begin
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* Record an "begin" memory trace event.
* Begin trace events should have a matching end event.
*/
@VisibleForTesting
public static synchronized void begin(String name, MemoryInfo memoryInfo) {
final long eventId = name.hashCode();
TraceEvent.startAsync(name, eventId);
if (sEnabled && matchesFilter(name)) {
// Done before calculating the starting perf data to ensure calculating the memory usage
// does not influence the timing data.
long timestampUs = (System.nanoTime() - sBeginNanoTime) / 1000;
savePerfString(makeMemoryTraceNameFromTimingName(name), eventId, EventType.START,
timestampUs, memoryInfo);
if (sTrackTiming) {
savePerfString(name, eventId, EventType.START, false);
}
}
}
示例3: end
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* Record an "end" memory trace event, to match a begin event. The
* memory usage delta between begin and end is usually interesting to
* graph code.
*/
@VisibleForTesting
public static synchronized void end(String name, MemoryInfo memoryInfo) {
final long eventId = name.hashCode();
TraceEvent.finishAsync(name, eventId);
if (sEnabled && matchesFilter(name)) {
if (sTrackTiming) {
savePerfString(name, eventId, EventType.FINISH, false);
}
// Done after calculating the instant perf data to ensure calculating the memory usage
// does not influence the timing data.
long timestampUs = (System.nanoTime() - sBeginNanoTime) / 1000;
savePerfString(makeMemoryTraceNameFromTimingName(name), eventId, EventType.FINISH,
timestampUs, memoryInfo);
}
}
示例4: savePerfString
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* Save a perf trace event as a JSON dict. The format mirrors a TraceEvent dict.
*
* @param name The trace data
* @param id The id of the event
* @param type the type of trace event (I, S, F)
* @param timestampUs The time stamp at which this event was recorded
* @param memoryInfo Memory details to be included in this perf string, null if
* no memory details are to be included.
*/
private static void savePerfString(String name, long id, EventType type, long timestampUs,
MemoryInfo memoryInfo) {
try {
JSONObject traceObj = new JSONObject();
traceObj.put("cat", "Java");
traceObj.put("ts", timestampUs);
traceObj.put("ph", type);
traceObj.put("name", name);
traceObj.put("id", id);
if (memoryInfo != null) {
int pss = memoryInfo.nativePss + memoryInfo.dalvikPss + memoryInfo.otherPss;
traceObj.put("mem", pss);
}
sPerfTraceStrings.put(traceObj);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
示例5: getProcessMemInfo
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* 获取进程内存信息
* @param pid
* @param info
*/
private static void getProcessMemInfo(int pid, ProcMemInfo info) {
if (pid >= 0) {
int[] pids = new int[1];
pids[0] = pid;
ActivityManager mAm = (ActivityManager) WTApplication
.getContext().getSystemService(Context.ACTIVITY_SERVICE);
MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids);
MemoryInfo pidMemoryInfo = memoryInfoArray[0];
info.setNatived(pidMemoryInfo.nativePss);
info.setDalvik(pidMemoryInfo.dalvikPss);
info.setTotal(pidMemoryInfo.getTotalPss());
}
}
示例6: a
import android.os.Debug.MemoryInfo; //导入依赖的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: getTotalPss
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* getTotalPss
*
* @param context
* @param processName
* @return
*/
public static long getTotalPss(Context context, String processName) {
ActivityManager activityMgr = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> list = activityMgr.getRunningAppProcesses();
if (list != null) {
for (RunningAppProcessInfo processInfo : list) {
if (processInfo.processName.equals(processName)) {
int pid = processInfo.pid;
MemoryInfo[] memoryInfos = activityMgr
.getProcessMemoryInfo(new int[] { pid });
MemoryInfo memoryInfo = memoryInfos[0];
int totalPss = memoryInfo.getTotalPss();
return totalPss;
}
}
}
return -1;
}
示例8: onStart
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
@Override
protected void onStart() {
ActivityManager am = (ActivityManager)getContext().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
ArrayList<RunningAppProcessInfo> runningProcesses = new ArrayList<RunningAppProcessInfo>(am.getRunningAppProcesses());
final int numProcesses = runningProcesses.size();
int[] runningProcessIds = new int[numProcesses];
for (int i=0; i<numProcesses; i++ ) {
runningProcessIds[i] = runningProcesses.get(i).pid;
}
List<MemoryInfo> memoryInfos = Arrays.asList(am.getProcessMemoryInfo(runningProcessIds));
List<ProcessErrorStateInfo> errorInfos = am.getProcessesInErrorState();
Gson gson = getGson();
JsonObject data = new JsonObject();
data.add("RUNNING_PROCESS_INFO", gson.toJsonTree(runningProcesses));
data.add("RUNNING_PROCESS_MEMORY_INFO", gson.toJsonTree(memoryInfos));
data.add("ERRORED_PROCESS_INFO", gson.toJsonTree(errorInfos));
data.add("CPU_LOAD", gson.toJsonTree(getCpuLoad()));
data.add("MEM_INFO", gson.toJsonTree(getMemInfo()));
data.add("NET_DEV", gson.toJsonTree(getNetDev()));
sendData(data);
stop();
}
示例9: printDeviceInformation
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
public static void printDeviceInformation(Context ctx, PrintWriter out) {
out.println();
out.println("Memory Information --------");
MemoryInfo mem = new MemoryInfo();
Debug.getMemoryInfo(mem);
out.println("TotalPss: " + mem.getTotalPss() + "KB");
out.println("TotalPrivateDirty: " + mem.getTotalPrivateDirty() + "KB");
out.println("TotalSharedDirty: " + mem.getTotalSharedDirty() + "KB");
out.println("HeapAllocatedSize: " + Debug.getNativeHeapAllocatedSize() / 1024 + "KB");
out.println("HeapSize: " + Debug.getNativeHeapSize() / 1024 + "KB");
out.println();
out.println("Device Information ---------");
out.println("manufactor: " + Build.MANUFACTURER);
out.println("model: " + Build.MODEL);
out.println("version: " + Build.VERSION.RELEASE);
out.println("product: " + Build.PRODUCT);
out.println("hardware: " + Build.HARDWARE);
out.println("board: " + Build.BOARD);
out.println("device: " + Build.DEVICE);
out.println("CPU_ABI: " + Build.CPU_ABI);
out.println("CPU_ABI2: " + Build.CPU_ABI2);
out.println();
out.println("Display Information --------");
DisplayMetrics dm = ctx.getResources().getDisplayMetrics();
out.println("Width: " + dm.widthPixels);
out.println("Height: " + dm.heightPixels);
out.println("Density: " + dm.density);
out.println("DPI: " + dm.densityDpi);
out.println("ScaledDensity: " + dm.scaledDensity);
}
示例10: getPrivDirty
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* 获取进程内存Private Dirty数据
*
* @param context Android上下文
* @param pid 进程ID
* @return {nativePrivateDirty,dalvikPrivateDirty,TotalPrivateDirty}
*/
public static long[] getPrivDirty(Context context, int pid) {
ActivityManager mAm = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
int[] pids = new int[1];
pids[0] = pid;
MemoryInfo[] memoryInfoArray = mAm.getProcessMemoryInfo(pids);
MemoryInfo pidMemoryInfo = memoryInfoArray[0];
long[] value = new long[3]; // Natvie Dalvik Total
value[0] = pidMemoryInfo.nativePrivateDirty;
value[1] = pidMemoryInfo.dalvikPrivateDirty;
value[2] = pidMemoryInfo.getTotalPrivateDirty();
return value;
}
示例11: getAvailableMemory
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* 获取可用内存
*
*/
public static long getAvailableMemory(Context context) {
ActivityManager activityManager = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
activityManager.getMemoryInfo(mi);
return mi.availMem;
}
示例12: getAvailMemory
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* 得到设备的可用RAM
* @return 返回所有内存大小,单位:kb
*/
private long getAvailMemory(Context context)
{
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
am.getMemoryInfo(mi);
return mi.availMem / 1024;
}
示例13: getMemoryInfo
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
public static MemoryInfo getMemoryInfo() {
/* Lazy allocation. */
if (SystemUtils.sMemoryInfo == null) {
SystemUtils.sMemoryInfo = new MemoryInfo();
}
Debug.getMemoryInfo(SystemUtils.sMemoryInfo);
return SystemUtils.sMemoryInfo;
}
示例14: getTaskprovider
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
/**
* ��ȡ�ֻ��Ľ�����Ϣ
* @param context
* @return
*/
public static List<TaskInfo> getTaskprovider(Context context) {
List<TaskInfo> taskInfos = new ArrayList<TaskInfo>();
ActivityManager am = (ActivityManager) context.getSystemService(context.ACTIVITY_SERVICE);
PackageManager pm = context.getPackageManager();
List<RunningAppProcessInfo> processInfos = am.getRunningAppProcesses();
for (RunningAppProcessInfo processInfo : processInfos) {
TaskInfo taskInfo = new TaskInfo();
String packageName = processInfo.processName;
taskInfo.setPackname(packageName);
MemoryInfo[] mi = am.getProcessMemoryInfo(new int[]{processInfo.pid});
taskInfo.setMemSize(mi[0].getTotalPrivateDirty()*1024);
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo(packageName, 0);
taskInfo.setName(applicationInfo.loadLabel(pm).toString());
taskInfo.setIcon(applicationInfo.loadIcon(pm));
if ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
taskInfo.setUserTack(true);
} else {
taskInfo.setUserTack(false);
}
} catch (NameNotFoundException e) {
e.printStackTrace();
/**
* �Ҳ����İ�������android.process.acore; android.process.media;
* ��������c����д�ģ�Ϊ�������Ĭ�ϵ���Ϣ
*/
taskInfo.setIcon(context.getResources().getDrawable(R.drawable.ic_launcher));
taskInfo.setName(packageName);
}
taskInfos.add(taskInfo);
}
return taskInfos;
}
示例15: getRunningApplication
import android.os.Debug.MemoryInfo; //导入依赖的package包/类
public static List<AppInfo> getRunningApplication(Context context) {
MemoryInfo processMemoryInfo;
PackageManager pm = context.getPackageManager();
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> runningAppProcesses = am
.getRunningAppProcesses();
List<AppInfo> list = new ArrayList<AppInfo>();
for (RunningAppProcessInfo runningAppProcessInfo : runningAppProcesses) {
AppInfo info = new AppInfo();
processMemoryInfo = am
.getProcessMemoryInfo(new int[] { runningAppProcessInfo.pid })[0];
long mem = processMemoryInfo.getTotalPrivateDirty() * 1024L;
info.mem = mem;
info.packagename = runningAppProcessInfo.processName;
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo(
runningAppProcessInfo.processName, 0);
info.sysApp = ((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0)
|| ((applicationInfo.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0);
info.icon = applicationInfo.loadIcon(pm);
info.name = applicationInfo.loadLabel(pm).toString();
list.add(info);
} catch (NameNotFoundException e) {
e.printStackTrace();
info = null;
}
}
return list;
}