MMI开机时间偏长

 

Mini版本开机时间长

Mini版本开机时间长

1. Problem Description:

2. Analysis:

3. Solution:

4. Summary:

1. Problem Description:

Mini版本主要是用来测试手机硬件的一款软件,

2. Analysis:

开机较慢的原因是在开机过程中会的data分区进行加密操作,而这个操作对应内部测试并没有什么用,因此可以去掉。然后是在开机过程中会安装APK,这会占用很多的开机时间,安装的这些APK中有许多并不是必备的,所以去掉那些无用的APK可以缩短开机时间。针对这个,可以设定在编译阶段就不编译这些APK。然后就是开机过程中会有些预优化,其优化的目的是节约手机内存即“用时间来换取空间”的策略。所以对降低开机时间主要在如下3个方面进行操作:

  • 关闭data 加密
  • 通过mmitest_skip_modules.mk 过滤多余APK
  • 去掉预优化

3. Solution:

  1. 关闭data分区
    在文件vendor/mediatek/proprietary/hardware/fstab/mt6755/Android.mk中进行如下修改:
  1. ifeq ($(strip $(MTK_ENCRYPTION_DEFAULT_OFF)),yes)
  2. __CFLAGS +=-D__MTK_FDE_NO_FORCE
  3. else ifeq ($(strip $(CUSTOM_CONFIG_MAX_DRAM_SIZE)),0x20000000)
  4. __CFLAGS +=-D__MTK_FDE_NO_FORCE
  5. else ifeq ($(strip $(TARGET_BUILD_MMITEST)),true)
  6. __CFLAGS +=-D__MTK_FDE_NO_FORCE
  7. endif
  8. ifeq ($(strip $(MTK_TEE_SUPPORT)),yes)
  9. ifeq ($(strip $(MTK_ENCRYPTION_TYPE_FILE)),yes)
  10. __CFLAGS +=-D__MTK_FDE_TYPE_FILE
  11. endif
  12. endif

条件语句ifeq ($(strip $(TARGET_BUILD_MMITEST)),true)会进行判断,如果是编译的MINI软件,会添加__MTK_FDE_NO_FORCE宏定义。在文件fstab.in中会进行判断:

  1. #ifdef __MTK_FDE_NO_FORCE
  2. /*打开此项, 即默认不强制加密*/
  3. #define FLAG_FDE_AUTO encryptable
  4. #else
  5. #define FLAG_FDE_AUTO forceencrypt
  1. 通过mmitest_skip_modules.mk 过滤多余APK
    在文件build/core/main.mk中如如下判断:
  1. ifeq ($(TARGET_BUILD_MMITEST),true)
  2. $(warning skip_before: $(product_MODULES))
  3. product_MODULES := $(filter-out $(MMITEST_SKIP_MODULES),$(product_MODULES))
  4. $(warning skip_after: $(product_MODULES))

即如果编译的是TARGET_BUILD_MMITEST版本,会过虑掉mmitest_skip_modules.mk中的模块,所以需要将不需要的APK加入到文件mmitest_skip_modules.mk中。

  1. 去掉预优化
    预优化(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/system@app@Music@Music.apk@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都不做优化)。

对文件build/core/dex_preopt.mk中,具体修改如下:

  1. ifeq ($(TARGET_BUILD_VARIANT),eng)
  2. ifeq ($(TARGET_BUILD_MMITEST),true)
  3. WITH_DEXPREOPT :=true
  4. WITH_DEXPREOPT_PIC :=true
  5. else
  6. WITH_DEXPREOPT :=false
  7. DONT_DEXPREOPT_PREBUILTS :=false
  8. endif
  9. endif
  10. ifeq (eng,$(TARGET_BUILD_VARIANT))
  11. ifeq ($(TARGET_BUILD_MMITEST),true)
  12. WITH_DEXPREOPT_BOOT_IMG_ONLY ?=false
  13. else
  14. WITH_DEXPREOPT_BOOT_IMG_ONLY ?=true
  15. endif
  16. ifneq (false,$(WITH_DEXPREOPT_DEBUG_INFO))
  17. PRODUCT_DEX_PREOPT_BOOT_FLAGS +=--generate-mini-debug-info
  18. endif
  19. endif

4. Summary:

针对这个问题,需要知道主要的耗时操作在什么地方,然后进行分析后来优化操作。可以通过命令adb shell cat /proc/bootprof来查看开机时的时间消耗情况。同时通过命令adb shell&&pm list package -f查看系统安装的APK情况,然后对无用的APK进行优化。需要注意的是有的APK相关的.so文件是系统所必须的,如果未将这部分APK编译进行系统,会导致系统无法正常开机。
可以将开机过程划分成如下几个阶段来进行分析:

 第一次开机时间   
 开始时间开始标志结束时间结束标志
preloader    
lk    
kernel init0 7115.804323Kernel_init_done
mount pattition9506.666791INIT:Mount_START13455.14742INIT:Mount_END
android boot50378.09604Zygote:Preload Start62539.99315Zygote:Preload End
package scan77678.46488Android:PackageManagerService_Start136793.9336Android:PMS_READY
app initiationlization136793.9336Android:PMS_READY189794.6175BOOT_Animation:END

下面是优化后开机时间的实际情况:
注:

  1. user@user-Lenovo-Product:/local$ adb shell cat /proc/bootprof
  2. ----------------------------------------
  3. 0 BOOT PROF (unit:msec)
  4. ----------------------------------------
  5. 3220: preloader
  6. 3667: lk
  7. ----------------------------------------
  8. 371.855769: ON
  9. 865.905540:1-swapper/0: initcall: of_init 227.898155ms
  10. 893.704540:1-swapper/0: initcall: ramoops_init 17.496000ms
  11. 952.617924:1-swapper/0: initcall: init_mtk_governor 23.135538ms
  12. 1021.233232:1-swapper/0: initcall: mt_power_management_init 25.048539ms
  13. 1301.584079:1-swapper/0: initcall: arm64_device_init 237.500924ms
  14. 1460.799464:1-swapper/0: initcall: param_sysfs_init 150.824308ms
  15. 1492.303310:1-swapper/0: initcall: pm_sysrq_init 28.820616ms
  16. 1554.894772:1-swapper/0: initcall: MTK_M4U_Init 25.420154ms
  17. 1600.313234:1-swapper/0: probe: probe=platform_drv_probe drv=mtk_cmdq(ffffffc00160fd78)35.709539ms
  18. 1605.032926:1-swapper/0: initcall: cmdq_init 41.354385ms
  19. 1730.910926:1-swapper/0: initcall: cfg80211_init 21.485846ms
  20. 2122.880696:1-swapper/0: initcall: event_trace_init 371.556078ms
  21. 2261.964774:1-swapper/0: probe: probe=platform_drv_probe drv=mt-pmic(ffffffc001604300)95.811769ms
  22. 2266.137928:1-swapper/0: initcall: pmic_mt_init 101.656769ms
  23. 2324.955082:1-swapper/0: initcall: inet_init 33.181154ms
  24. 2507.386236:1-swapper/0: initcall: populate_rootfs 177.119692ms
  25. 2735.783313:1-swapper/0: initcall: slab_sysfs_init 145.808231ms
  26. 2922.011391:1-swapper/0: initcall: pty_init 17.699615ms
  27. 2960.162160:1-swapper/0: initcall: loop_init 29.996923ms
  28. 3028.701775:1-swapper/0: initcall: mt_gpufreq_init 17.778692ms
  29. 3072.091545:1-swapper/0: initcall: hps_init 26.006461ms
  30. 3098.926776:1-swapper/0: initcall: mtk_uart_init 15.949923ms
  31. 3283.340622:1-swapper/0: probe: probe=i2c_device_probe drv=pn544(ffffffc0015f64a8)86.596615ms
  32. 3285.073776:1-swapper/0: probe: probe=platform_drv_probe drv=mt-i2c(ffffffc0016000e8)90.320847ms
  33. 3289.343622:1-swapper/0: initcall: mt_i2c_init 109.559615ms
  34. 3336.911699:1-swapper/0: probe: probe=platform_drv_probe drv=Accdet_Driver(ffffffc001601f88)24.650847ms
  35. 3342.731930:1-swapper/0: initcall: accdet_mod_init 34.558538ms
  36. 3362.740776:1-swapper/0: initcall: init 18.654000ms
  37. 3443.727469:1-swapper/0: probe: probe=platform_drv_probe drv=musb-hdrc(ffffffc00160bd38)20.658847ms
  38. 3445.988392:1-swapper/0: probe: probe=platform_drv_probe drv=musb-mtu3d(ffffffc00160c008)23.848616ms
  39. 3450.176623:1-swapper/0: initcall: mtu3d_driver_init 29.606231ms
  40. 3710.967392:1-swapper/0: probe: probe=mtkfb_probe drv=mtkfb(ffffffc001612008)223.363924ms
  41. 3714.922854:1-swapper/0: initcall: mtkfb_init 231.631924ms
  42. 3751.890316:1-swapper/0: probe: probe=platform_drv_probe drv=mali(ffffffc001617578)21.980308ms
  43. 3755.982085:1-swapper/0: initcall: kbase_platform_driver_init 27.714923ms
  44. 3863.481316:1-swapper/0: probe: probe=i2c_device_probe drv=kd_camera_hw(ffffffc00161a448)57.799539ms
  45. 3865.574854:1-swapper/0: probe: probe=platform_drv_probe drv=image_sensor(ffffffc00161a1e0)85.040846ms
  46. 3873.808316:1-swapper/0: initcall: CAMERA_HW_i2C_init 99.528308ms
  47. 3962.954393:1-swapper/0: probe: probe=platform_drv_probe drv=kd_camera_flashlight(ffffffc00161e258)59.763000ms
  48. 3969.943778:1-swapper/0: initcall: flashlight_init 75.757616ms
  49. 4090.410316:1-swapper/0: probe: probe=platform_drv_probe drv=cldma_modem(ffffffc00162d590)108.923078ms
  50. 4095.188932:1-swapper/0: initcall: modem_cd_init 114.386231ms
  51. 4153.136394:1-swapper/0: initcall: BTIF_init 39.421231ms
  52. 4286.060009:1-swapper/0: initcall: mtk_cooler_dtm_init 24.058692ms
  53. 4339.072932:1-swapper/0: initcall: emi_mpu_mod_init 23.010693ms
  54. 4364.575009:1-swapper/0: initcall: init 18.190692ms
  55. 4440.468856:1-swapper/0: probe: probe=platform_drv_probe drv=HardwareInfo(ffffffc001639f08)53.160539ms
  56. 4443.734163:1-swapper/0: initcall:HardwareInfo_mod_init58.462154ms
  57. 4575.167471:1-swapper/0: probe: probe=platform_drv_probe drv=mtk-kpd(ffffffc00164df40)15.611769ms
  58. 4580.932318:1-swapper/0: initcall: kpd_mod_init 22.393846ms
  59. 4690.719933:1-swapper/0: probe: probe=platform_drv_probe drv=battery_meter(ffffffc001661020)83.773770ms
  60. 4692.538703:1-swapper/0: probe: pdev=battery_meter(ffffffc001660cd0)86.807769ms
  61. 4694.067472:1-swapper/0: probe: probe=platform_drv_probe drv=battery_meter_dts(ffffffc0016610d0)89.507462ms
  62. 4697.669010:1-swapper/0: initcall: battery_meter_init 96.310308ms
  63. 4747.176241:1-swapper/0: initcall: mt67xx_v2_cpuidle_init 25.403769ms
  64. 4776.516934:1-swapper/0: initcall: mt_msdc_init 23.781692ms
  65. 5067.848319:1-swapper/0: probe: probe=platform_drv_probe drv=soc-audio(ffffffc0016774a0)121.699693ms
  66. 5068.152934:1-swapper/0: initcall: mt_soc_snd_init 123.002000ms
  67. 5120.639396:1-swapper/0: initcall: inet6_init 32.686385ms
  68. 5340.091243:1-swapper/0: initcall: enable_ftrace 194.529078ms
  69. 5373.725781:1-swapper/0: initcall: add_shrinker_debug 30.885000ms
  70. 5485.367704:1-swapper/0: initcall: mt_dcm_init 88.614615ms
  71. 5532.398243:1-swapper/0: probe: probe=platform_drv_probe drv=mt-cpufreq(ffffffc0015f0198)35.841154ms
  72. 5535.746935:1-swapper/0: initcall: _mt_cpufreq_pdrv_init 43.911154ms
  73. 5543.812781:6-kworker/u16:0: probe: probe=mmc_bus_probe drv=mmcblk(ffffffc001668c40)72.474692ms
  74. 5670.824782:1-swapper/0: probe: probe=i2c_device_probe drv=stk3x1x(ffffffc0015fd9c8)89.990308ms
  75. 5682.310166:1-swapper/0: initcall: alsps_init 107.247231ms
  76. 5707.768705:1-swapper/0: probe: probe=i2c_device_probe drv=BMA2XX(ffffffc0015fe440)21.252154ms
  77. 5717.638936:1-swapper/0: initcall: acc_init 32.605384ms
  78. 5784.254397:1-swapper/0: probe: probe=i2c_device_probe drv=bmg250_gyro(ffffffc0015ff168)64.123231ms
  79. 5802.952705:1-swapper/0: initcall: gyro_init 84.019539ms
  80. 5820.408705:1-swapper/0: initcall: mag_init 16.166846ms
  81. 5841.251475:1-swapper/0: initcall: step_c_init 19.552769ms
  82. 5873.744628:1-swapper/0: initcall: devapc_init 15.065000ms
  83. 5953.311398:1-swapper/0: initcall: init 62.161462ms
  84. 6636.759323:1-swapper/0: probe: probe=spi_drv_probe drv=fp_spi(ffffffc00165b6a0)390.230540ms
  85. 6850.068400:1-swapper/0: probe: probe=platform_drv_probe drv=fp_drv(ffffffc00164daf0)892.541617ms
  86. 6853.522477:1-swapper/0: initcall: fp_drv_init 898.986541ms
  87. 6890.832323:1-swapper/0: initcall: battery_init 27.719308ms
  88. 6939.269631:147-kworker/u16:2: probe: probe=platform_drv_probe drv=battery(ffffffc001663978)42.569539ms
  89. 6939.860093:147-kworker/u16:2: probe: pdev=battery(ffffffc0016635a8)45.113385ms
  90. 6939.923785:147-kworker/u16:2: probe: probe=platform_drv_probe drv=battery-dts(ffffffc001663160)46.362692ms
  91. 7076.133477:1-swapper/0: initcall: clk_debug_init 169.705539ms
  92. 7110.142478:1-swapper/0: initcall: regulator_init_complete 26.655154ms
  93. 7124.238862:1-swapper/0:Kernel_init_done
  94. 7346.506940:6-kworker/u16:0: probe: probe=i2c_device_probe drv=fts(ffffffc00164f200)461.019770ms
  95. 7380.387632:6-kworker/u16:0: probe: probe=platform_drv_probe drv=mtk-tpd(ffffffc00164e1b0)505.097539ms
  96. 8436.728096:1-init : INIT:early-init
  97. 9527.990176:1-init : INIT:late-init
  98. 9529.631329:1-init : INIT:Mount_START
  99. 13540.467877:1-init : INIT:Mount_END
  100. 13564.849262:1-init : setup mobicore perms ++(on fs)
  101. 13572.114570:1-init : setup mobicore perms --(on fs)
  102. 15212.874112:1-init : INIT:post-fs
  103. 16440.699577:1-init : INIT:post-fs-data
  104. 16635.690577:1-init : post-fs-data: on modem start
  105. 16951.829809:1-init : INIT:boot
  106. 17245.023579:1-init : create /data/misc/mcRegistry ++(unencrypted)
  107. 17246.505271:1-init : create /data/misc/mcRegistry --(unencrypted)
  108. 17247.555963:1-init : create /data/misc/mcRegistry ++(unencrypted)
  109. 17249.106502:1-init : create /data/misc/mcRegistry --(unencrypted)
  110. 17284.131502:328-wmt_loader : probe: probe=platform_drv_probe drv=fm(ffffffc001633d10)47.623538ms
  111. 20117.511509:340-surfaceflinger : BOOT_Animation:START
  112. 22752.109976:381-main :Zygote:PreloadStart
  113. 22901.186131:380-main :Zygote:PreloadStart
  114. 25185.028905:380-main :Zygote:Preload4161 classes in2124ms
  115. 25203.203751:381-main :Zygote:Preload4161 classes in2299ms
  116. 26061.491523:380-main :Zygote:Preload114 obtain resources in405ms
  117. 26065.363292:381-main :Zygote:Preload114 obtain resources in415ms
  118. 26087.808215:380-main :Zygote:Preload41 resources in24ms
  119. 26089.247907:381-main :Zygote:Preload41 resources in22ms
  120. 26370.564985:380-main :Zygote:PreloadEnd
  121. 26500.120062:381-main :Zygote:PreloadEnd
  122. 26715.354986:857-system_server :Android:SysServerInit_START
  123. 28576.801452:857-system_server :Android:PackageManagerService_Start
  124. 28886.731453:857-system_server :Android:PMS_scan_START
  125. 29073.939761:857-system_server :Android:PMS_scan_data:/vendor/overlay
  126. 30086.105455:857-system_server :Android:PMS_scan_data:/system/framework
  127. 30408.115379:857-system_server :Android:PMS_scan_data:/vendor/framework
  128. 30513.919072:857-system_server :Android:PMS_scan_data:/system/custpack/app/unremoveable/priv-app
  129. 30933.341996:857-system_server :Android:PMS_scan_data:/system/custpack/app/unremoveable/withlibs
  130. 31652.178228:857-system_server :Android:PMS_scan_data:/system/priv-app
  131. 34101.119465:857-system_server :Android:PMS_scan_data:/system/app
  132. 36764.976164:857-system_server :Android:PMS_scan_data:/vendor/priv-app
  133. 36875.507164:857-system_server :Android:PMS_scan_data:/system/vendor/app
  134. 37153.869472:857-system_server :Android:PMS_scan_data:/vendor/plugin
  135. 37226.375626:857-system_server :Android:PMS_scan_END
  136. 49955.817887:857-system_server :Android:PMS_READY
  137. 56871.808288:857-system_server : AMS:systemReady
  138. 56897.408827:857-system_server : AMS:AMS_READY
  139. 57065.576981:935-ActivityManager: AP_Init:[broadcast]:[com.android.settings]:[com.android.settings/.wifi.WifiPreconfigAPReceiver]:pid:1460
  140. 57140.895520:857-system_server : AP_Init:[service]:[com.android.inputmethod.latin]:[com.android.inputmethod.latin/.LatinIME]:pid:1476
  141. 57350.931367:935-ActivityManager: AP_Init:[broadcast]:[android.process.media]:[com.android.providers.media/.MtpReceiver]:pid:1494
  142. 57426.956059:857-system_server : AP_Init:[service]:[com.android.systemui]:[com.android.systemui/.SystemUIService]:pid:1508:(PersistAP)
  143. 58150.542907:857-system_server :SystemServer:NetworkManagementService systemReady
  144. 58427.997369:857-system_server :SystemServer:NetworkStatsService systemReady
  145. 59029.889063:857-system_server :SystemServer:NetworkPolicyManagerService systemReady
  146. 59106.422755:857-system_server :SystemServer:ConnectivityService systemReady
  147. 59417.024295:857-system_server :SystemServer:PhaseThirdPartyAppsCanStart
  148. 59480.887141:857-system_server : AP_Init:[added application]:[com.android.phone]:[com.android.phone]:pid:1625:(PersistAP)
  149. 59534.872987:857-system_server : AP_Init:[added application]:[com.mediatek.ims]:[com.mediatek.ims]:pid:1639:(PersistAP)
  150. 59588.214526:857-system_server : AP_Init:[added application]:[com.mediatek.wfo.impl]:[com.mediatek.wfo.impl]:pid:1653:(PersistAP)
  151. 59645.845064:857-system_server : AP_Init:[added application]:[se.dirac.acs]:[se.dirac.acs]:pid:1667:(PersistAP)
  152. 59657.955141:857-system_server : AMS:ENABLE_SCREEN
  153. 59714.057064:857-system_server :Android:SysServerInit_END
  154. 64974.737462:496-Binder:340_1 : BOOT_Animation:END
  155. 64977.551385: OFF
  156. ----------------------------------------
    原文作者:PackageManagerService
    原文地址: http://www.cnblogs.com/sayhellowen/p/c52acda1192c871bd5d6cce1a9c6669c.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞