本文整理汇总了Java中android.os.Debug类的典型用法代码示例。如果您正苦于以下问题:Java Debug类的具体用法?Java Debug怎么用?Java Debug使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Debug类属于android.os包,在下文中一共展示了Debug类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateStats
import android.os.Debug; //导入依赖的package包/类
private void updateStats() {
final Runtime runtime = Runtime.getRuntime();
final long heapMemory = runtime.totalMemory() - runtime.freeMemory();
final StringBuilder sb = new StringBuilder(DEFAULT_MESSAGE_SIZE);
// When changing format of output below, make sure to sync "run_comparison.py" as well
sb.append("Heap: ");
appendSize(sb, heapMemory);
sb.append(" Java ");
appendSize(sb, Debug.getNativeHeapSize());
sb.append(" native\n");
appendTime(sb, "Avg wait time: ", mPerfListener.getAverageWaitTime(), "\n");
appendNumber(sb, "Requests: ", mPerfListener.getOutstandingRequests(), " outsdng ");
appendNumber(sb, "", mPerfListener.getCancelledRequests(), " cncld\n");
final String message = sb.toString();
mStatsDisplay.setText(message);
FLog.i(TAG, message);
}
示例2: avgTimeEnd
import android.os.Debug; //导入依赖的package包/类
/**
* 统计平均时常
*
* @param tag
* @param msg
*/
public static void avgTimeEnd(String tag, Object... msg) {
if (LuaViewConfig.isDebug()) {
Map map = mAvgTime.get(tag);
if (map != null) {//已经开始
long lastTime = Long.valueOf(String.valueOf(map.get(LAST_TIME)));
long totalTime = Long.valueOf(String.valueOf(map.get(TOTAL_TIME))) + Debug.threadCpuTimeNanos() - lastTime;
map.put(TOTAL_TIME, totalTime);//总时间
long printInterval = Long.valueOf(String.valueOf(map.get(PRINT_INTERVAL)));
long times = Long.valueOf(String.valueOf(map.get(TIMES))) + 1;//总次数
if (times >= printInterval) {//可以打印
Log.d(DEFAULT_PREFIX, tag + " end " + (double) totalTime / printInterval + " " + getMsg(msg));
mAvgTime.put(tag, null);
} else {
map.put(TIMES, times);//总次数
}
}
}
}
示例3: handleMessage
import android.os.Debug; //导入依赖的package包/类
@Override
public boolean handleMessage(Message msg) {
// TODO uncomment below code when release
if (Debug.isDebuggerConnected()) {
return true;
}
Event event = (Event) msg.obj;
if (event != null) {
try {
processEvent(event);
} catch (Exception e) {
e.printStackTrace();
}
event.recycle();
}
// return true, so handler won't process this msg again, since we have event recycled here
return true;
}
示例4: 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);
}
示例5: 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);
}
示例6: 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();
}
示例7: 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;
}
示例8: dumpHeap
import android.os.Debug; //导入依赖的package包/类
public File dumpHeap() {
if (!LeakCanaryInternals.isExternalStorageWritable()) {
Log.d(TAG, "Could not dump heap, external storage not mounted.");
}
File heapDumpFile = getHeapDumpFile();
if (heapDumpFile.exists()) {
Log.d(TAG, "Could not dump heap, previous analysis still is in progress.");
return NO_DUMP;
}
FutureResult<Toast> waitingForToast = new FutureResult();
showToast(waitingForToast);
if (waitingForToast.wait(5, TimeUnit.SECONDS)) {
Toast toast = (Toast) waitingForToast.get();
try {
Debug.dumpHprofData(heapDumpFile.getAbsolutePath());
cancelToast(toast);
return heapDumpFile;
} catch (IOException e) {
cleanup();
Log.e(TAG, "Could not perform heap dump", e);
return NO_DUMP;
}
}
Log.d(TAG, "Did not dump heap, too much time waiting for Toast.");
return NO_DUMP;
}
示例9: start
import android.os.Debug; //导入依赖的package包/类
void start(int initialVelocity) {
initialVelocity = modifyFlingInitialVelocity(initialVelocity);
int initialY = initialVelocity < 0 ? Integer.MAX_VALUE : 0;
mLastFlingY = initialY;
mScroller.fling(0, initialY, 0, initialVelocity,
0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
mTouchMode = TOUCH_MODE_FLING;
post(this);
if (PROFILE_FLINGING) {
if (!mFlingProfilingStarted) {
Debug.startMethodTracing("AbsListViewFling");
mFlingProfilingStarted = true;
}
}
}
示例10: 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;
}
示例11: println
import android.os.Debug; //导入依赖的package包/类
@Override
public void println(String x) {
if (mStopWhenDebugging && Debug.isDebuggerConnected()) {
return;
}
if (!mPrintingStarted) {
mStartTimestamp = System.currentTimeMillis();
mStartThreadTimestamp = SystemClock.currentThreadTimeMillis();
mPrintingStarted = true;
startDump();
} else {
final long endTime = System.currentTimeMillis();
mPrintingStarted = false;
if (isBlock(endTime)) {
notifyBlockEvent(endTime);
}
stopDump();
}
}
示例12: dumpHeap
import android.os.Debug; //导入依赖的package包/类
public static void dumpHeap(String filename) {
try {
Debug.dumpHprofData(filename);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例13: start
import android.os.Debug; //导入依赖的package包/类
void start(int initialVelocity) {
initialVelocity = modifyFlingInitialVelocity(initialVelocity);
int initialY = initialVelocity < 0 ? Integer.MAX_VALUE : 0;
mLastFlingY = initialY;
mScroller.fling(0, initialY, 0, initialVelocity, 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE);
if (DEBUG)
Log.d(TAG, String.format("String Fling: [%d, %d] to [%d]", initialY, initialVelocity, mScroller.getFinalY()));
mTouchMode = TOUCH_MODE_FLING;
post(this);
if (PROFILE_FLINGING) {
if (!mFlingProfilingStarted) {
Debug.startMethodTracing("AbsListViewFling");
mFlingProfilingStarted = true;
}
}
}
示例14: onPause
import android.os.Debug; //导入依赖的package包/类
@Override
protected void onPause() {
super.onPause();
DebugLog.d("AndouKun", "onPause");
hidePauseMessage();
mGame.onPause();
mGLSurfaceView.onPause();
mGame.getRenderer().onPause(); // hack!
if (mMethodTracing) {
Debug.stopMethodTracing();
mMethodTracing = false;
}
if (mSensorManager != null) {
mSensorManager.unregisterListener(this);
}
}
示例15: antiDebug
import android.os.Debug; //导入依赖的package包/类
public void antiDebug() {
try {
// Debug.isDebuggerConnected();
Method isDebuggerConnected = Debug.class.getMethod("isDebuggerConnected");
XposedBridge.hookMethod(isDebuggerConnected, new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
// Log.d("cc", "set isDebuggerConnected false");
param.setResult(false);
}
});
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}