码迷,mamicode.com
首页 > 移动开发 > 详细

Android 最简单的测试UI卡顿

时间:2017-11-20 13:08:31      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:ret   size   static   pat   turn   void   read   stat   over   

就两个类:

public class BlockDetectByPrinter {
private static final String START = ">>>>> Dispatching";
private static final String END = "<<<<< Finished";
public static void start(){
Looper.getMainLooper().setMessageLogging(new Printer() {
@Override
public void println(String x) {
if(x.startsWith(START)){
LogMonitor.getsInstance().startMonitor();
}
if(x.startsWith(END)){
LogMonitor.getsInstance().startMonitor();
}
}
});
}
}


public class LogMonitor {
private static LogMonitor sInstance = new LogMonitor();
private HandlerThread mLogThread = new HandlerThread("log");
private Handler mIoHandler;
private static final long TIME_BLOCK = 2000L;

private LogMonitor(){
mLogThread.start();
mIoHandler = new Handler(mLogThread.getLooper());
}
private static Runnable mLogRunnable = new Runnable() {
@Override
public void run() {
StringBuilder sb = new StringBuilder();
StackTraceElement[] stackTrace = Looper.getMainLooper().getThread().getStackTrace();
for(StackTraceElement s:stackTrace){
sb.append(s.toString()+"\n");
}
LogUtil.e("LogMonitor",sb.toString());
}
};
public static LogMonitor getsInstance(){
return sInstance;
}
// public boolean isMonitor(){
// return mIoHandler.hasCallbacks(mLogRunnable);
// }
public void startMonitor(){
mIoHandler.postDelayed(mLogRunnable,TIME_BLOCK);
}
public void removeMonitor(){
mIoHandler.removeCallbacks(mLogRunnable);
}

}
然后在application的onCreate方法使用
BlockDetectByPrinter.start();



Android 最简单的测试UI卡顿

标签:ret   size   static   pat   turn   void   read   stat   over   

原文地址:http://www.cnblogs.com/xiaoxiaing/p/7865366.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!