Bri*_*ham 1 performance user-interface android
我正在尝试确定什么会降低我的应用程序的性能,我正在研究什么是垄断主线程.
我刚刚发现Looper.setMessageLogging并正在设置客户Printer以查看主线程的使用方式:
Looper.getMainLooper().setMessageLogging(new LogPrinter(Log.DEBUG, "MainLooper")) {
private long startTime = 0L;
@Override
public void println(String x) {
if (x.startsWith(">")) {
startTime = System.nanoTime();
} else if (x.startsWith("<")) {
final long duration = System.nanoTime() - startTime;
x += " (" + (duration / 1000000L) + " ms)";
}
super.println(x);
}
});
Run Code Online (Sandbox Code Playgroud)
这让我发现,是的,有很多代码需要超过500毫秒,有些代码需要几秒钟,这可能是性能如此糟糕的原因.
D/MainLooper( 1542): >>>>> Dispatching to Handler{433ae6a0} null: 1000
D/MainLooper( 1542): <<<<< Finished to Handler{433ae6a0} null (952 ms)
Run Code Online (Sandbox Code Playgroud)
现在,我只能理解这些日志消息了.我不知道在主线程上采用952 ms的方法是什么.有没有更好的方法来确定花费这么长时间的方法?
| 归档时间: |
|
| 查看次数: |
907 次 |
| 最近记录: |