Merge "Use the build start time from Soong main UI for metrics build timestamp."

This commit is contained in:
Treehugger Robot 2020-07-14 21:04:48 +00:00 committed by Gerrit Code Review
commit 3058878cc7
5 changed files with 10 additions and 18 deletions

View file

@ -117,7 +117,7 @@ func inList(s string, list []string) bool {
// Command is the type of soong_ui execution. Only one type of
// execution is specified. The args are specific to the command.
func main() {
buildStartedMilli := time.Now().UnixNano() / int64(time.Millisecond)
buildStarted := time.Now()
c, args := getCommand(os.Args)
if c == nil {
@ -138,6 +138,7 @@ func main() {
defer trace.Close()
met := metrics.New()
met.SetBuildDateTime(buildStarted)
stat := &status.Status{}
defer stat.Finish()
@ -171,7 +172,7 @@ func main() {
buildErrorFile := filepath.Join(logsDir, c.logsPrefix+"build_error")
rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb")
soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics")
defer build.UploadMetrics(buildCtx, config, c.forceDumbOutput, buildStartedMilli, buildErrorFile, rbeMetricsFile, soongMetricsFile)
defer build.UploadMetrics(buildCtx, config, c.forceDumbOutput, buildStarted, buildErrorFile, rbeMetricsFile, soongMetricsFile)
os.MkdirAll(logsDir, 0777)
log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log"))

View file

@ -256,9 +256,6 @@ func NewConfig(ctx Context, args ...string) Config {
ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
}
if ctx.Metrics != nil {
ctx.Metrics.SetBuildDateTime(ret.buildDateTime)
}
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
return Config{ret}

View file

@ -44,7 +44,7 @@ var (
// environment variable. The metrics files are copied to a temporary directory
// and the uploader is then executed in the background to allow the user to continue
// working.
func UploadMetrics(ctx Context, config Config, forceDumbOutput bool, buildStartedMilli int64, files ...string) {
func UploadMetrics(ctx Context, config Config, forceDumbOutput bool, buildStarted time.Time, files ...string) {
ctx.BeginTrace(metrics.RunSetupTool, "upload_metrics")
defer ctx.EndTrace()
@ -86,7 +86,7 @@ func UploadMetrics(ctx Context, config Config, forceDumbOutput bool, buildStarte
// For platform builds, the branch and target name is hardcoded to specific
// values for later extraction of the metrics in the data metrics pipeline.
data, err := proto.Marshal(&upload_proto.Upload{
CreationTimestampMs: proto.Uint64(uint64(buildStartedMilli)),
CreationTimestampMs: proto.Uint64(uint64(buildStarted.UnixNano() / int64(time.Millisecond))),
CompletionTimestampMs: proto.Uint64(uint64(time.Now().UnixNano() / int64(time.Millisecond))),
BranchName: proto.String("developer-metrics"),
TargetName: proto.String("platform-build-systems-metrics"),

View file

@ -97,7 +97,7 @@ func TestUploadMetrics(t *testing.T) {
buildDateTime: strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10),
}}
UploadMetrics(ctx, config, false, 1591031903, metricsFiles...)
UploadMetrics(ctx, config, false, time.Now(), metricsFiles...)
})
}
}
@ -151,7 +151,7 @@ func TestUploadMetricsErrors(t *testing.T) {
"OUT_DIR=/bad",
}}}
UploadMetrics(ctx, config, true, 1591031903, metricsFile)
UploadMetrics(ctx, config, true, time.Now(), metricsFile)
t.Errorf("got nil, expecting %q as a failure", tt.expectedErr)
})
}

View file

@ -17,7 +17,7 @@ package metrics
import (
"io/ioutil"
"os"
"strconv"
"time"
"github.com/golang/protobuf/proto"
@ -131,14 +131,8 @@ func (m *Metrics) getArch(arch string) *soong_metrics_proto.MetricsBase_Arch {
}
}
func (m *Metrics) SetBuildDateTime(date_time string) {
if date_time != "" {
date_time_timestamp, err := strconv.ParseInt(date_time, 10, 64)
if err != nil {
panic(err)
}
m.metrics.BuildDateTimestamp = &date_time_timestamp
}
func (m *Metrics) SetBuildDateTime(buildTimestamp time.Time) {
m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
}
// exports the output to the file at outputPath