Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1547)

Unified Diff: milo/appengine/buildbot/build.go

Issue 2772623002: Milo: Don't float step times if build has finished (Closed)
Patch Set: Compile fix Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | milo/appengine/buildbot/builder.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: milo/appengine/buildbot/build.go
diff --git a/milo/appengine/buildbot/build.go b/milo/appengine/buildbot/build.go
index 138ee35da6629f1163ada399c972d5dcb945f5c4..5c260a27e99051c1842db0a8969c63911ee53ce5 100644
--- a/milo/appengine/buildbot/build.go
+++ b/milo/appengine/buildbot/build.go
@@ -67,9 +67,20 @@ func result2Status(s *int) (status resp.Status) {
return
}
-// parseTimes translates a buildbot time tuple (start/end) into a triplet
+// buildbotTimeToTime converts a buildbot time representation (pointer to float
+// of seconds since epoch) to a native time.Time object.
+func buildbotTimeToTime(t *float64) (result time.Time) {
+ if t != nil {
+ result = time.Unix(int64(*t), int64(*t*1e9)%1e9).UTC()
+ }
+ return
+}
+
+// parseTimes translates a buildbot time tuple (start, end) into a triplet
// of (Started time, Ending time, duration).
-func parseTimes(times []*float64) (started, ended time.Time, duration time.Duration) {
+// If times[1] is nil and buildFinished is not, ended will be set to buildFinished
+// time.
+func parseTimes(buildFinished *float64, times []*float64) (started, ended time.Time, duration time.Duration) {
if len(times) != 2 {
panic(fmt.Errorf("Expected 2 floats for times, got %v", times))
}
@@ -77,11 +88,15 @@ func parseTimes(times []*float64) (started, ended time.Time, duration time.Durat
// Some steps don't have timing info. In that case, just return nils.
return
}
- started = time.Unix(int64(*times[0]), int64(*times[0]*1e9)%1e9).UTC()
- if times[1] != nil {
- ended = time.Unix(int64(*times[1]), int64(*times[1]*1e9)%1e9).UTC()
+ started = buildbotTimeToTime(times[0])
+ switch {
+ case times[1] != nil:
+ ended = buildbotTimeToTime(times[1])
duration = ended.Sub(started)
- } else {
+ case buildFinished != nil:
+ ended = buildbotTimeToTime(buildFinished)
+ duration = ended.Sub(started)
+ default:
duration = time.Since(started)
}
return
@@ -127,7 +142,7 @@ func summary(c context.Context, b *buildbotBuild) resp.BuildComponent {
}
// Timing info
- started, ended, duration := parseTimes(b.Times)
+ started, ended, duration := parseTimes(nil, b.Times)
// Link to bot and original build.
server := "build.chromium.org/p"
@@ -182,6 +197,7 @@ var rLineBreak = regexp.MustCompile("<br */?>")
// components takes a full buildbot build struct and extract step info from all
// of the steps and returns it as a list of milo Build Components.
func components(b *buildbotBuild) (result []*resp.BuildComponent) {
+ endingTime := b.Times[1]
for _, step := range b.Steps {
if step.Hidden == true {
continue
@@ -291,7 +307,7 @@ func components(b *buildbotBuild) (result []*resp.BuildComponent) {
}
// Figure out the times.
- bc.Started, bc.Finished, bc.Duration = parseTimes(step.Times)
+ bc.Started, bc.Finished, bc.Duration = parseTimes(endingTime, step.Times)
result = append(result, bc)
}
« no previous file with comments | « no previous file | milo/appengine/buildbot/builder.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698