Add top level and per-mutator traces to soong_build
- Top-level trace for all soong_build runs
- Includes adding Peek() to OncePer because not all soong_build
invocations have GenerateBuildActions run.
- A trace per mutator invocation
Test: m && build/bazel/scripts/print_analysis_metrics.py
Change-Id: Ief5c04630484fb38ec7e3757de45c7dc294d3b3c
diff --git a/android/metrics.go b/android/metrics.go
index 1580f82..ecda026 100644
--- a/android/metrics.go
+++ b/android/metrics.go
@@ -32,8 +32,13 @@
Variants int
}
-func ReadSoongMetrics(config Config) SoongMetrics {
- return config.Get(soongMetricsOnceKey).(SoongMetrics)
+func readSoongMetrics(config Config) (SoongMetrics, bool) {
+ soongMetrics, ok := config.Peek(soongMetricsOnceKey)
+ if ok {
+ return soongMetrics.(SoongMetrics), true
+ } else {
+ return SoongMetrics{}, false
+ }
}
func init() {
@@ -60,9 +65,11 @@
func collectMetrics(config Config, eventHandler metrics.EventHandler) *soong_metrics_proto.SoongBuildMetrics {
metrics := &soong_metrics_proto.SoongBuildMetrics{}
- soongMetrics := ReadSoongMetrics(config)
- metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules))
- metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants))
+ soongMetrics, ok := readSoongMetrics(config)
+ if ok {
+ metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules))
+ metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants))
+ }
memStats := runtime.MemStats{}
runtime.ReadMemStats(&memStats)