APP启动时间检测——u-apm

本文介绍了Android应用的冷启动知识及其重要性,探讨了通过adb命令、logcat和代码中的reportFullyDrawn()方法测量APP启动时间的方法,并重点讲解了友盟+u-apm工具在启动分析、内存分析和卡顿分析方面的功能,帮助开发者优化启动性能。

众所周知APP启动时间是用户对一款APP的第一印象,如果某一款APP启动时间要耗费8秒之久,那么,用户对研发成员的能力就会产生质疑,也会否定开发者辛辛苦苦熬夜赶出来的成果,这也是我们不想看到的,但是产生了性能问题我们就要勇敢的去面对,怎样检测APP启动时间呢?怎样能实时检测启动中发生的性能问题呢?就这篇文章来浅谈相关知识!

一、冷启动的相关知识

启动分为冷启动和热启动,一般的优化都是针对冷启动来进行,本文主要分析冷启动。

冷启动是Android性能测试中的重要指标,即应用从进程未创建到完全启动的时间,一般要求时长<1.5s,过长需要考虑优化。

比如:设备启动后,APP第一次Launch或者APP被Kill掉后的重启。这种类型的启动优化存在很大挑战,因为Android系统或应用还有其他更多的后台进程在运行。

启动流程大致如下:

点击Launcher 上的 icon开加载app -->立即显示白屏或黑屏等 --> Application onCreate --> Activity Init----> Activity onCreate ---> 初始化数据,填充显示View ---> Activity onResume等。

二、App 启动时间测量与分析

如何获取APP启动时间,请看以下测量方法

1.通过 adb 命令测量APP 冷启动时间

使用adb 命令直接启动APP进而测量APP启动耗时 的方法如下:

adb shell am start -W [packageName]/[packageName.MainActivity]`

adb [-d|-e|-s ] shell am start -S -W [packageName]/[packageName.MainActivity] -c android.intent.category.LAUNCHER -a android.intent.action.MAIN

2.通过 adb logcat 查看APP 启动时间

在Log中,主

行 22096: 10-30 14:23:44.091663 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 22101: 10-30 14:23:44.104129 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 22810: 10-30 14:23:44.511537 3177 4886 D AS.AudioService: setMode , mode =0 from pid=20217, ignore same settings 行 22818: 10-30 14:23:44.512242 3177 4069 D AudioServiceExtImpl: +notifyAtlasServiceModesUpdate onlyRead :true 行 22819: 10-30 14:23:44.512252 3177 4069 D AudioServiceExtImpl: modekey = allmodes= 行 22820: 10-30 14:23:44.512660 3177 4069 D AudioServiceExtImpl: -notifyAtlasServiceModesUpdate 行 26102: 10-30 14:23:46.923723 3177 4926 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26124: 10-30 14:23:46.939763 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26127: 10-30 14:23:46.940486 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26138: 10-30 14:23:46.941381 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26144: 10-30 14:23:46.943131 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26147: 10-30 14:23:46.944109 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26244: 10-30 14:23:46.995399 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26247: 10-30 14:23:46.997153 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26259: 10-30 14:23:47.001285 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26275: 10-30 14:23:47.003644 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26278: 10-30 14:23:47.005067 3177 4886 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26281: 10-30 14:23:47.008914 3177 3840 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26283: 10-30 14:23:47.009915 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26306: 10-30 14:23:47.013623 3177 4926 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26315: 10-30 14:23:47.020521 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26334: 10-30 14:23:47.024803 2010 7490 D AudioPolicyManagerExtImpl: checkUllCompatible() denied raw flag on session 241 for performance noise 行 26335: 10-30 14:23:47.024873 2010 7490 D AudioPolicyManagerExtImpl: forceOutputForMusicEffects Enter: session 241, dev {AUDIO_DEVICE_OUT_USB_HEADSET, @:card=1;device=0}, streamType 3, flags 4, forced_deep 0 行 26336: 10-30 14:23:47.025086 2010 7490 D AudioPolicyManagerExtImpl: check callingUid 10370 whose pacakge name is not in fast-audio-effects 行 26337: 10-30 14:23:47.025115 2010 7490 D AudioPolicyManagerExtImpl: forceOutputForMusicEffects Done: flags 4, forced_deep 0 行 26338: 10-30 14:23:47.025160 2010 7490 D APM_AudioPolicyManager: mSpatializerOutput is null, canBeSpatializedInt=0, forceSpatialized:0 forceMss 0 forceMeta 0 行 26351: 10-30 14:23:47.027718 3177 4926 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26356: 10-30 14:23:47.028603 3177 4926 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26374: 10-30 14:23:47.029000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1008): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26412: 10-30 14:23:47.037000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1009): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26449: 10-30 14:23:47.057000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1010): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26458: 10-30 14:23:47.060190 2010 2627 D APM_AudioPolicyManager: startOutput() output 13, stream 3, portId 119, session 241 行 26466: 10-30 14:23:47.066707 2010 2627 D AudioPolicyManagerExtImpl: oplusSelectOutputForMusicEffects: pendingOutput => 13 flags => 0x00000006 outputTageName =>primary output outputs.size(6) older music effect ouput(29), hasAliveGameTracks(0) 行 26467: 10-30 14:23:47.066711 2010 2627 D AudioPolicyManagerExtImpl: oplusSelectOutputForMusicEffects pending music output is low latency output, but no alive fast effect tracks, block effectchain fallback to primary, set deepbuffer as defaultEffectsOutput instead 行 26471: 10-30 14:23:47.067035 2010 2627 D APM_AudioPolicyManager: setOutputDevice() output 13 device {AUDIO_DEVICE_OUT_USB_HEADSET, @:card=1;device=0} force 1 delayMs 0 行 26504: 10-30 14:23:47.085063 3177 4886 D AS.AudioService: uid 1000, callingApp = android.uid.system:1000 行 26588: 10-30 14:23:47.101000 2010 2010 W AudioRtBoostThr: type=1400 audit(0.0:1011): avc: denied { getsched } for scontext=u:r:audioserver:s0 tcontext=u:r:untrusted_app:s0:c114,c257,c512,c768 tclass=process permissive=0 行 26809: 10-30 14:23:47.131542 3177 3340 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 26900: 10-30 14:23:47.139858 3177 4937 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 27070: 10-30 14:23:47.200767 3177 4998 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 27079: 10-30 14:23:47.209432 3177 4478 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 27628: 10-30 14:23:47.600224 3177 4069 D AS.AudioService: uid 1000, callingApp = android.uid.system:1000 行 27755: 10-30 14:23:47.677392 3177 4069 D AS.AudioService: uid 1000, callingApp = android.uid.system:1000 行 28312: 10-30 14:23:47.952669 3177 4994 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 28316: 10-30 14:23:47.955313 3177 4994 D AS.AudioService: uid 10370, callingApp = sg.bigo.live 行 28382: 10-30 14:23:47.991765 3177 4936 D AS.AudioService: setMode , mode =0 from pid=20217, ignore same settings 行 28389: 10-30 14:23:47.998511 3177 4069 D AudioServiceExtImpl: +notifyAtlasServiceModesUpdate onlyRead :true 行 28390: 10-30 14:23:47.998548 3177 4069 D AudioServiceExtImpl: modekey = allmodes= 行 28409: 10-30 14:23:48.001992 3177 4069 D AudioServiceExtImpl: -notifyAtlasServiceModesUpdate 行 28459: 10-30 14:23:48.013843 2010 2627 D APM_AudioPolicyManager: stopOutput portId 119 行 28460: 10-30 14:23:48.013858 2010 2627 D APM_AudioPolicyManager: stopOutput() output 13, stream 3, session 241能分析出为啥没有创建audiorecord么
最新发布
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值