标签: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();
标签:ret size static pat turn void read stat over
原文地址:http://www.cnblogs.com/xiaoxiaing/p/7865366.html