Add SoongExecutionMetrics to ninja run
This adds metrics for partial compilation to Soong.
- Soong_ui names the directory SOONG_METRICS_AGGREGATION_DIR, which it
empties before each ninja run.
- Find_input_delta writes metrics there
- At the end of the build, Soong_ui aggregates the metrics that were
written to generate the aggregated metrics.
Bug: b/376287012
Test: Manual, TH
Change-Id: I123df654f5b963fcd213b5c4d815173051f5d72e
diff --git a/ui/build/ninja.go b/ui/build/ninja.go
index f5f637f..04c52a2 100644
--- a/ui/build/ninja.go
+++ b/ui/build/ninja.go
@@ -244,6 +244,9 @@
// SOONG_USE_PARTIAL_COMPILE only determines which half of the rule we execute.
"SOONG_USE_PARTIAL_COMPILE",
+
+ // Directory for ExecutionMetrics
+ "SOONG_METRICS_AGGREGATION_DIR",
}, config.BuildBrokenNinjaUsesEnvVars()...)...)
}
@@ -256,6 +259,10 @@
// Only set RUST_BACKTRACE for n2.
}
+ // Set up the metrics aggregation directory.
+ ctx.ExecutionMetrics.SetDir(filepath.Join(config.OutDir(), "soong", "metrics_aggregation"))
+ cmd.Environment.Set("SOONG_METRICS_AGGREGATION_DIR", ctx.ExecutionMetrics.MetricsAggregationDir)
+
// Print the environment variables that Ninja is operating in.
ctx.Verboseln("Ninja environment: ")
envVars := cmd.Environment.Environ()
@@ -300,6 +307,8 @@
}
}()
+ ctx.ExecutionMetrics.Start()
+ defer ctx.ExecutionMetrics.Finish(ctx)
ctx.Status.Status("Starting ninja...")
cmd.RunAndStreamOrFatal()
}