智能座舱天气appcpu loading太高优化

一、背景
智能座舱在浏览天气weather app的时候,测试发现cpu loading过高,天气app的cpu负载110%左右,针对这种场景,需要优化这一特定场景的cpu 负载。

二、问题分析以及修改方案
在这里插入图片描述

在这里插入图片描述

在postCallbackDelayedInternal 函数,加上如下log。
//android add for debug begin
if (callbackType == CALLBACK_ANIMATION) {
Log.d(TAG, Thread.currentThread().getName() + " postCallback: postCallbackDelayedInternal type=" + callbackType
+ “, action=” + action + “, token=” + token + ", this = " + this + ",callstack = ", new Throwable(“xxxx”));
}
//android add for debug end

    private void postCallbackDelayedInternal(int callbackType,
            Object action, Object token, long delayMillis) {
        if (DEBUG_FRAMES) {
            Log.d(TAG, "PostCallback: type=" + callbackType
                    + ", action=" + action + ", token=" + token
                    + ", delayMillis=" + delayMillis);
        }
        //android add for debug begin
        if (callbackType == CALLBACK_ANIMATION) {
            Log.d(TAG, Thread.currentThread().getName() + " postCallback: postCallbackDelayedInternal type=" + callbackType
                + ", action=" + action + ", token=" + token + ", this = " + this + ",callstack = ", new Throwable("xxxx"));
        }
        //android add for debug end

        synchronized (mLock) {
            final long now = SystemClock.uptimeMillis();
            final long dueTime = now + delayMillis;
            mCallbackQueues[callbackType].addCallbackLocked(dueTime, action, token);

            if (dueTime <= now) {
                scheduleFrameLocked(now);
            } else {
                Message msg = mHandler.obtainMessage(MSG_DO_SCHEDULE_CALLBACK, action);
                msg.arg1 = callbackType;
                msg.setAsynchronous(true);
                mHandler.sendMessageAtTime(msg, dueTime);
            }
        }
    }

存在如下两路动画,会以60fps刷新:
第一路如下:

67897: 12-19 12:11:58.177  5426  5426 D Choreographer: main postCallback: postCallbackDelayedInternal type=1, action=android.graphics.drawable.AnimationDrawable@4f8d3f1, token=android.graphics.drawable.AnimationDrawable@4f8d3f1, this = android.view.Choreographer@d4b390a,callstack =67898: 12-19 12:11:58.177  5426  5426 D Choreographer: java.lang.Throwable: xxxx
	行 67899: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.Choreographer.postCallbackDelayedInternal(Choreographer.java:467)67900: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.Choreographer.postCallbackDelayed(Choreographer.java:455)67901: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.scheduleDrawable(View.java:23113)67902: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.graphics.drawable.Drawable.scheduleSelf(Drawable.java:494)67903: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.graphics.drawable.AnimationDrawable.setFrame(AnimationDrawable.java:286)67904: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.graphics.drawable.AnimationDrawable.start(AnimationDrawable.java:159)67905: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.widget.ProgressBar.drawTrack(ProgressBar.java:2144)67906: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.widget.ProgressBar.onDraw(ProgressBar.java:2107)67907: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22353)67908: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21229)67909: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67910: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67911: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67912: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22356)67913: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21229)67914: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67915: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67916: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67917: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67918: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67919: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67920: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67921: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67922: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67923: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67924: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67925: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67926: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67927: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67928: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5030)67929: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67930: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22356)67931: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)67932: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21229)67933: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67934: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67935: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67936: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67937: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67938: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67939: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67940: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67941: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67942: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67943: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67944: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67945: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67946: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67947: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67948: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67949: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67950: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67951: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67952: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67953: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67954: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67955: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67956: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21220)67957: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22084)67958: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.drawChild(ViewGroup.java:4516)67959: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4277)67960: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.draw(View.java:22356)67961: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at com.android.internal.policy.DecorView.draw(DecorView.java:806)67962: 12-19 12:11:58.177  5426  5426 D Choreographer: 	at android.view.View.updateDisplayListIfDirty(View.java:21229)67963: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:559)67964: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:565)67965: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:642)67966: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ViewRootImpl.draw(ViewRootImpl.java:4109)67967: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3836)67968: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3104)67969: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1948)67970: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8189)67971: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.Choreographer$CallbackRecord.run(Choreographer.java:984)67972: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.Choreographer.doCallbacks(Choreographer.java:808)67973: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.Choreographer.doFrame(Choreographer.java:743)67974: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:969)67975: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.os.Handler.handleCallback(Handler.java:938)67976: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.os.Handler.dispatchMessage(Handler.java:99)67977: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.os.Looper.loop(Looper.java:223)67978: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at android.app.ActivityThread.main(ActivityThread.java:7667)67979: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at java.lang.reflect.Method.invoke(Native Method)67980: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)67981: 12-19 12:11:58.178  5426  5426 D Choreographer: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)

第二路如下:

68295: 12-19 12:11:58.276  5426  5426 D Choreographer: main postCallback: postCallbackDelayedInternal type=1, action=android.animation.AnimationHandler$1@25a9b0, token=FRAME_CALLBACK_TOKEN, this = android.view.Choreographer@d4b390a,callstack =68296: 12-19 12:11:58.276  5426  5426 D Choreographer: java.lang.Throwable: xxxx
	行 68297: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.view.Choreographer.postCallbackDelayedInternal(Choreographer.java:467)68298: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.view.Choreographer.postFrameCallbackDelayed(Choreographer.java:557)68299: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.view.Choreographer.postFrameCallback(Choreographer.java:537)68300: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.animation.AnimationHandler$MyFrameCallbackProvider.postFrameCallback(AnimationHandler.java:248)68301: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.animation.AnimationHandler.addAnimationFrameCallback(AnimationHandler.java:95)68302: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.animation.ValueAnimator.addAnimationCallback(ValueAnimator.java:1529)68303: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.animation.ValueAnimator.start(ValueAnimator.java:1076)68304: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.animation.ValueAnimator.start(ValueAnimator.java:1106)68305: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at org.libpag.DisplayLink$a.run(SourceFile:1)68306: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.os.Handler.handleCallback(Handler.java:938)68307: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.os.Handler.dispatchMessage(Handler.java:99)68308: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.os.Looper.loop(Looper.java:223)68309: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at android.app.ActivityThread.main(ActivityThread.java:7667)68310: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at java.lang.reflect.Method.invoke(Native Method)68311: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:596)68312: 12-19 12:11:58.276  5426  5426 D Choreographer: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:965)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值