Add support for timing data in JSON format. (#510)

This commit is contained in:
dlorenc 2019-01-08 17:24:47 -08:00 committed by GitHub
parent 859e63c991
commit 5f6fbfe74f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -390,7 +390,11 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
}
defer f.Close()
f.WriteString(timing.Summary())
s, err := timing.JSON()
if err != nil {
logrus.Warnf("Unable to write benchmark file: %s", err)
}
f.WriteString(s)
}
return sourceImage, nil
}

View File

@ -18,6 +18,7 @@ package timing
import (
"bytes"
"encoding/json"
"sync"
"text/template"
"time"
@ -77,6 +78,10 @@ func Summary() string {
return DefaultRun.Summary()
}
func JSON() (string, error) {
return DefaultRun.JSON()
}
// Summary outputs a summary of the specified TimedRun.
func (tr *TimedRun) Summary() string {
b := bytes.Buffer{}
@ -86,3 +91,11 @@ func (tr *TimedRun) Summary() string {
DefaultFormat.Execute(&b, tr.categories)
return b.String()
}
func (tr *TimedRun) JSON() (string, error) {
b, err := json.Marshal(tr.categories)
if err != nil {
return "", err
}
return string(b), nil
}