android adm查看进程,基于android studio 的ADM对卡顿,耗时方法的检测
Message next() {
// 當消息循環已經退出或被釋放的時候,直接返回null
// 如果應用程序在退出后嘗試重新啟動一個looper,就可能會發生這種情況
final long ptr = mPtr;
if (ptr == 0) {
return null;
}
int pendingIdleHandlerCount = -1; // -1 only during first iteration
int nextPollTimeoutMillis = 0;
for (;;) {//死循環
//將當前線程中的任何阻塞的binder命令刷新到cpu中執行,在執行可能導致長時間阻塞的操作前調用是非常有用的,可以確保任何掛起的對象引用被釋放,防止進程持有一個對象的時間超過它所需要的
if (nextPollTimeoutMillis != 0) {
Binder.flushPendingCommands();
}
//消息死循環不會崩潰的原因
nativePollOnce(ptr, nextPollTimeoutMillis);
//同步代碼塊
synchronized (this) {
// 嘗試檢索下一條信息,如果有就返回
final long now = SystemClock.uptimeMillis();
Message prevMsg = null;
Message msg = mMessages;
if (msg != null && msg.target == null) {
// Stalled by a barrier. 在消息隊列中查找下一個異步消息
do {
prevMsg = msg;
msg = msg.next;
} while (msg != null && !msg.isAsynchronous());
}
if (msg != null) {
if (now < msg.when) {
//如果下一條消息尚未準備好。設置超時喚醒
nextPollTimeoutMillis = (int) Math.min(msg.when - now, Integer.MAX_VALUE);
} else {
// 如果準備好了就獲取消息.
mBlocked = false;
if (prevMsg != null) {
prevMsg.next = msg.next;
} else {
mMessages = msg.next;
}
msg.next = null;
if (DEBUG) Log.v(TAG, "Returning message: " + msg);
msg.markInUse();
return msg;
}
} else {
// 沒有異步消息了
nextPollTimeoutMillis = -1;
}
// Process the quit message now that all pending messages have been handled.
if (mQuitting) {
dispose();
return null;
}
// 如果第一次空閑,則獲取可運行消息數
// 空閑消息只會在消息隊列為空或者隊列第一個消息將要被處理時處理
if (pendingIdleHandlerCount < 0
&& (mMessages == null || now < mMessages.when)) {
pendingIdleHandlerCount = mIdleHandlers.size();
}
if (pendingIdleHandlerCount <= 0) {
// No idle handlers to run. Loop and wait some more.
mBlocked = true;
continue;
}
if (mPendingIdleHandlers == null) {
//容量只有四個
mPendingIdleHandlers = new IdleHandler[Math.max(pendingIdleHandlerCount, 4)];
}
mPendingIdleHandlers = mIdleHandlers.toArray(mPendingIdleHandlers);
}
// Run the idle handlers.
//只有在第一次迭代中才到達這個代碼塊
for (int i = 0; i < pendingIdleHandlerCount; i++) {
final IdleHandler idler = mPendingIdleHandlers[i];
mPendingIdleHandlers[i] = null; // release the reference to the handler
boolean keep = false;
try {
keep = idler.queueIdle();
} catch (Throwable t) {
Log.wtf(TAG, "IdleHandler threw exception", t);
}
if (!keep) {
synchronized (this) {
//當返回值keep為false時,從空閑列表中移除
mIdleHandlers.remove(idler);
}
}
}
// 保證了空閑列表中的消息只處理一次.
pendingIdleHandlerCount = 0;
// 在調用空閑處理程序時,可能已經傳遞了一個新消息,因此可以返回并再次查找掛起的消息,而不必等待
nextPollTimeoutMillis = 0;
}
}
總結
以上是生活随笔為你收集整理的android adm查看进程,基于android studio 的ADM对卡顿,耗时方法的检测的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 鸿蒙系统正式版官方下载,华为鸿蒙os2.
- 下一篇: gartner android 市场份额