MMI开机时间偏长
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MMI开机时间偏长相关的知识,希望对你有一定的参考价值。
Mini版本开机时间长
1. Problem Description:
Mini版本主要是用来测试手机硬件的一款软件,
2. Analysis:
开机较慢的原因是在开机过程中会的data分区进行加密操作,而这个操作对应内部测试并没有什么用,因此可以去掉。然后是在开机过程中会安装APK,这会占用很多的开机时间,安装的这些APK中有许多并不是必备的,所以去掉那些无用的APK可以缩短开机时间。针对这个,可以设定在编译阶段就不编译这些APK。然后就是开机过程中会有些预优化,其优化的目的是节约手机内存即“用时间来换取空间”的策略。所以对降低开机时间主要在如下3个方面进行操作:
- 关闭data 加密
- 通过mmitest_skip_modules.mk 过滤多余APK
- 去掉预优化
3. Solution:
- 关闭data分区
在文件vendor/mediatek/proprietary/hardware/fstab/mt6755/android.mk中进行如下修改:
ifeq ($(strip $(MTK_ENCRYPTION_DEFAULT_OFF)),yes)
__CFLAGS +=-D__MTK_FDE_NO_FORCE
else ifeq ($(strip $(CUSTOM_CONFIG_MAX_DRAM_SIZE)),0x20000000)
__CFLAGS +=-D__MTK_FDE_NO_FORCE
else ifeq ($(strip $(TARGET_BUILD_MMITEST)),true)
__CFLAGS +=-D__MTK_FDE_NO_FORCE
endif
ifeq ($(strip $(MTK_TEE_SUPPORT)),yes)
ifeq ($(strip $(MTK_ENCRYPTION_TYPE_FILE)),yes)
__CFLAGS +=-D__MTK_FDE_TYPE_FILE
endif
endif
条件语句ifeq ($(strip $(TARGET_BUILD_MMITEST)),true)
会进行判断,如果是编译的MINI软件,会添加__MTK_FDE_NO_FORCE
宏定义。在文件fstab.in中会进行判断:
#ifdef __MTK_FDE_NO_FORCE
/*打开此项, 即默认不强制加密*/
#define FLAG_FDE_AUTO encryptable
#else
#define FLAG_FDE_AUTO forceencrypt
- 通过mmitest_skip_modules.mk 过滤多余APK
在文件build/core/main.mk中如如下判断:
ifeq ($(TARGET_BUILD_MMITEST),true)
$(warning skip_before: $(product_MODULES))
product_MODULES := $(filter-out $(MMITEST_SKIP_MODULES),$(product_MODULES))
$(warning skip_after: $(product_MODULES))
即如果编译的是TARGET_BUILD_MMITEST版本,会过虑掉mmitest_skip_modules.mk中的模块,所以需要将不需要的APK加入到文件mmitest_skip_modules.mk中。
- 去掉预优化
预优化(pre-optimization)是通过宏WITH_DEXPREOPT控制,如将宏开关DONT_DEXPREOPT_PREBUILTS设为true后,将不会对 Android.mk中包含了 include $(BUILD_PREBUILT)的Apk进行预优化,从而加快第一次开机的启动时间。
主要对如下几个宏开关进行操作:- WITH_DEXPREOPT
打开(Enable)宏开关WITH_DEXPREOPT,会使system image 中的所有apk, jar 文件参与预优化,这会大大增大system image的大小 - WITH_DEXPREOPT_PIC
设为true时,dex2oat编译生成的 odex文件在运行时将不必再从 /system 下拷贝到 /data/dalvik-cache/ 目录下, 可以节省 /data 空间。可能会对性能有轻微影响,但为了节省空间,可以这么做。(there is a slight runtime impact because it disables an optimization that takes advantage of position-dependent code. Typically, devices wanting to save space in /data should enable PIC compilation.)
设为false时,system中已经存在 class.odex的 apk,第一次开机后还是会在 /data下面生成 class.odex,如data/dalvik-cache/arm64/[email protected]@[email protected]@classes.dex,这是何解?原来 Google为了提高安全性,在每一台机器开机时都会在之前的机器码加一个随机的偏移量,这个偏移量是随机的,每台机器都不相同,而 data分区下的这些文件就是从 system下的 class.odex加上偏移而来。 - DONT_DEXPREOPT_PREBUILTS
设为true后,将不会对 Android.mk中包含了 include $(BUILD_PREBUILT)的 Apk进行预优化,例如 Gmail,它很可能会在后期通过商店升级,而升级后系统中的 oat文件则没有意义了,但又无法删除,会造成空间的浪费(oat比dex文件要大)。
Enable DONT_DEXPREOPT_PREBUILTS,节省system 空间,增长第一次开机时间。 - WITH_DEXPREOPT_BOOT_IMG_ONLY
打开该宏开关将针对 boot image进行预优化,节省system相当一部分空间,但是会延长开机时间(意味着对所有的apk都不做优化)。
- WITH_DEXPREOPT
对文件build/core/dex_preopt.mk中,具体修改如下:
ifeq ($(TARGET_BUILD_VARIANT),eng)
ifeq ($(TARGET_BUILD_MMITEST),true)
WITH_DEXPREOPT :=true
WITH_DEXPREOPT_PIC :=true
else
WITH_DEXPREOPT :=false
DONT_DEXPREOPT_PREBUILTS :=false
endif
endif
ifeq (eng,$(TARGET_BUILD_VARIANT))
ifeq ($(TARGET_BUILD_MMITEST),true)
WITH_DEXPREOPT_BOOT_IMG_ONLY ?=false
else
WITH_DEXPREOPT_BOOT_IMG_ONLY ?=true
endif
ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
PRODUCT_DEX_PREOPT_BOOT_FLAGS +=--generate-mini-debug-info
endif
endif
4. Summary:
针对这个问题,需要知道主要的耗时操作在什么地方,然后进行分析后来优化操作。可以通过命令adb shell cat /proc/bootprof
来查看开机时的时间消耗情况。同时通过命令adb shell
&&pm list package -f
查看系统安装的APK情况,然后对无用的APK进行优化。需要注意的是有的APK相关的.so文件是系统所必须的,如果未将这部分APK编译进行系统,会导致系统无法正常开机。
可以将开机过程划分成如下几个阶段来进行分析:
第一次开机时间 | ||||
---|---|---|---|---|
开始时间 | 开始标志 | 结束时间 | 结束标志 | |
preloader | ||||
lk | ||||
kernel init | 0 | 7115.804323 | Kernel_init_done | |
mount pattition | 9506.666791 | INIT:Mount_START | 13455.14742 | INIT:Mount_END |
android boot | 50378.09604 | Zygote:Preload Start | 62539.99315 | Zygote:Preload End |
package scan | 77678.46488 | Android:PackageManagerService_Start | 136793.9336 | Android:PMS_READY |
app initiationlization | 136793.9336 | Android:PMS_READY | 189794.6175 | BOOT_Animation:END |
下面是优化后开机时间的实际情况:
注:
[email protected]-Lenovo-Product:/local$ adb shell cat /proc/bootprof
----------------------------------------
0 BOOT PROF (unit:msec)
----------------------------------------
3220: preloader
3667: lk
----------------------------------------
371.855769: ON
865.905540:1-swapper/0: initcall: of_init 227.898155ms
893.704540:1-swapper/0: initcall: ramoops_init 17.496000ms
952.617924:1-swapper/0: initcall: init_mtk_governor 23.135538ms
1021.233232:1-swapper/0: initcall: mt_power_management_init 25.048539ms
1301.584079:1-swapper/0: initcall: arm64_device_init 237.500924ms
1460.799464:1-swapper/0: initcall: param_sysfs_init 150.824308ms
1492.303310:1-swapper/0: initcall: pm_sysrq_init 28.820616ms
1554.894772:1-swapper/0: initcall: MTK_M4U_Init 25.420154ms
1600.313234:1-swapper/0: probe: probe=platform_drv_probe drv=mtk_cmdq(ffffffc00160fd78)35.709539ms
1605.032926:1-swapper/0: initcall: cmdq_init 41.354385ms
1730.910926:1-swapper/0: initcall: cfg80211_init 21.485846ms
2122.880696:1-swapper/0: initcall: event_trace_init 371.556078ms
2261.964774:1-swapper/0: probe: probe=platform_drv_probe drv=mt-pmic(ffffffc001604300)95.811769ms
2266.137928:1-swapper/0: initcall: pmic_mt_init 101.656769ms
2324.955082:1-swapper/0: initcall: inet_init 33.181154ms
2507.386236:1-swapper/0: initcall: populate_rootfs 177.119692ms
2735.783313:1-swapper/0: initcall: slab_sysfs_init 145.808231ms
2922.011391:1-swapper/0: initcall: pty_init 17.699615ms
2960.162160:1-swapper/0: initcall: loop_init 29.996923ms
3028.701775:1-swapper/0: initcall: mt_gpufreq_init 17.778692ms
3072.091545:1-swapper/0: initcall: hps_init 26.006461ms
3098.926776:1-swapper/0: initcall: mtk_uart_init 15.949923ms
3283.340622:1-swapper/0: probe: probe=i2c_device_probe drv=pn544(ffffffc0015f64a8)86.596615ms
3285.073776:1-swapper/0: probe: probe=platform_drv_probe drv=mt-i2c(ffffffc0016000e8)90.320847ms
3289.343622:1-swapper/0: initcall: mt_i2c_init 109.559615ms
3336.911699:1-swapper/0: probe: probe=platform_drv_probe drv=Accdet_Driver(ffffffc001601f88)24.650847ms
3342.731930:1-swapper/0: initcall: accdet_mod_init 34.558538ms
3362.740776:1-swapper/0: initcall: init 18.654000ms
3443.727469:1-swapper/0: probe: probe=platform_drv_probe drv=musb-hdrc(ffffffc00160bd38)20.658847ms
3445.988392:1-swapper/0: probe: probe=platform_drv_probe drv=musb-mtu3d(ffffffc00160c008)23.848616ms
3450.176623:1-swapper/0: initcall: mtu3d_driver_init 29.606231ms
3710.967392:1-swapper/0: probe: probe=mtkfb_probe drv=mtkfb(ffffffc001612008)223.363924ms
3714.922854:1-swapper/0: initcall: mtkfb_init 231.631924ms
3751.890316:1-swapper/0: probe: probe=platform_drv_probe drv=mali(ffffffc001617578)21.980308ms
3755.982085:1-swapper/0: initcall: kbase_platform_driver_init 27.714923ms
3863.481316:1-swapper/0: probe: probe=i2c_device_probe drv=kd_camera_hw(ffffffc00161a448)57.799539ms
3865.574854:1-swapper/0: probe: probe=platform_drv_probe drv=image_sensor(ffffffc00161a1e0)85.040846ms
3873.808316:1-swapper/0: initcall: CAMERA_HW_i2C_init 99.528308ms
3962.954393:1-swapper/0: probe: probe=platform_drv_probe drv=kd_camera_flashlight(ffffffc00161e258)59.763000ms
3969.943778:1-swapper/0: initcall: flashlight_init 75.757616ms
4090.410316:1-swapper/0: probe: probe=platform_drv_probe drv=cldma_modem(ffffffc00162d590)108.923078ms
4095.188932:1-swapper/0: initcall: modem_cd_init 114.386231ms
4153.136394:1-swapper/0: initcall: BTIF_init 39.421231ms
4286.060009:1-swapper/0: initcall: mtk_cooler_dtm_init 24.058692ms
4339.072932:1-swapper/0: initcall: emi_mpu_mod_init 23.010693ms
4364.575009:1-swapper/0: initcall: init 18.190692ms
4440.468856:1-swapper/0: probe: probe=platform_drv_probe drv=HardwareInfo(ffffffc001639f08)53.160539ms
4443.734163:1-swapper/0: initcall:HardwareInfo_mod_init58.462154ms
4575.167471:1-swapper/0: probe: probe=platform_drv_probe drv=mtk-kpd(ffffffc00164df40)15.611769ms
4580.932318:1-swapper/0: initcall: kpd_mod_init 22.393846ms
4690.719933:1-swapper/0: probe: probe=platform_drv_probe drv=battery_meter(ffffffc001661020)83.773770ms
4692.538703:1-swapper/0: probe: pdev=battery_meter(ffffffc001660cd0)86.807769ms
4694.067472:1-swapper/0: probe: probe=platform_drv_probe drv=battery_meter_dts(ffffffc0016610d0)89.507462ms
4697.669010:1-swapper/0: initcall: battery_meter_init 96.310308ms
4747.176241:1-swapper/0: initcall: mt67xx_v2_cpuidle_init 25.403769ms
4776.516934:1-swapper/0: initcall: mt_msdc_init 23.781692ms
5067.848319:1-swapper/0: probe: probe=platform_drv_probe drv=soc-audio(ffffffc0016774a0)121.699693ms
5068.152934:1-swapper/0: initcall: mt_soc_snd_init 123.002000ms
5120.639396:1-swapper/0: initcall: inet6_init 32.686385ms
5340.091243:1-swapper/0: initcall: enable_ftrace 194.529078ms
5373.725781:1-swapper/0: initcall: add_shrinker_debug 30.885000ms
5485.367704:1-swapper/0: initcall: mt_dcm_init 88.614615ms
5532.398243:1-swapper/0: probe: probe=platform_drv_probe drv=mt-cpufreq(ffffffc0015f0198)35.841154ms
5535.746935:1-swapper/0: initcall: _mt_cpufreq_pdrv_init 43.911154ms
5543.812781:6-kworker/u16:0: probe: probe=mmc_bus_probe drv=mmcblk(ffffffc001668c40)72.474692ms
5670.824782:1-swapper/0: probe: probe=i2c_device_probe drv=stk3x1x(ffffffc0015fd9c8)89.990308ms
5682.310166:1-swapper/0: initcall: alsps_init 107.247231ms
5707.768705:1-swapper/0: probe: probe=i2c_device_probe drv=BMA2XX(ffffffc0015fe440)21.252154ms
5717.638936:1-swapper/0: initcall: acc_init 32.605384ms
5784.254397:1-swapper/0: probe: probe=i2c_device_probe drv=bmg250_gyro(ffffffc0015ff168)64.123231ms
5802.952705:1-swapper/0: initcall: gyro_init 84.019539ms
5820.408705:1-swapper/0: initcall: mag_init 16.166846ms
5841.251475:1-swapper/0: initcall: step_c_init 19.552769ms
5873.744628:1-swapper/0: initcall: devapc_init 15.065000ms
5953.311398:1-swapper/0: initcall: init 62.161462ms
6636.759323:1-swapper/0: probe: probe=spi_drv_probe drv=fp_spi(ffffffc00165b6a0)390.230540ms
6850.068400:1-swapper/0: probe: probe=platform_drv_probe drv=fp_drv(ffffffc00164daf0)892.541617ms
6853.522477:1-swapper/0: initcall: fp_drv_init 898.986541ms
6890.832323:1-swapper/0: initcall: battery_init 27.719308ms
6939.269631:147-kworker/u16:2: probe: probe=platform_drv_probe drv=battery(ffffffc001663978)42.569539ms
6939.860093:147-kworker/u16:2: probe: pdev=battery(ffffffc0016635a8)45.113385ms
6939.923785:147-kworker/u16:2: probe: probe=platform_drv_probe drv=battery-dts(ffffffc001663160)46.362692ms
7076.133477:1-swapper/0: initcall: clk_debug_init 169.705539ms
7110.142478:1-swapper/0: initcall: regulator_init_complete 26.655154ms
7124.238862:1-swapper/0:Kernel_init_done
7346.506940:6-kworker/u16:0: probe: probe=i2c_device_probe drv=fts(ffffffc00164f200)461.019770ms
7380.387632:6-kworker/u16:0: probe: probe=platform_drv_probe drv=mtk-tpd(ffffffc00164e1b0)505.097539ms
8436.728096:1-init : INIT:early-init
9527.990176:1-init : INIT:late-init
9529.631329:1-init : INIT:Mount_START
13540.467877:1-init : INIT:Mount_END
13564.849262:1-init : setup mobicore perms ++(on fs)
13572.114570:1-init : setup mobicore perms --(on fs)
15212.874112:1-init : INIT:post-fs
16440.699577:1-init : INIT:post-fs-data
16635.690577:1-init : post-fs-data: on modem start
16951.829809:1-init : INIT:boot
17245.023579:1-init : create /data/misc/mcRegistry ++(unencrypted)
17246.505271:1-init : create /data/misc/mcRegistry --(unencrypted)
17247.555963:1-init : create /data/misc/mcRegistry ++(unencrypted)
17249.106502:1-init : create /data/misc/mcRegistry --(unencrypted)
17284.131502:328-wmt_loader : probe: probe=platform_drv_probe drv=fm(ffffffc001633d10)47.623538ms
20117.511509:340-surfaceflinger : BOOT_Animation:START
22752.109976:381-main :Zygote:PreloadStart
22901.186131:380-main :Zygote:PreloadStart
25185.028905:380-main :Zygote:Preload4161 classes in2124ms
25203.203751:381-main :Zygote:Preload4161 classes in2299ms
26061.491523:380-main :Zygote:Preload114 obtain resources in405ms
26065.363292:381-main :Zygote:Preload114 obtain resources in415ms
26087.808215:380-main :Zygote:Preload41 resources in24ms
26089.247907:381-main :Zygote:Preload41 resources in22ms
26370.564985:380-main :Zygote:PreloadEnd
26500.120062:381-main :Zygote:PreloadEnd
26715.354986:857-system_server :Android:SysServerInit_START
28576.801452:857-system_server :Android:PackageManagerService_Start
28886.731453:857-system_server :Android:PMS_scan_START
29073.939761:857-system_server :Android:PMS_scan_data:/vendor/overlay
30086.105455:857-system_server :Android:PMS_scan_data:/system/framework
30408.115379:857-system_server :Android:PMS_scan_data:/vendor/framework
30513.919072:857-system_server :Android:PMS_scan_data:/system/custpack/app/unremoveable/priv-app
30933.341996:857-system_server :Android:PMS_scan_data:/system/custpack/app/unremoveable/withlibs
31652.178228:857-system_server :Android:PMS_scan_data:/system/priv-app
34101.119465:857-system_server :Android:PMS_scan_data:/system/app
36764.976164:857-system_server :Android:PMS_scan_data:/vendor/priv-app
36875.507164:857-system_server :Android:PMS_scan_data:/system/vendor/app
37153.869472:857-system_server :Android:PMS_scan_data:/vendor/plugin
37226.375626:857-system_server :Android:PMS_scan_END
49955.817887:857-system_server :Android:PMS_READY
56871.808288:857-system_server : AMS:systemReady
56897.408827:857-system_server : AMS:AMS_READY
57065.576981:935-ActivityManager: AP_Init:[broadcast]:[com.android.settings]:[com.android.settings/.wifi.WifiPreconfigAPReceiver]:pid:1460
57140.895520:857-system_server : AP_Init:[service]:[com.android.inputmethod.latin]:[com.android.inputmethod.latin/.LatinIME]:pid:1476
57350.931367:935-ActivityManager: AP_Init:[broadcast]:[android.process.media]:[com.android.providers.media/.MtpReceiver]:pid:1494
57426.956059:857-system_server : AP_Init:[service]:[com.android.systemui]:[com.android.systemui/.SystemUIService]:pid:1508:(PersistAP)
58150.542907:857-system_server :SystemServer:NetworkManagementService systemReady
58427.997369:857-system_server :SystemServer:NetworkStatsService systemReady
59029.889063:857-system_server :SystemServer:NetworkPolicyManagerService systemReady
59106.422755:857-system_server :SystemServer:ConnectivityService systemReady
59417.024295:857-system_server :SystemServer:PhaseThirdPartyAppsCanStart
59480.887141:857-system_server : AP_Init:[added application]:[com.android.phone]:[com.android.phone]:pid:1625:(PersistAP)
59534.872987:857-system_server : AP_Init:[added application]:[com.mediatek.ims]:[com.mediatek.ims]:pid:1639:(PersistAP)
59588.214526:857-system_server : AP_Init:[added application]:[com.mediatek.wfo.impl]:[com.mediatek.wfo.impl]:pid:1653:(PersistAP)
59645.845064:857-system_server : AP_Init:[added application]:[se.dirac.acs]:[se.dirac.acs]:pid:1667:(PersistAP)
59657.955141:857-system_server : AMS:ENABLE_SCREEN
59714.057064:857-system_server :Android:SysServerInit_END
64974.737462:496-Binder:340_1 : BOOT_Animation:END
64977.551385: OFF
----------------------------------------
以上是关于MMI开机时间偏长的主要内容,如果未能解决你的问题,请参考以下文章
MTK修改开机动画和墙纸要怎修改? 是在res.setting.c的populateDisplaychar中修改那个路径? 如下程序: