From 49540800f038de8b93411aa20b95215cb674ee42 Mon Sep 17 00:00:00 2001 From: Pirama Arumuga Nainar Date: Mon, 29 Jan 2018 23:11:42 -0800 Subject: [PATCH] Search for PGO profiles in PGO_ADDITIONAL_PROFILE_DIRS This variable can be set in BoardConfig.mk to specify a list of additional paths that contain PGO profiles. These directories are searched after the predefined paths in soong/cc/pgo.go while finding PGO profiles. Test: Set this variable in a BoardConfig and verify that such profiles are found and that these paths are searched after the predefined paths in soong/cc/pgo.go. Change-Id: I0bb9523de614d0f23aba8d51c887d8fc8f41c993 --- android/config.go | 4 ++++ android/variable.go | 2 ++ cc/pgo.go | 13 ++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/android/config.go b/android/config.go index b5ec97588..1e5dd521f 100644 --- a/android/config.go +++ b/android/config.go @@ -710,6 +710,10 @@ func (c *deviceConfig) CoverageEnabledForPath(path string) bool { return coverage } +func (c *deviceConfig) PgoAdditionalProfileDirs() []string { + return c.config.ProductVariables.PgoAdditionalProfileDirs +} + func (c *config) IntegerOverflowDisabledForPath(path string) bool { if c.ProductVariables.IntegerOverflowExcludePaths == nil { return false diff --git a/android/variable.go b/android/variable.go index 2c2a0cfe9..328074a3d 100644 --- a/android/variable.go +++ b/android/variable.go @@ -205,6 +205,8 @@ type productVariables struct { ExtraVndkVersions []string `json:",omitempty"` NamespacesToExport []string `json:",omitempty"` + + PgoAdditionalProfileDirs []string `json:",omitempty"` } func boolPtr(v bool) *bool { diff --git a/cc/pgo.go b/cc/pgo.go index 3ce67be7a..1e7033979 100644 --- a/cc/pgo.go +++ b/cc/pgo.go @@ -27,17 +27,24 @@ var ( // some functions profileUseOtherFlags = []string{"-Wno-backend-plugin"} - pgoProfileProjects = []string{ + globalPgoProfileProjects = []string{ "toolchain/pgo-profiles", "vendor/google_data/pgo-profiles", } ) +const pgoProfileProjectsConfigKey = "PgoProfileProjects" const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp" const profileSamplingFlag = "-gline-tables-only" const profileUseInstrumentFormat = "-fprofile-use=%s" const profileUseSamplingFormat = "-fprofile-sample-use=%s" +func getPgoProfileProjects(config android.DeviceConfig) []string { + return config.OnceStringSlice(pgoProfileProjectsConfigKey, func() []string { + return append(globalPgoProfileProjects, config.PgoAdditionalProfileDirs()...) + }) +} + func recordMissingProfileFile(ctx ModuleContext, missing string) { getNamedMapForConfig(ctx.Config(), modulesMissingProfileFile).Store(missing, true) } @@ -92,8 +99,8 @@ func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags } func (props *PgoProperties) getPgoProfileFile(ctx ModuleContext) android.OptionalPath { - // Test if the profile_file is present in any of the pgoProfileProjects - for _, profileProject := range pgoProfileProjects { + // Test if the profile_file is present in any of the PGO profile projects + for _, profileProject := range getPgoProfileProjects(ctx.DeviceConfig()) { path := android.ExistentPathForSource(ctx, "", profileProject, *props.Pgo.Profile_file) if path.Valid() { return path