From 84803c50a6b4d0b8bf6c0a0b5a2f763a41398145 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Tue, 21 Jul 2020 15:38:23 +0800 Subject: [PATCH 1/2] [pgo] Sampling PGO does not require benchmark property Test: build with Sampling PGO Bug: 79161490 Change-Id: I70bb8dc2e4492d6a3713ca16fcb3f1216615f8ac --- cc/pgo.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/cc/pgo.go b/cc/pgo.go index 9298e7a74..42bc5d264 100644 --- a/cc/pgo.go +++ b/cc/pgo.go @@ -199,8 +199,8 @@ func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { return false } - // If at least one property exists, validate that all properties exist - if !profileKindPresent || !filePresent || !benchmarksPresent { + // profileKindPresent and filePresent are mandatory properties. + if !profileKindPresent || !filePresent { var missing []string if !profileKindPresent { missing = append(missing, "profile kind (either \"instrumentation\" or \"sampling\" property)") @@ -208,13 +208,15 @@ func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { if !filePresent { missing = append(missing, "profile_file property") } - if !benchmarksPresent { - missing = append(missing, "non-empty benchmarks property") - } missingProps := strings.Join(missing, ", ") ctx.ModuleErrorf("PGO specification is missing properties: " + missingProps) } + // Benchmark property is mandatory for instrumentation PGO. + if isInstrumentation && !benchmarksPresent { + ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property") + } + if isSampling && isInstrumentation { ctx.PropertyErrorf("pgo", "Exactly one of \"instrumentation\" and \"sampling\" properties must be set") } From a575ff38a8dae782c66794ae4585597bbdaf2dd2 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Wed, 22 Jul 2020 01:41:58 +0800 Subject: [PATCH 2/2] [pgo] Allow profile gather and use flags to coexist for sampling PGO Bug: 79161490 Test: presubmit Change-Id: I90df9c04dbe2a423c06e9a966fe9bcaed0a84a65 --- cc/pgo.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cc/pgo.go b/cc/pgo.go index 42bc5d264..674e1bbf1 100644 --- a/cc/pgo.go +++ b/cc/pgo.go @@ -290,15 +290,17 @@ func (pgo *pgo) flags(ctx ModuleContext, flags Flags) Flags { // Add flags to profile this module based on its profile_kind if props.ShouldProfileModule && props.isInstrumentation() { - return props.addInstrumentationProfileGatherFlags(ctx, flags) + props.addInstrumentationProfileGatherFlags(ctx, flags) + // Instrumentation PGO use and gather flags cannot coexist. + return flags } else if props.ShouldProfileModule && props.isSampling() { - return props.addSamplingProfileGatherFlags(ctx, flags) + props.addSamplingProfileGatherFlags(ctx, flags) } else if ctx.DeviceConfig().SamplingPGO() { - return props.addSamplingProfileGatherFlags(ctx, flags) + props.addSamplingProfileGatherFlags(ctx, flags) } if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") { - return props.addProfileUseFlags(ctx, flags) + props.addProfileUseFlags(ctx, flags) } return flags