Add timing of bp2build steps

Bug: b/239044089
Test: run build/bazel/ci/incremental_build --bazel-mode com.android.adbd and see the additional metrics in summary.csv
Change-Id: I2c3b9cead2ee43c700a9ad52e669a64aab1499ce
This commit is contained in:
Usta Shrestha
2022-10-04 12:13:25 -04:00
committed by Usta (Tsering) Shrestha
parent 02c1b12b1f
commit a117c58308

View File

@@ -480,8 +480,8 @@ func getExistingBazelRelatedFiles(topDir string) ([]string, error) {
// an alternate pipeline of mutators and singletons specifically for generating // an alternate pipeline of mutators and singletons specifically for generating
// Bazel BUILD files instead of Ninja files. // Bazel BUILD files instead of Ninja files.
func runBp2Build(configuration android.Config, extraNinjaDeps []string) { func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
var codegenMetrics bp2build.CodegenMetrics
eventHandler := metrics.EventHandler{} eventHandler := metrics.EventHandler{}
var metrics bp2build.CodegenMetrics
eventHandler.Do("bp2build", func() { eventHandler.Do("bp2build", func() {
// Register an alternate set of singletons and mutators for bazel // Register an alternate set of singletons and mutators for bazel
@@ -494,32 +494,38 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
bp2buildCtx.SetNameInterface(newNameResolver(configuration)) bp2buildCtx.SetNameInterface(newNameResolver(configuration))
bp2buildCtx.RegisterForBazelConversion() bp2buildCtx.RegisterForBazelConversion()
var ninjaDeps []string
ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
// The bp2build process is a purely functional process that only depends on // The bp2build process is a purely functional process that only depends on
// Android.bp files. It must not depend on the values of per-build product // Android.bp files. It must not depend on the values of per-build product
// configurations or variables, since those will generate different BUILD // configurations or variables, since those will generate different BUILD
// files based on how the user has configured their tree. // files based on how the user has configured their tree.
bp2buildCtx.SetModuleListFile(cmdlineArgs.ModuleListFile) bp2buildCtx.SetModuleListFile(cmdlineArgs.ModuleListFile)
modulePaths, err := bp2buildCtx.ListModulePaths(".") if modulePaths, err := bp2buildCtx.ListModulePaths("."); err != nil {
if err != nil {
panic(err) panic(err)
} else {
ninjaDeps = append(ninjaDeps, modulePaths...)
} }
extraNinjaDeps = append(extraNinjaDeps, modulePaths...)
// Run the loading and analysis pipeline to prepare the graph of regular // Run the loading and analysis pipeline to prepare the graph of regular
// Modules parsed from Android.bp files, and the BazelTargetModules mapped // Modules parsed from Android.bp files, and the BazelTargetModules mapped
// from the regular Modules. // from the regular Modules.
blueprintArgs := cmdlineArgs eventHandler.Do("bootstrap", func() {
ninjaDeps := bootstrap.RunBlueprint(blueprintArgs, bootstrap.StopBeforePrepareBuildActions, bp2buildCtx.Context, configuration) blueprintArgs := cmdlineArgs
ninjaDeps = append(ninjaDeps, extraNinjaDeps...) bootstrapDeps := bootstrap.RunBlueprint(blueprintArgs, bootstrap.StopBeforePrepareBuildActions, bp2buildCtx.Context, configuration)
ninjaDeps = append(ninjaDeps, bootstrapDeps...)
})
globListFiles := writeBuildGlobsNinjaFile(bp2buildCtx, configuration.SoongOutDir(), configuration) globListFiles := writeBuildGlobsNinjaFile(bp2buildCtx, configuration.SoongOutDir(), configuration)
ninjaDeps = append(ninjaDeps, globListFiles...) ninjaDeps = append(ninjaDeps, globListFiles...)
// Run the code-generation phase to convert BazelTargetModules to BUILD files // Run the code-generation phase to convert BazelTargetModules to BUILD files
// and print conversion metrics to the user. // and print conversion codegenMetrics to the user.
codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build) codegenContext := bp2build.NewCodegenContext(configuration, *bp2buildCtx, bp2build.Bp2Build)
metrics = bp2build.Codegen(codegenContext) eventHandler.Do("codegen", func() {
codegenMetrics = bp2build.Codegen(codegenContext)
})
generatedRoot := shared.JoinPath(configuration.SoongOutDir(), "bp2build") generatedRoot := shared.JoinPath(configuration.SoongOutDir(), "bp2build")
workspaceRoot := shared.JoinPath(configuration.SoongOutDir(), "workspace") workspaceRoot := shared.JoinPath(configuration.SoongOutDir(), "workspace")
@@ -547,11 +553,17 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
excludes = append(excludes, getTemporaryExcludes()...) excludes = append(excludes, getTemporaryExcludes()...)
symlinkForestDeps := bp2build.PlantSymlinkForest( // PlantSymlinkForest() returns all the directories that were readdir()'ed.
configuration, topDir, workspaceRoot, generatedRoot, ".", excludes) // Such a directory SHOULD be added to `ninjaDeps` so that a child directory
// or file created/deleted under it would trigger an update of the symlink
// forest.
eventHandler.Do("symlink_forest", func() {
symlinkForestDeps := bp2build.PlantSymlinkForest(
configuration, topDir, workspaceRoot, generatedRoot, ".", excludes)
ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
})
ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...) ninjaDeps = append(ninjaDeps, codegenContext.AdditionalNinjaDeps()...)
ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
writeDepFile(bp2buildMarker, eventHandler, ninjaDeps) writeDepFile(bp2buildMarker, eventHandler, ninjaDeps)
@@ -563,9 +575,9 @@ func runBp2Build(configuration android.Config, extraNinjaDeps []string) {
// for queryview, since that's a total repo-wide conversion and there's a // for queryview, since that's a total repo-wide conversion and there's a
// 1:1 mapping for each module. // 1:1 mapping for each module.
if configuration.IsEnvTrue("BP2BUILD_VERBOSE") { if configuration.IsEnvTrue("BP2BUILD_VERBOSE") {
metrics.Print() codegenMetrics.Print()
} }
writeBp2BuildMetrics(&metrics, configuration, eventHandler) writeBp2BuildMetrics(&codegenMetrics, configuration, eventHandler)
} }
// Write Bp2Build metrics into $LOG_DIR // Write Bp2Build metrics into $LOG_DIR