metrics: count symlink/mkdir in symlink forest

Bug: 260029212
Test: inspect out/bp2build_metrics.pb
Change-Id: Ia84c095a8d7b129cca629256b6c626c726cbfab1
This commit is contained in:
Usta Shrestha
2022-11-08 14:12:36 -05:00
parent e0598a1cbd
commit da15c61add
5 changed files with 130 additions and 73 deletions

View File

@@ -189,7 +189,7 @@ func runApiBp2build(ctx *android.Context, extraNinjaDeps []string) string {
workspace := shared.JoinPath(ctx.Config().SoongOutDir(), "api_bp2build")
// Create the symlink forest
symlinkDeps := bp2build.PlantSymlinkForest(
symlinkDeps, _, _ := bp2build.PlantSymlinkForest(
ctx.Config().IsEnvTrue("BP2BUILD_VERBOSE"),
topDir,
workspace,
@@ -459,8 +459,10 @@ func bazelArtifacts() []string {
// symlink tree creation binary. Then the latter would not need to depend on
// the very heavy-weight machinery of soong_build .
func runSymlinkForestCreation(ctx *android.Context, extraNinjaDeps []string, metricsDir string) string {
var ninjaDeps []string
var mkdirCount, symlinkCount uint64
ctx.EventHandler.Do("symlink_forest", func() {
var ninjaDeps []string
ninjaDeps = append(ninjaDeps, extraNinjaDeps...)
verbose := ctx.Config().IsEnvTrue("BP2BUILD_VERBOSE")
@@ -469,15 +471,16 @@ func runSymlinkForestCreation(ctx *android.Context, extraNinjaDeps []string, met
// or file created/deleted under it would trigger an update of the symlink forest.
generatedRoot := shared.JoinPath(ctx.Config().SoongOutDir(), "bp2build")
workspaceRoot := shared.JoinPath(ctx.Config().SoongOutDir(), "workspace")
var symlinkForestDeps []string
ctx.EventHandler.Do("plant", func() {
symlinkForestDeps := bp2build.PlantSymlinkForest(
symlinkForestDeps, mkdirCount, symlinkCount = bp2build.PlantSymlinkForest(
verbose, topDir, workspaceRoot, generatedRoot, excludedFromSymlinkForest(ctx, verbose))
ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
})
writeDepFile(cmdlineArgs.SymlinkForestMarker, ctx.EventHandler, ninjaDeps)
touch(shared.JoinPath(topDir, cmdlineArgs.SymlinkForestMarker))
ninjaDeps = append(ninjaDeps, symlinkForestDeps...)
})
writeDepFile(cmdlineArgs.SymlinkForestMarker, ctx.EventHandler, ninjaDeps)
touch(shared.JoinPath(topDir, cmdlineArgs.SymlinkForestMarker))
codegenMetrics := bp2build.ReadCodegenMetrics(metricsDir)
if codegenMetrics == nil {
m := bp2build.CreateCodegenMetrics()
@@ -486,6 +489,8 @@ func runSymlinkForestCreation(ctx *android.Context, extraNinjaDeps []string, met
//TODO (usta) we cannot determine if we loaded a stale file, i.e. from an unrelated prior
//invocation of codegen. We should simply use a separate .pb file
}
codegenMetrics.SetSymlinkCount(symlinkCount)
codegenMetrics.SetMkDirCount(mkdirCount)
writeBp2BuildMetrics(codegenMetrics, ctx.EventHandler, metricsDir)
return cmdlineArgs.SymlinkForestMarker
}