Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. | 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
| 4 | 4 |
| 5 package main | 5 package main |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "flag" | 8 "flag" |
| 9 "fmt" | 9 "fmt" |
| 10 "sort" | 10 "sort" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 173 if factor >= 1 { | 173 if factor >= 1 { |
| 174 fmt.Printf("%s is %.1fx faster\n", r.builder2, factor) | 174 fmt.Printf("%s is %.1fx faster\n", r.builder2, factor) |
| 175 } else { | 175 } else { |
| 176 fmt.Printf("%s is %.1fx slower\n", r.builder2, 1/factor) | 176 fmt.Printf("%s is %.1fx slower\n", r.builder2, 1/factor) |
| 177 } | 177 } |
| 178 fmt.Printf("%s median time: %s\n", r.builder1, time1) | 178 fmt.Printf("%s median time: %s\n", r.builder1, time1) |
| 179 fmt.Printf("%s median time: %s\n", r.builder2, time2) | 179 fmt.Printf("%s median time: %s\n", r.builder2, time2) |
| 180 return nil | 180 return nil |
| 181 } | 181 } |
| 182 | 182 |
| 183 func (r *inconsistencyRun) fetchBuilds(builder builderID, startingFrom time.Time ) ([]*buildbucket.ApiBuildMessage, error) { | 183 func (r *inconsistencyRun) fetchBuilds(builder builderID, startingFrom time.Time ) ([]*buildbucket.ApiCommonBuildMessage, error) { |
|
nodir
2017/06/08 01:25:23
:(
| |
| 184 req := r.client.Search() | 184 req := r.client.Search() |
| 185 req.Bucket(builder.Bucket) | 185 req.Bucket(builder.Bucket) |
| 186 req.Tag("builder:" + builder.Builder) | 186 req.Tag("builder:" + builder.Builder) |
| 187 req.Status("COMPLETED") | 187 req.Status("COMPLETED") |
| 188 req.MaxBuilds(100) | 188 req.MaxBuilds(100) |
| 189 | 189 |
| 190 » var result []*buildbucket.ApiBuildMessage | 190 » var result []*buildbucket.ApiCommonBuildMessage |
| 191 for { | 191 for { |
| 192 res, err := req.Do() | 192 res, err := req.Do() |
| 193 if err != nil { | 193 if err != nil { |
| 194 return result, err | 194 return result, err |
| 195 } | 195 } |
| 196 if res.Error != nil { | 196 if res.Error != nil { |
| 197 return result, fmt.Errorf(res.Error.Message) | 197 return result, fmt.Errorf(res.Error.Message) |
| 198 } | 198 } |
| 199 | 199 |
| 200 for _, b := range res.Builds { | 200 for _, b := range res.Builds { |
| 201 if parseTimestamp(b.CreatedTs).Before(startingFrom) { | 201 if parseTimestamp(b.CreatedTs).Before(startingFrom) { |
| 202 return result, nil | 202 return result, nil |
| 203 } | 203 } |
| 204 result = append(result, b) | 204 result = append(result, b) |
| 205 } | 205 } |
| 206 | 206 |
| 207 if len(res.Builds) == 0 || res.NextCursor == "" { | 207 if len(res.Builds) == 0 || res.NextCursor == "" { |
| 208 break | 208 break |
| 209 } | 209 } |
| 210 req.StartCursor(res.NextCursor) | 210 req.StartCursor(res.NextCursor) |
| 211 } | 211 } |
| 212 return result, nil | 212 return result, nil |
| 213 } | 213 } |
| 214 | 214 |
| 215 type buildSet struct { | 215 type buildSet struct { |
| 216 » builds []*buildbucket.ApiBuildMessage | 216 » builds []*buildbucket.ApiCommonBuildMessage |
| 217 bestResult string | 217 bestResult string |
| 218 } | 218 } |
| 219 | 219 |
| 220 // groupBuilds groups builds by buildset tag. | 220 // groupBuilds groups builds by buildset tag. |
| 221 func groupBuilds(builds []*buildbucket.ApiBuildMessage) map[string]*buildSet { | 221 func groupBuilds(builds []*buildbucket.ApiCommonBuildMessage) map[string]*buildS et { |
| 222 results := map[string]*buildSet{} | 222 results := map[string]*buildSet{} |
| 223 for _, b := range builds { | 223 for _, b := range builds { |
| 224 tags := parseTags(b.Tags) | 224 tags := parseTags(b.Tags) |
| 225 buildSetName := tags["buildset"] | 225 buildSetName := tags["buildset"] |
| 226 if buildSetName == "" { | 226 if buildSetName == "" { |
| 227 fmt.Printf("skipped build %d: no buildset tag\n", b.Id) | 227 fmt.Printf("skipped build %d: no buildset tag\n", b.Id) |
| 228 continue | 228 continue |
| 229 } | 229 } |
| 230 set := results[buildSetName] | 230 set := results[buildSetName] |
| 231 if set == nil { | 231 if set == nil { |
| 232 set = &buildSet{} | 232 set = &buildSet{} |
| 233 results[buildSetName] = set | 233 results[buildSetName] = set |
| 234 } | 234 } |
| 235 | 235 |
| 236 set.builds = append(set.builds, b) | 236 set.builds = append(set.builds, b) |
| 237 if set.bestResult == "" || b.Result == "SUCCESS" { | 237 if set.bestResult == "" || b.Result == "SUCCESS" { |
| 238 set.bestResult = b.Result | 238 set.bestResult = b.Result |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 return results | 241 return results |
| 242 } | 242 } |
| 243 | 243 |
| 244 // medianTime returns median completed_time - created_time of successful builds. | 244 // medianTime returns median completed_time - created_time of successful builds. |
| 245 func medianTime(builds []*buildbucket.ApiBuildMessage) time.Duration { | 245 func medianTime(builds []*buildbucket.ApiCommonBuildMessage) time.Duration { |
| 246 if len(builds) == 0 { | 246 if len(builds) == 0 { |
| 247 return 0 | 247 return 0 |
| 248 } | 248 } |
| 249 durations := make(durationSlice, 0, len(builds)) | 249 durations := make(durationSlice, 0, len(builds)) |
| 250 for _, b := range builds { | 250 for _, b := range builds { |
| 251 if b.Result != "SUCCESS" { | 251 if b.Result != "SUCCESS" { |
| 252 continue | 252 continue |
| 253 } | 253 } |
| 254 created := parseTimestamp(b.CreatedTs) | 254 created := parseTimestamp(b.CreatedTs) |
| 255 completed := parseTimestamp(b.CompletedTs) | 255 completed := parseTimestamp(b.CompletedTs) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 275 return time.Time{} | 275 return time.Time{} |
| 276 } | 276 } |
| 277 return time.Unix(ts/1000000, 0) | 277 return time.Unix(ts/1000000, 0) |
| 278 } | 278 } |
| 279 | 279 |
| 280 type durationSlice []time.Duration | 280 type durationSlice []time.Duration |
| 281 | 281 |
| 282 func (a durationSlice) Len() int { return len(a) } | 282 func (a durationSlice) Len() int { return len(a) } |
| 283 func (a durationSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] } | 283 func (a durationSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] } |
| 284 func (a durationSlice) Less(i, j int) bool { return a[i] < a[j] } | 284 func (a durationSlice) Less(i, j int) bool { return a[i] < a[j] } |
| OLD | NEW |