Android系统优化(65)---MTK 平台开关机、重启时间优化

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhangbijun1230/article/details/80821646
开关机、重启时间优化
 

一、开关机、重启时间优化:

开机性能优化:是用功能和其它因素多方面平衡的结果,片面追求单方面的性能没有太大意义;有些产品设计开机动画非常酷炫,动画图片过多、高帧率会影响开机速度,这时就需要看是开机速度优先还是体验优先;
1.zygote,预加载class、resources;加载的多了,会影响开机时间;
/sdcard/mtklog/bootprof
12450.516490 : 860-system_server : Android:PMS_READY
13136.536031 : 506-main : Zygote:Preload 4715 classes in 495ms
13263.841416 : 506-main : Zygote:Preload 64 obtain resources in 42ms
13271.525031 : 506-main : Zygote:Preload 41 resources in 6ms
13639.574263 : 860-system_server : AMS:systemReady
13645.305493 : 860-system_server : AMS:AMS_READY

/frameworks/base/config/preloaded-classes,因为少加载类会影响APP启动速度,开机过程会涉及到APP启动,此地没有优化空间;
/frameworks/base/core/res/会被打包成:framework-res.apk,确保没有冗余的资源图片,可以挨个检查图片、XML是否在系统中有用到;

2.开机动画进程bootanimation或者mtkbootanimation,走android比走movie流程占用内存资源要少些,开机会快些,测试大概快上百毫秒;
开机动画分两种情况:
(1)播放mp3,需要等到mp3播放完动画才能退出,开机才能完成;所以mp3文件不能过长,最好不要超过system_server启动时间;
system_server启动时间查看如下:
/sdcard/mtklog/bootprof
10367.726870 : 860-system_server : Android:SysServerInit_START
……
14137.026648 : 860-system_server : Android:SysServerInit_END
(2)不播放mp3,不会影响开机时间;
bootanimation.zip中图片越少越好;

3.修改风险较大,除非对开机速度有特别严苛的要求才修改:
/frameworks/base/services/java/com/android/server/SystemServer.java
比如:DropBoxManagerService和调试相关,可以异步加载或者直接阉割掉:
比如:PinnerService没有配置相关则可以去除;
其他Service可以挨个排查;

4.system_server特定的服务导致开机变慢,比如:指纹系统;
非必要的服务可以放在system_server进程外启动;

5.kernel init 时间长,需要先看一下客户的版本上init.rc文件相对Driveronly版本是否有添加新的init,这些是否都是必须添加的。
在uartlog 中,需要查关键字-----[ cut here ]------------ ,找到在kernel init 过程中,频繁打出的这些call stack,看这些call stack,排查一下所客制化的点。

6.在uartlog中排查驱动设备初始化是否有完成或延时较长

7.如果是刷机后第一次因为对apk进行dex2oat导致的开机慢:
 bootprof文件中包含PMS:performDexOpt,说明在编译时没有打开dex2oat选项;可以按照下面修改
 log示例如下:
/sdcard/mtklog/mobile/../bootprof
49643.453733 : 777-system_server : Android:PMS_READY
50662.038197 : 777-system_server : PMS:performDexOpt:com.mediatek.ims
50958.422582 : 434-main : Zygote:Preload 4715 classes in 957ms
51027.330659 : 777-system_server : PMS:performDexOpt:com.google.android.ext.services
51175.849890 : 434-main : Zygote:Preload 64 obtain resources in 89ms
51191.674429 : 434-main : Zygote:Preload 41 resources in 15ms
52011.623200 : 777-system_server : PMS:performDexOpt:com.android.providers.telephony
53090.475818 : 777-system_server : PMS:performDexOpt:com.valmul.defcontainer
53500.331742 : 777-system_server : PMS:performDexOpt:com.google.android.ext.shared
53759.386897 : 777-system_server : PMS:performDexOpt:com.figoglobal.gpsinitialization
55253.543054 : 777-system_server : PMS:performDexOpt:com.android.mms.service
55263.628131 : 777-system_server : PMS:performDexOpt:com.mediatek.wfo.impl
55270.579900 : 777-system_server : PMS:performDexOpt:com.android.defcontainer
55276.243746 : 777-system_server : PMS:performDexOpt:com.android.providers.settings
55278.248439 : 777-system_server : PMS:performDexOpt:com.android.inputdevices
55282.328746 : 777-system_server : PMS:performDexOpt:com.android.server.telecom
55294.016439 : 777-system_server : PMS:performDexOpt:com.android.dialer
55310.146285 : 777-system_server : PMS:performDexOpt:com.google.android.packageinstaller
56816.388981 : 777-system_server : PMS:performDexOpt:com.android.proxyhandler
56822.447212 : 777-system_server : PMS:performDexOpt:com.android.settings
56839.445365 : 777-system_server : PMS:performDexOpt:com.android.phone
56857.746212 : 777-system_server : PMS:performDexOpt:com.android.shell
56866.477442 : 777-system_server : PMS:performDexOpt:com.android.location.fused
56871.597365 : 777-system_server : PMS:performDexOpt:com.android.systemui
56890.546827 : 777-system_server : PMS:performDexOpt:com.mediatek.mtklogger
56902.493673 : 777-system_server : PMS:performDexOpt:com.mediatek.dataprotection
57298.609059 : 777-system_server : PMS:performDexOpt:com.google.android.inputmethod.latin
61557.196915 : 777-system_server : PMS:performDexOpt:com.android.fmradio
61565.777377 : 777-system_server : PMS:performDexOpt:com.mediatek.gba
61571.754300 : 777-system_server : PMS:performDexOpt:com.google.android.youtube
75712.856180 : 777-system_server : PMS:performDexOpt:com.google.android.googlequicksearchbox
99753.523929 : 777-system_server : PMS:performDexOpt:com.mediatek.camera
99774.462545 : 777-system_server : PMS:performDexOpt:com.android.providers.calendar
99784.232852 : 777-system_server : PMS:performDexOpt:com.android.providers.media
99789.938160 : 777-system_server : PMS:performDexOpt:com.google.android.apps.docs.editors.docs
114430.013733 : 777-system_server : PMS:performDexOpt:com.google.android.onetimeinitializer
114811.085504 : 777-system_server : PMS:performDexOpt:com.mediatek.location.lppe.main
115139.649966 : 777-system_server : PMS:performDexOpt:com.android.wallpapercropper
115144.646197 : 777-system_server : PMS:performDexOpt:com.android.protips
115150.169581 : 777-system_server : PMS:performDexOpt:com.android.documentsui
115166.986274 : 777-system_server : PMS:performDexOpt:com.android.externalstorage
115171.057197 : 777-system_server : PMS:performDexOpt:com.mediatek.ygps
115177.234966 : 777-system_server : PMS:performDexOpt:com.android.htmlviewer
115181.287581 : 777-system_server : PMS:performDexOpt:com.android.companiondevicemanager
115187.204274 : 777-system_server : PMS:performDexOpt:com.google.android.apps.docs.editors.sheets
130281.575156 : 777-system_server : PMS:performDexOpt:com.android.providers.downloads
130297.580156 : 777-system_server : PMS:performDexOpt:com.google.android.apps.messaging
136510.900478 : 777-system_server : PMS:performDexOpt:com.android.writeimei
136517.015402 : 777-system_server : PMS:performDexOpt:com.mediatek.engineermode
136533.084478 : 777-system_server : PMS:performDexOpt:com.otaupdater.client.pci
139099.409869 : 777-system_server : PMS:performDexOpt:com.google.android.apps.genie.geniewidget
141841.039414 : 777-system_server : PMS:performDexOpt:com.mediatek.omacp
141852.033722 : 777-system_server : PMS:performDexOpt:com.google.android.configupdater
143942.007804 : 777-system_server : PMS:performDexOpt:com.android.providers.downloads.ui
143950.975881 : 777-system_server : PMS:performDexOpt:com.android.vending
153350.969057 : 777-system_server : PMS:performDexOpt:com.android.pacprocessor
153357.482442 : 777-system_server : PMS:performDexOpt:com.android.certinstaller
153362.990057 : 777-system_server : PMS:performDexOpt:com.android.carrierconfig
153367.606672 : 777-system_server : PMS:performDexOpt:com.google.android.marvin.talkback
154832.208599 : 777-system_server : PMS:performDexOpt:com.google.android.apps.work.oobconfig
160397.116228 : 777-system_server : PMS:performDexOpt:com.android.egg
160407.464382 : 777-system_server : PMS:performDexOpt:com.android.mtp
160414.571766 : 777-system_server : PMS:performDexOpt:com.android.nfc
160427.387843 : 777-system_server : PMS:performDexOpt:com.android.stk
160435.046920 : 777-system_server : PMS:performDexOpt:com.android.launcher3
160447.006074 : 777-system_server : PMS:performDexOpt:com.android.backupconfirm
160452.568689 : 777-system_server : PMS:performDexOpt:com.mediatek.bluetooth.dtt
160465.013843 : 777-system_server : PMS:performDexOpt:com.google.android.deskclock
162244.236617 : 777-system_server : PMS:performDexOpt:com.android.statementservice
162251.229540 : 777-system_server : PMS:performDexOpt:com.google.android.gm
172015.771409 : 777-system_server : PMS:performDexOpt:com.google.android.apps.tachyon
176043.776419 : 777-system_server : PMS:performDexOpt:com.mediatek.mdmlsample
176051.331573 : 777-system_server : PMS:performDexOpt:com.mediatek.providers.drm
176056.306573 : 777-system_server : PMS:performDexOpt:com.google.android.setupwizard
177954.596039 : 777-system_server : PMS:performDexOpt:com.android.sharedstoragebackup
177960.795346 : 777-system_server : PMS:performDexOpt:com.mediatek.batterywarning
178219.600347 : 777-system_server : PMS:performDexOpt:com.google.android.music
187542.735908 : 777-system_server : PMS:performDexOpt:com.android.printspooler
187556.019446 : 777-system_server : PMS:performDexOpt:com.android.dreams.basic
187560.172908 : 777-system_server : PMS:performDexOpt:com.android.bips
187565.581754 : 777-system_server : PMS:performDexOpt:com.example
187844.819832 : 777-system_server : PMS:performDexOpt:com.mediatek.duraspeed
187854.295601 : 777-system_server : PMS:performDexOpt:com.android.musicfx
187859.364370 : 777-system_server : PMS:performDexOpt:com.google.android.apps.docs
195943.050389 : 777-system_server : PMS:performDexOpt:com.google.android.apps.maps
221750.079451 : 777-system_server : PMS:performDexOpt:com.google.android.apps.plus
230560.679933 : 777-system_server : PMS:performDexOpt:com.android.cellbroadcastreceiver
230576.272087 : 777-system_server : PMS:performDexOpt:com.google.android.webview
230830.527934 : 777-system_server : PMS:performDexOpt:com.google.android.contacts
234057.796942 : 777-system_server : PMS:performDexOpt:com.mediatek.nlpservice
234310.225942 : 777-system_server : PMS:performDexOpt:com.google.android.syncadapters.contacts
235439.648484 : 777-system_server : PMS:performDexOpt:com.android.facelock
236278.940486 : 777-system_server : PMS:performDexOpt:com.android.keychain
236285.839716 : 777-system_server : PMS:performDexOpt:com.google.android.calculator
237256.699719 : 777-system_server : PMS:performDexOpt:com.android.chrome
247269.808050 : 777-system_server : PMS:performDexOpt:com.google.android.gms
291173.412385 : 777-system_server : PMS:performDexOpt:com.google.android.gsf
291889.272310 : 777-system_server : PMS:performDexOpt:com.google.android.ims
294370.807931 : 777-system_server : PMS:performDexOpt:com.google.android.tag
294895.197548 : 777-system_server : PMS:performDexOpt:com.google.android.tts
296506.454398 : 777-system_server : PMS:performDexOpt:com.google.android.gmsintegration
296517.176552 : 777-system_server : PMS:performDexOpt:com.android.calllogbackup
296520.955705 : 777-system_server : PMS:performDexOpt:com.google.android.partnersetup
297375.172707 : 777-system_server : PMS:performDexOpt:com.valmedia.fdelux
299746.301790 : 777-system_server : PMS:performDexOpt:com.google.android.videos
305182.171495 : 777-system_server : PMS:performDexOpt:com.android.carrierdefaultapp
305190.510726 : 777-system_server : PMS:performDexOpt:com.google.android.feedback
305740.677035 : 777-system_server : PMS:performDexOpt:com.google.android.printservice.recommendation
306011.271036 : 777-system_server : PMS:performDexOpt:com.google.android.apps.photos
319736.751530 : 777-system_server : PMS:performDexOpt:com.google.android.calendar
324612.068619 : 777-system_server : PMS:performDexOpt:com.android.managedprovisioning
324623.492234 : 777-system_server : PMS:performDexOpt:com.mediatek.calendarimporter
324631.520311 : 777-system_server : PMS:performDexOpt:com.mediatek.thermalmanager
324959.254850 : 777-system_server : PMS:performDexOpt:com.mediatek.callrecorder
324964.480081 : 777-system_server : PMS:performDexOpt:com.mediatek.webview
327421.028548 : 777-system_server : PMS:performDexOpt:com.android.providers.partnerbookmarks
327429.625548 : 777-system_server : PMS:performDexOpt:com.mediatek.factorymode
327437.938548 : 777-system_server : PMS:performDexOpt:com.mtk.telephony
327691.050318 : 777-system_server : PMS:performDexOpt:com.baidu.map.location
328728.378167 : 777-system_server : PMS:performDexOpt:com.google.android.apps.translate
332677.203715 : 777-system_server : PMS:performDexOpt:com.google.android.backuptransport
332928.584946 : 777-system_server : PMS:performDexOpt:com.android.storagemanager
332944.970254 : 777-system_server : PMS:performDexOpt:com.android.bookmarkprovider
332949.513254 : 777-system_server : PMS:performDexOpt:com.google.android.inputmethod.pinyin
335415.889952 : 777-system_server : PMS:performDexOpt:com.mediatek.mdmconfig
335425.267183 : 777-system_server : PMS:performDexOpt:com.google.android.apps.books
341578.219044 : 777-system_server : PMS:performDexOpt:com.mediatek.lbs.em2.ui
341986.969814 : 777-system_server : PMS:performDexOpt:com.android.vpndialogs
341993.090198 : 777-system_server : PMS:performDexOpt:com.google.android.keep
346305.760132 : 777-system_server : PMS:performDexOpt:com.android.wallpaperbackup
346314.091670 : 777-system_server : PMS:performDexOpt:com.android.providers.blockednumber
346323.088055 : 777-system_server : PMS:performDexOpt:com.android.providers.userdictionary
346327.427440 : 777-system_server : PMS:performDexOpt:com.android.emergency
346342.475132 : 777-system_server : PMS:performDexOpt:com.android.bluetoothmidiservice
346346.436670 : 777-system_server : PMS:performDexOpt:com.mediatek.location.mtknlp
346351.760286 : 777-system_server : PMS:performDexOpt:com.mediatek.filemanager
346359.031132 : 777-system_server : PMS:performDexOpt:com.mediatek.sensorhub.ui
346363.830824 : 777-system_server : PMS:performDexOpt:com.google.android.play.games
350019.136756 : 777-system_server : PMS:performDexOpt:com.google.android.apps.magazines
357144.564619 : 777-system_server : PMS:performDexOpt:com.android.bluetooth
357162.350619 : 777-system_server : PMS:performDexOpt:com.android.wallpaperpicker
357168.592542 : 777-system_server : PMS:performDexOpt:com.android.providers.contacts
357180.100773 : 777-system_server : PMS:performDexOpt:com.android.captiveportallogin
357184.506389 : 777-system_server : PMS:performDexOpt:com.mediatek.mtklogger.proxy
362317.530247 : 777-system_server : AMS:systemReady
362327.296170 : 777-system_server : AMS:AMS_READY

在/device和/build目录下,修改下面的宏,具体下面3个宏的位置可以在代码中搜索一下:
build/core/dex_preopt.mk
WITH_DEXPREOPT := true 
WITH_DEXPREOPT_PIC := true
DONT_DEXPREOPT_PREBUILTS := false //或者注释掉

8.尽量少把APP设置为persist;
优化每一个有源码的persist APP;使他们启动尽可能快;
com.android.systemui(PersistAP)
com.mediatek.ims(PersistAP)
com.android.phone(PersistAP)
com.android.settings
精简apk包;
(1)删除没有用到的,图片、资源文件、没有用到的jar包文件、不需要使用的so文件;
(2)预置自己的APP,假如设备只会加载drawable-xxhdpi中的资源,那么可以在drawable包重复的资源可以直接删除;
(3)预置自己的APP,假如设置只支持英文,values-da、values-fa这样的多语言支持资源都可以删除;
(4)apk中只保留和系统适配的so文件,比如:armv7和arm64的so文件;

Application的onCreate方法中不要有耗时的代码段;
 通过修改--compiler-filter为speed、quick、speed-profile来提高apk的启动速度;speed模式优化的类较多,这时优化后的vdex、odex的文件较大,应用启动过程包括映射apk文件的过程,文件偏大导致有一定的时间损耗;但speed模式优化后,Java类执行更快;所以这个需要针对具体的应用多次验证,没有普适性;
Android O、N版本修改dex2oat编译选项,减少占用ROM空间或者加快安装速度

9.定频定核,调高CPU频率,会带来一定的功耗:
以6763的O1版本代码为例:
/system/core/rootdir/init.rc
on early-init
#mtk begin
write /proc/ppm/policy/ut_fix_core_num "4 4"
write /proc/ppm/policy/ut_fix_freq_idx "0 0"
#mtk end

on property:sys.boot_completed=1
bootchart stop
#mtk begin
write /proc/ppm/policy/ut_fix_core_num "-1 -1"
write /proc/ppm/policy/ut_fix_freq_idx "-1 -1"
#mtk end

10.客制化进程的启动速度关注一下,是否有影响开机速度的;

11.PackageManagerService
scanDirTracedLI
(1)减少预置APP的数量(对开机速度会有较为明显的提升);
(2)删除没有必要的apk包;
(3)单线程scan分区里面的apk并不一定能充分使用IO资源,尝试改为多线程异步scan;
(部分手机厂商有做出此种修改,且效果较为明显,但修改需谨慎);
(4)精简系统,把系统中用不到的apk包、有重复功能的apk移除(比如:我司代码默认包含有计算器APP,如果贵司有自己单独的计算器APP则可以移除我司apk),这样既可以使系统有更大的剩余存储空间又可以减少scan的时间,加快开机;
 
12.关机时间优化:
以MTK6763为例:
[ro.mediatek.version.branch]: [alps-mp-o1.mp1]
可以把下面这个时间改为1s(可以自己测试找一个最优值),然后关机音频控制在1s(否则音频播放不完整),或者关机时不播放铃声,把这个值设置为10ms;
/frameworks/base/services/core/java/com/android/server/power/ShutdownThread.java
149 // Shutdown Animation
150 private static final int MIN_SHUTDOWN_ANIMATION_PLAY_TIME = 1 * 1000;
 
13.关机时间长的另外一个原因有可能是后台应用乱跑;尤其国内一些有保活的APP,在后台都在积极抢占CPU,在手机系统资源紧张时对系统的性能影响是非常大的;手机使用过程中,适当的限制后台进程的数量,会一定程度提高系统性能和更快的关机;
 还有些APP一直保持有1个像素的悬浮窗,使自己一直为可见进程,可见进程能更多的占用系统资源,手机系统可以增加悬浮窗的权限管控开关只有获取到了才允许悬浮,可以更加合理的非配系统资源。
 
 谷歌官方开机优化资料:
https://source.android.com/devices/tech/perf/boot-times
阅读更多

扫码向博主提问

zhangbijun1230

非学,无以致疑;非问,无以广识
  • 擅长领域:
  • Android系统
  • IOT
  • 大数据
  • AI
  • 手机功耗
去开通我的Chat快问

没有更多推荐了,返回首页