Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 41886f27 authored by Jason Wu's avatar Jason Wu
Browse files

Stop embedding soong_build_metrics in soong_metrics

Test: Run `m --bazel-mode-dev nothing` and query the database to make sure
soong_build_metrics will only update to its standalone column
Run `bp2build` and `b build` to make sure soong_build_metrics and
soong_metrics.soong_build_metrics will be null.

Bug: 262280865
Change-Id: Ice5115c468bda350b742c5a1d03fff66ad346cd6
parent 22f8b3d9
Loading
Loading
Loading
Loading
+0 −54
Original line number Diff line number Diff line
@@ -15,16 +15,13 @@
package build

import (
	"errors"
	"fmt"
	"io/fs"
	"os"
	"path/filepath"
	"strconv"
	"strings"

	"android/soong/ui/metrics"
	soong_metrics_proto "android/soong/ui/metrics/metrics_proto"
	"android/soong/ui/status"

	"android/soong/shared"
@@ -32,8 +29,6 @@ import (
	"github.com/google/blueprint"
	"github.com/google/blueprint/bootstrap"
	"github.com/google/blueprint/microfactory"

	"google.golang.org/protobuf/proto"
)

const (
@@ -566,22 +561,6 @@ func runSoong(ctx Context, config Config) {
		targets = append(targets, config.SoongNinjaFile())
	}

	// TODO(juu): Stop embedding soong_build_metrics in soong_metrics.
	soongBuildMetricsFile := filepath.Join(config.LogsDir(), "soong_build_metrics.pb")
	if err := os.Remove(soongBuildMetricsFile); err != nil && !os.IsNotExist(err) {
		ctx.Verbosef("Failed to remove %s", soongBuildMetricsFile)
	}
	if shouldCollectBuildSoongMetrics(config) {
		defer func() {
			soongBuildMetrics := loadSoongBuildMetrics(ctx, soongBuildMetricsFile)
			if soongBuildMetrics != nil {
				logSoongBuildMetrics(ctx, soongBuildMetrics)
				if ctx.Metrics != nil {
					ctx.Metrics.SetSoongBuildMetrics(soongBuildMetrics)
				}
			}
		}()
	}
	ninja("bootstrap", "bootstrap.ninja", targets...)

	distGzipFile(ctx, config, config.SoongNinjaFile(), "soong")
@@ -614,36 +593,3 @@ func runMicrofactory(ctx Context, config Config, name string, pkg string, mappin
		ctx.Fatalf("failed to build %s: %s", name, err)
	}
}

func shouldCollectBuildSoongMetrics(config Config) bool {
	// Do not collect metrics protobuf if the soong_build binary ran as the
	// bp2build converter or the JSON graph dump.
	return config.SoongBuildInvocationNeeded()
}

func loadSoongBuildMetrics(ctx Context, soongBuildMetricsFile string) *soong_metrics_proto.SoongBuildMetrics {
	buf, err := os.ReadFile(soongBuildMetricsFile)
	if errors.Is(err, fs.ErrNotExist) {
		// Soong may not have run during this invocation
		ctx.Verbosef("Failed to read metrics file, %s: %s", soongBuildMetricsFile, err)
		return nil
	} else if err != nil {
		ctx.Fatalf("Failed to load %s: %s", soongBuildMetricsFile, err)
	}
	soongBuildMetrics := &soong_metrics_proto.SoongBuildMetrics{}
	err = proto.Unmarshal(buf, soongBuildMetrics)
	if err != nil {
		ctx.Fatalf("Failed to unmarshal %s: %s", soongBuildMetricsFile, err)
	}
	return soongBuildMetrics
}

func logSoongBuildMetrics(ctx Context, metrics *soong_metrics_proto.SoongBuildMetrics) {
	ctx.Verbosef("soong_build metrics:")
	ctx.Verbosef(" modules: %v", metrics.GetModules())
	ctx.Verbosef(" variants: %v", metrics.GetVariants())
	ctx.Verbosef(" max heap size: %v MB", metrics.GetMaxHeapSize()/1e6)
	ctx.Verbosef(" total allocation count: %v", metrics.GetTotalAllocCount())
	ctx.Verbosef(" total allocation size: %v MB", metrics.GetTotalAllocSize()/1e6)

}
+194 −189

File changed.

Preview size limit exceeded, changes collapsed.

+3 −1
Original line number Diff line number Diff line
@@ -93,7 +93,9 @@ message MetricsBase {
  // The metrics for the whole build
  optional PerfInfo total = 21;

  optional SoongBuildMetrics soong_build_metrics = 22;
  // Deprecated because instead of embedding in a MetricsBase, we keep
  // SoongBuildMetrics in its own file
  optional SoongBuildMetrics soong_build_metrics = 22 [deprecated=true];

  optional BuildConfig build_config = 23;