Merge "Use the build start time from Soong main UI for metrics build timestamp." am: 3058878cc7
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1362302 Change-Id: I0e15e8ed5f4cfb09d0b8916c2eb90bf133cc882a
This commit is contained in:
commit
cf9d84a893
5 changed files with 10 additions and 18 deletions
|
@ -117,7 +117,7 @@ func inList(s string, list []string) bool {
|
||||||
// Command is the type of soong_ui execution. Only one type of
|
// Command is the type of soong_ui execution. Only one type of
|
||||||
// execution is specified. The args are specific to the command.
|
// execution is specified. The args are specific to the command.
|
||||||
func main() {
|
func main() {
|
||||||
buildStartedMilli := time.Now().UnixNano() / int64(time.Millisecond)
|
buildStarted := time.Now()
|
||||||
|
|
||||||
c, args := getCommand(os.Args)
|
c, args := getCommand(os.Args)
|
||||||
if c == nil {
|
if c == nil {
|
||||||
|
@ -138,6 +138,7 @@ func main() {
|
||||||
defer trace.Close()
|
defer trace.Close()
|
||||||
|
|
||||||
met := metrics.New()
|
met := metrics.New()
|
||||||
|
met.SetBuildDateTime(buildStarted)
|
||||||
|
|
||||||
stat := &status.Status{}
|
stat := &status.Status{}
|
||||||
defer stat.Finish()
|
defer stat.Finish()
|
||||||
|
@ -171,7 +172,7 @@ func main() {
|
||||||
buildErrorFile := filepath.Join(logsDir, c.logsPrefix+"build_error")
|
buildErrorFile := filepath.Join(logsDir, c.logsPrefix+"build_error")
|
||||||
rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb")
|
rbeMetricsFile := filepath.Join(logsDir, c.logsPrefix+"rbe_metrics.pb")
|
||||||
soongMetricsFile := filepath.Join(logsDir, c.logsPrefix+"soong_metrics")
|
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)
|
os.MkdirAll(logsDir, 0777)
|
||||||
log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log"))
|
log.SetOutput(filepath.Join(logsDir, c.logsPrefix+"soong.log"))
|
||||||
|
|
|
@ -256,9 +256,6 @@ func NewConfig(ctx Context, args ...string) Config {
|
||||||
ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
|
ret.buildDateTime = strconv.FormatInt(time.Now().Unix(), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Metrics != nil {
|
|
||||||
ctx.Metrics.SetBuildDateTime(ret.buildDateTime)
|
|
||||||
}
|
|
||||||
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
|
ret.environ.Set("BUILD_DATETIME_FILE", buildDateTimeFile)
|
||||||
|
|
||||||
return Config{ret}
|
return Config{ret}
|
||||||
|
|
|
@ -44,7 +44,7 @@ var (
|
||||||
// environment variable. The metrics files are copied to a temporary directory
|
// 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
|
// and the uploader is then executed in the background to allow the user to continue
|
||||||
// working.
|
// 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")
|
ctx.BeginTrace(metrics.RunSetupTool, "upload_metrics")
|
||||||
defer ctx.EndTrace()
|
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
|
// For platform builds, the branch and target name is hardcoded to specific
|
||||||
// values for later extraction of the metrics in the data metrics pipeline.
|
// values for later extraction of the metrics in the data metrics pipeline.
|
||||||
data, err := proto.Marshal(&upload_proto.Upload{
|
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))),
|
CompletionTimestampMs: proto.Uint64(uint64(time.Now().UnixNano() / int64(time.Millisecond))),
|
||||||
BranchName: proto.String("developer-metrics"),
|
BranchName: proto.String("developer-metrics"),
|
||||||
TargetName: proto.String("platform-build-systems-metrics"),
|
TargetName: proto.String("platform-build-systems-metrics"),
|
||||||
|
|
|
@ -97,7 +97,7 @@ func TestUploadMetrics(t *testing.T) {
|
||||||
buildDateTime: strconv.FormatInt(time.Now().UnixNano()/int64(time.Millisecond), 10),
|
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",
|
"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)
|
t.Errorf("got nil, expecting %q as a failure", tt.expectedErr)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ package metrics
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"time"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"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) {
|
func (m *Metrics) SetBuildDateTime(buildTimestamp time.Time) {
|
||||||
if date_time != "" {
|
m.metrics.BuildDateTimestamp = proto.Int64(buildTimestamp.UnixNano() / int64(time.Second))
|
||||||
date_time_timestamp, err := strconv.ParseInt(date_time, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
m.metrics.BuildDateTimestamp = &date_time_timestamp
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// exports the output to the file at outputPath
|
// exports the output to the file at outputPath
|
||||||
|
|
Loading…
Reference in a new issue