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

Commit c21015a0 authored by David Goldsmith's avatar David Goldsmith Committed by Gerrit Code Review
Browse files

Merge "Add metrics to expconfigfetcher call"

parents d2aa190b 62243a36
Loading
Loading
Loading
Loading
+26 −13
Original line number Diff line number Diff line
@@ -144,6 +144,12 @@ func checkTopDir(ctx Context) {
// fetchEnvConfig optionally fetches environment config from an
// experiments system to control Soong features dynamically.
func fetchEnvConfig(ctx Context, config *configImpl, envConfigName string) error {
	configName := envConfigName + "." + jsonSuffix
	expConfigFetcher := &smpb.ExpConfigFetcher{}
	defer func() {
		ctx.Metrics.ExpConfigFetcher(expConfigFetcher)
	}()

	s, err := os.Stat(configFetcher)
	if err != nil {
		if os.IsNotExist(err) {
@@ -152,31 +158,38 @@ func fetchEnvConfig(ctx Context, config *configImpl, envConfigName string) error
		return err
	}
	if s.Mode()&0111 == 0 {
		status := smpb.ExpConfigFetcher_ERROR
		expConfigFetcher.Status = &status
		return fmt.Errorf("configuration fetcher binary %v is not executable: %v", configFetcher, s.Mode())
	}

	configExists := false
	outConfigFilePath := filepath.Join(config.OutDir(), envConfigName+jsonSuffix)
	if _, err := os.Stat(outConfigFilePath); err == nil {
		configExists = true
	}

	tCtx, cancel := context.WithTimeout(ctx, envConfigFetchTimeout)
	defer cancel()
	cmd := exec.CommandContext(tCtx, configFetcher, "-output_config_dir", config.OutDir())
	fetchStart := time.Now()
	cmd := exec.CommandContext(tCtx, configFetcher, "-output_config_dir", config.OutDir(),
		"-output_config_name", configName)
	if err := cmd.Start(); err != nil {
		status := smpb.ExpConfigFetcher_ERROR
		expConfigFetcher.Status = &status
		return err
	}

	// If a config file already exists, return immediately and run the config file
	// fetch in the background. Otherwise, wait for the config file to be fetched.
	if configExists {
		go cmd.Wait()
		return nil
	}
	if err := cmd.Wait(); err != nil {
		status := smpb.ExpConfigFetcher_ERROR
		expConfigFetcher.Status = &status
		return err
	}
	fetchEnd := time.Now()
	expConfigFetcher.Micros = proto.Uint64(uint64(fetchEnd.Sub(fetchStart).Microseconds()))
	outConfigFilePath := filepath.Join(config.OutDir(), configName)
	expConfigFetcher.Filename = proto.String(outConfigFilePath)
	if _, err := os.Stat(outConfigFilePath); err == nil {
		status := smpb.ExpConfigFetcher_CONFIG
		expConfigFetcher.Status = &status
	} else {
		status := smpb.ExpConfigFetcher_NO_CONFIG
		expConfigFetcher.Status = &status
	}
	return nil
}

+6 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import (
	"time"

	"android/soong/shared"

	"google.golang.org/protobuf/proto"

	soong_metrics_proto "android/soong/ui/metrics/metrics_proto"
@@ -135,6 +136,11 @@ func (m *Metrics) SystemResourceInfo(b *soong_metrics_proto.SystemResourceInfo)
	m.metrics.SystemResourceInfo = b
}

// ExpConfigFetcher stores information about the expconfigfetcher.
func (m *Metrics) ExpConfigFetcher(b *soong_metrics_proto.ExpConfigFetcher) {
	m.metrics.ExpConfigFetcher = b
}

// SetMetadataMetrics sets information about the build such as the target
// product, host architecture and out directory.
func (m *Metrics) SetMetadataMetrics(metadata map[string]string) {
+320 −149

File changed.

Preview size limit exceeded, changes collapsed.

+22 −0
Original line number Diff line number Diff line
@@ -108,6 +108,9 @@ message MetricsBase {

  // The metrics for calling Bazel.
  repeated PerfInfo bazel_runs = 27;

  // The metrics of the experiment config fetcher
  optional ExpConfigFetcher exp_config_fetcher = 28;
}

message BuildConfig {
@@ -239,3 +242,22 @@ message SoongBuildMetrics {
  // Runtime metrics for soong_build execution.
  repeated PerfInfo events = 6;
}

message ExpConfigFetcher {
  enum ConfigStatus {
    NO_CONFIG = 0;
    CONFIG = 1;
    ERROR = 2;
  }
  // The result of the call to expconfigfetcher
  // NO_CONFIG - Not part of experiment
  // CONFIG - Part of experiment, config copied successfully
  // ERROR - expconfigfetcher failed
  optional ConfigStatus status = 1;

  // The output config filename
  optional string filename = 2;

  // Time, in microseconds, taken by the expconfigfetcher
  optional uint64 micros = 3;
}