Merge changes Ib23bad52,I1923ebde

* changes:
  Do not use profiles if ANDROID_PGO_NO_PROFILE_USE is set
  Refactor methods to be on PgoProperties struct
This commit is contained in:
Treehugger Robot
2017-10-11 00:08:29 +00:00
committed by Gerrit Code Review

View File

@@ -63,37 +63,55 @@ func (pgo *pgo) props() []interface{} {
return []interface{}{&pgo.Properties} return []interface{}{&pgo.Properties}
} }
func (pgo *pgo) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags { func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
if pgo.Properties.isInstrumentation() { if props.isInstrumentation() {
flags.CFlags = append(flags.CFlags, profileInstrumentFlag) flags.CFlags = append(flags.CFlags, profileInstrumentFlag)
// The profile runtime is added below in deps(). Add the below // The profile runtime is added below in deps(). Add the below
// flag, which is the only other link-time action performed by // flag, which is the only other link-time action performed by
// the Clang driver during link. // the Clang driver during link.
flags.LdFlags = append(flags.LdFlags, "-u__llvm_profile_runtime") flags.LdFlags = append(flags.LdFlags, "-u__llvm_profile_runtime")
} }
if pgo.Properties.isSampling() { if props.isSampling() {
flags.CFlags = append(flags.CFlags, profileSamplingFlag) flags.CFlags = append(flags.CFlags, profileSamplingFlag)
flags.LdFlags = append(flags.LdFlags, profileSamplingFlag) flags.LdFlags = append(flags.LdFlags, profileSamplingFlag)
} }
return flags return flags
} }
func (pgo *pgo) profileUseFlag(ctx ModuleContext, file string) string { func (props *PgoProperties) profileUseFlag(ctx ModuleContext, file string) string {
if pgo.Properties.isInstrumentation() { if props.isInstrumentation() {
return fmt.Sprintf(profileUseInstrumentFormat, file) return fmt.Sprintf(profileUseInstrumentFormat, file)
} }
if pgo.Properties.isSampling() { if props.isSampling() {
return fmt.Sprintf(profileUseSamplingFormat, file) return fmt.Sprintf(profileUseSamplingFormat, file)
} }
return "" return ""
} }
func (pgo *pgo) profileUseFlags(ctx ModuleContext, file string) []string { func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []string {
flags := []string{pgo.profileUseFlag(ctx, file)} flags := []string{props.profileUseFlag(ctx, file)}
flags = append(flags, profileUseOtherFlags...) flags = append(flags, profileUseOtherFlags...)
return flags return flags
} }
func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags {
// If the PGO profiles project is found, and this module has PGO
// enabled, add flags to use the profile
if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() {
profileFile := android.PathForSource(ctx, profilesDir.String(), *props.Pgo.Profile_file)
profileUseFlags := props.profileUseFlags(ctx, profileFile.String())
flags.CFlags = append(flags.CFlags, profileUseFlags...)
flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
// if profileFile gets updated
flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile)
}
return flags
}
func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool {
isInstrumentation := props.isInstrumentation() isInstrumentation := props.isInstrumentation()
isSampling := props.isSampling() isSampling := props.isSampling()
@@ -188,22 +206,11 @@ func (pgo *pgo) flags(ctx ModuleContext, flags Flags) Flags {
// Add flags to profile this module based on its profile_kind // Add flags to profile this module based on its profile_kind
if props.ShouldProfileModule { if props.ShouldProfileModule {
return pgo.addProfileGatherFlags(ctx, flags) return props.addProfileGatherFlags(ctx, flags)
} }
// If the PGO profiles project is found, and this module has PGO if !ctx.AConfig().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") {
// enabled, add flags to use the profile return props.addProfileUseFlags(ctx, flags)
if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() {
profileFile := android.PathForSource(ctx, profilesDir.String(), *(props.Pgo.Profile_file))
profileUseFlags := pgo.profileUseFlags(ctx, profileFile.String())
flags.CFlags = append(flags.CFlags, profileUseFlags...)
flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
// if profileFile gets updated
flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile)
flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile)
} }
return flags return flags