Merge "Add top level and per-mutator traces to soong_build"
This commit is contained in:
@@ -32,8 +32,13 @@ type SoongMetrics struct {
|
|||||||
Variants int
|
Variants int
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReadSoongMetrics(config Config) SoongMetrics {
|
func readSoongMetrics(config Config) (SoongMetrics, bool) {
|
||||||
return config.Get(soongMetricsOnceKey).(SoongMetrics)
|
soongMetrics, ok := config.Peek(soongMetricsOnceKey)
|
||||||
|
if ok {
|
||||||
|
return soongMetrics.(SoongMetrics), true
|
||||||
|
} else {
|
||||||
|
return SoongMetrics{}, false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@@ -60,9 +65,11 @@ func (soongMetricsSingleton) GenerateBuildActions(ctx SingletonContext) {
|
|||||||
func collectMetrics(config Config, eventHandler metrics.EventHandler) *soong_metrics_proto.SoongBuildMetrics {
|
func collectMetrics(config Config, eventHandler metrics.EventHandler) *soong_metrics_proto.SoongBuildMetrics {
|
||||||
metrics := &soong_metrics_proto.SoongBuildMetrics{}
|
metrics := &soong_metrics_proto.SoongBuildMetrics{}
|
||||||
|
|
||||||
soongMetrics := ReadSoongMetrics(config)
|
soongMetrics, ok := readSoongMetrics(config)
|
||||||
metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules))
|
if ok {
|
||||||
metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants))
|
metrics.Modules = proto.Uint32(uint32(soongMetrics.Modules))
|
||||||
|
metrics.Variants = proto.Uint32(uint32(soongMetrics.Variants))
|
||||||
|
}
|
||||||
|
|
||||||
memStats := runtime.MemStats{}
|
memStats := runtime.MemStats{}
|
||||||
runtime.ReadMemStats(&memStats)
|
runtime.ReadMemStats(&memStats)
|
||||||
|
@@ -79,6 +79,17 @@ func (once *OncePer) Get(key OnceKey) interface{} {
|
|||||||
return once.maybeWaitFor(key, v)
|
return once.maybeWaitFor(key, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Peek returns the value previously computed with Once for a given key. If Once has not
|
||||||
|
// been called for the given key Peek will return ok == false.
|
||||||
|
func (once *OncePer) Peek(key OnceKey) (interface{}, bool) {
|
||||||
|
v, ok := once.values.Load(key)
|
||||||
|
if !ok {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
|
return once.maybeWaitFor(key, v), true
|
||||||
|
}
|
||||||
|
|
||||||
// OnceStringSlice is the same as Once, but returns the value cast to a []string
|
// OnceStringSlice is the same as Once, but returns the value cast to a []string
|
||||||
func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string {
|
func (once *OncePer) OnceStringSlice(key OnceKey, value func() []string) []string {
|
||||||
return once.Once(key, func() interface{} { return value() }).([]string)
|
return once.Once(key, func() interface{} { return value() }).([]string)
|
||||||
|
@@ -220,7 +220,7 @@ func writeDepFile(outputFile string, eventHandler metrics.EventHandler, ninjaDep
|
|||||||
// doChosenActivity runs Soong for a specific activity, like bp2build, queryview
|
// doChosenActivity runs Soong for a specific activity, like bp2build, queryview
|
||||||
// or the actual Soong build for the build.ninja file. Returns the top level
|
// or the actual Soong build for the build.ninja file. Returns the top level
|
||||||
// output file of the specific activity.
|
// output file of the specific activity.
|
||||||
func doChosenActivity(configuration android.Config, extraNinjaDeps []string, logDir string) string {
|
func doChosenActivity(ctx *android.Context, configuration android.Config, extraNinjaDeps []string, logDir string) string {
|
||||||
mixedModeBuild := configuration.BazelContext.BazelEnabled()
|
mixedModeBuild := configuration.BazelContext.BazelEnabled()
|
||||||
generateBazelWorkspace := bp2buildMarker != ""
|
generateBazelWorkspace := bp2buildMarker != ""
|
||||||
generateQueryView := bazelQueryViewDir != ""
|
generateQueryView := bazelQueryViewDir != ""
|
||||||
@@ -236,7 +236,6 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string, log
|
|||||||
|
|
||||||
blueprintArgs := cmdlineArgs
|
blueprintArgs := cmdlineArgs
|
||||||
|
|
||||||
ctx := newContext(configuration)
|
|
||||||
if mixedModeBuild {
|
if mixedModeBuild {
|
||||||
runMixedModeBuild(configuration, ctx, extraNinjaDeps)
|
runMixedModeBuild(configuration, ctx, extraNinjaDeps)
|
||||||
} else {
|
} else {
|
||||||
@@ -284,7 +283,6 @@ func doChosenActivity(configuration android.Config, extraNinjaDeps []string, log
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
writeMetrics(configuration, *ctx.EventHandler, logDir)
|
|
||||||
return cmdlineArgs.OutFile
|
return cmdlineArgs.OutFile
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -344,7 +342,13 @@ func main() {
|
|||||||
// change between every CI build, so tracking it would require re-running Soong for every build.
|
// change between every CI build, so tracking it would require re-running Soong for every build.
|
||||||
logDir := availableEnv["LOG_DIR"]
|
logDir := availableEnv["LOG_DIR"]
|
||||||
|
|
||||||
finalOutputFile := doChosenActivity(configuration, extraNinjaDeps, logDir)
|
ctx := newContext(configuration)
|
||||||
|
ctx.EventHandler.Begin("soong_build")
|
||||||
|
|
||||||
|
finalOutputFile := doChosenActivity(ctx, configuration, extraNinjaDeps, logDir)
|
||||||
|
|
||||||
|
ctx.EventHandler.End("soong_build")
|
||||||
|
writeMetrics(configuration, *ctx.EventHandler, logDir)
|
||||||
|
|
||||||
writeUsedEnvironmentFile(configuration, finalOutputFile)
|
writeUsedEnvironmentFile(configuration, finalOutputFile)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user