欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

android adm查看进程,基于android studio 的ADM对卡顿,耗时方法的检测

发布时间:2025/3/19 编程问答 64 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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对卡顿,耗时方法的检测的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。