如何使抓取的各类profile生效
1. system_server系统的profile
SystemServer.art-profile
1、增量修改源码中的services/art-profile
可以源码中的art-profile做比较,看一下哪些是新增的
frameworks/base/services/art-profile
如果是这样的话,建议“Android S抓取各类profile的方法”中的第三章的第一点,–apk=services.jar 只加入services的
2、对PRODUCT_SYSTEM_SERVER_JARS的其它jar包做profile的优化(普通Android版本默认都是speed,如果加上profile,会多一个appimage的优化
;如果是Android go版本则直接是speed-profile优化)
可以在
build/soong/java/dexpreopt.go
build/soong/dexpreopt/dexpreopt.go
这2个文件都可以修改,参考源码(services.jar会跑)的逻辑自行增加isSystemServerJar其它jar的优化
//build/soong/java/dexpreopt.go
isSystemServerJar := global.SystemServerJars.ContainsJar(ctx.ModuleName())
//...
if String(d.dexpreoptProperties.Dex_preopt.Profile) != "" {
profileClassListing = android.OptionalPathForPath(
android.PathForModuleSrc(ctx, String(d.dexpreoptProperties.Dex_preopt.Profile)))
profileBootListing = android.ExistentPathForSource(ctx,
ctx.ModuleDir(), String(d.dexpreoptProperties.Dex_preopt.Profile)+"-boot")
profileIsTextListing = true
}
或者直接在下面增加profile修改(这样就无需转换了,直接用profile),或者GenerateDexpreoptRule直接写入profileClassListing(比上面的方法麻烦,建议在java/dexpreopt.go修改)
build/soong/dexpreopt/dexpreopt.go
if global.SystemServerJars.ContainsJar(module.Name) {
// Jars of system server, use the product option if it is set, speed otherwise.
if global.SystemServerCompilerFilter != "" {
compilerFilter = global.SystemServerCompilerFilter
} else {
compilerFilter = "speed"
}
}
if profile != nil {
cmd.FlagWithInput("--profile-file=", profile)
}
2. boot image上层所有进程的profile
boot-image-profile.txt
找一个system编译的mk将这个加进去PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION += frameworks/base/config/yunhen-boot-image-profile.txt
具体原因如下
//build/make/core/dex_preopt_config.mk
$(call add_json_list, BootImageProfiles, $(PRODUCT_DEX_PREOPT_BOOT_IMAGE_PROFILE_LOCATION))
//build/soong/java/dexpreopt_bootjars.go
func bootImageProfileRule(ctx android.ModuleContext, image *bootImageConfig) android.WritablePath {
globalSoong := dexpreopt.GetGlobalSoongConfig(ctx)
global := dexpreopt.GetGlobalConfig(ctx)
if global.DisableGenerateProfile {
return nil
}
defaultProfile := "frameworks/base/config/boot-image-profile.txt"
rule := android.NewRuleBuilder(pctx, ctx)
var bootImageProfile android.Path
//此处是全部合成一个
if len(global.BootImageProfiles) > 1 {
combinedBootImageProfile := image.dir.Join(ctx, "boot-image-profile.txt")
rule.Command().Text("cat").Inputs(global.BootImageProfiles).Text(">").Output(combinedBootImageProfile)
bootImageProfile = combinedBootImageProfile
preloaded-classes
这个是预加载的类,对比一下原生的,看一下哪些是项目自己加入的类(原生的可以不用加,Google已经加了很多,自己看吧),加进去就行了,注意这个会导致开机时间增加,记得打印时间对比一下,还有zygote进程启动时会载入,看一下内存用量是否增加
3. 系统预置应用的profile
1、Android.mk
编译的模块(旧版本的android大部分跑的这里)
找到配置类似LOCAL_DEX_PREOPT/my_process_profile
的地方,
build/make/core/dex_preopt_odex_install.mk
ifeq (false,$(LOCAL_DEX_PREOPT))
LOCAL_DEX_PREOPT :=
endif
# Disable preopt for DISABLE_PREOPT
ifeq (true,$(DISABLE_PREOPT))
LOCAL_DEX_PREOPT :=
endif
# Disable preopt if not WITH_DEXPREOPT
ifneq (true,$(WITH_DEXPREOPT))
LOCAL_DEX_PREOPT :=
endif
ifndef LOCAL_DEX_PREOPT_GENERATE_PROFILE
# If LOCAL_DEX_PREOPT_GENERATE_PROFILE is not defined, default it based on the existence of the
# profile class listing. TODO: Use product specific directory here.
my_classes_directory := $(PRODUCT_DEX_PREOPT_PROFILE_DIR)
#这里是配置profile文件的方法
LOCAL_DEX_PREOPT_PROFILE := $(my_classes_directory)/$(LOCAL_MODULE).prof
ifneq (,$(wildcard $(LOCAL_DEX_PREOPT_PROFILE)))
my_process_profile := true
my_profile_is_text_listing :=
endif
else
#这里是配置转换后的art-profile文件的方法
my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE)
my_profile_is_text_listing := true
LOCAL_DEX_PREOPT_PROFILE := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
endif
参考代码***_LIST
是你需要做什么类型就什么类型(speed和speed-profile都是可以的,按照各自的需求做就行了)
ifneq (,$(filter $(LOCAL_MODULE),$(***_LIST)))
#从上面仿照过来
LOCAL_DEX_PREOPT_GENERATE_PROFILE := true
LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING := yunhen/$(LOCAL_MODULE).art-profile
my_process_profile := $(LOCAL_DEX_PREOPT_GENERATE_PROFILE)
my_profile_is_text_listing := true
LOCAL_DEX_PREOPT_PROFILE := $(LOCAL_DEX_PREOPT_PROFILE_CLASS_LISTING)
#设置默认compiler-filter为speed-profile
LOCAL_DEX_PREOPT_FLAGS := --compiler-filter=speed-profile
#或者speed模式,自行选择
#LOCAL_DEX_PREOPT_FLAGS := --compiler-filter=speed
# 强制生成appimage '.art'文件,可以不设置的,设置之后就算没有profile,也会有'.art'文件,只是大小很小,也就是优化还是需要profile文件
LOCAL_DEX_PREOPT_APP_IMAGE := true
endif
2、Android.bp
编译的应用(和之前说的services.jar里面的方法一样的,global.**List请参考global.SpeedApps
的实现)
//build/soong/java/dexpreopt.go
is**List := global.**List.ContainsJar(ctx.ModuleName())
//...
if (is**List) {
//profileClassListing = "yunhen/" + ctx.ModuleName() + ".art-profile";
profileClassListing = android.ExistentPathForSource(ctx,
appProfileDir, ctx.ModuleName() + ".art-profile")
profileIsTextListing = true
}