From f2615e923eda16c183c9444d62d558da9ff7501f Mon Sep 17 00:00:00 2001 From: Yu Liu Date: Thu, 16 May 2024 23:15:49 +0000 Subject: [PATCH] Upload build.trace.gz for user builds. Bug: 340206057 Test: Manually verified build.trace.gz was uploaded to build server. Change-Id: I9c071188343baf7c11c30a5c4c1d1ca7bcaac06b --- cmd/soong_ui/main.go | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/cmd/soong_ui/main.go b/cmd/soong_ui/main.go index fe3f8f725..2d3156a46 100644 --- a/cmd/soong_ui/main.go +++ b/cmd/soong_ui/main.go @@ -155,7 +155,6 @@ func main() { // Create a new trace file writer, making it log events to the log instance. trace := tracer.New(log) - defer trace.Close() // Create a new Status instance, which manages action counts and event output channels. stat := &status.Status{} @@ -194,14 +193,29 @@ func main() { soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics") rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb") soongBuildMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_build_metrics.pb") + buildTraceFile := filepath.Join(logsDir, c.logsPrefix+"build.trace.gz") metricsFiles := []string{ buildErrorFile, // build error strings rbeMetricsFile, // high level metrics related to remote build execution. soongMetricsFile, // high level metrics related to this build system. soongBuildMetricsFile, // high level metrics related to soong build + buildTraceFile, } + defer func() { + stat.Finish() + criticalPath.WriteToMetrics(met) + met.Dump(soongMetricsFile) + if !config.SkipMetricsUpload() { + build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...) + } + }() + + // This has to come after the metrics uploading function, so that + // build.trace.gz is closed and ready for upload. + defer trace.Close() + os.MkdirAll(logsDir, 0777) log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log")) @@ -222,16 +236,7 @@ func main() { config = freshConfig() } - defer func() { - stat.Finish() - criticalPath.WriteToMetrics(met) - met.Dump(soongMetricsFile) - if !config.SkipMetricsUpload() { - build.UploadMetrics(buildCtx, config, c.simpleOutput, buildStarted, metricsFiles...) - } - }() c.run(buildCtx, config, args) - } // This function must not modify config, since product config may cause us to recreate the config,