Add support for timing data in JSON format. (#510)
This commit is contained in:
parent
859e63c991
commit
5f6fbfe74f
|
|
@ -390,7 +390,11 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
|
||||||
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
|
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
|
||||||
}
|
}
|
||||||
defer f.Close()
|
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
|
return sourceImage, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package timing
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
"sync"
|
"sync"
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
@ -77,6 +78,10 @@ func Summary() string {
|
||||||
return DefaultRun.Summary()
|
return DefaultRun.Summary()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JSON() (string, error) {
|
||||||
|
return DefaultRun.JSON()
|
||||||
|
}
|
||||||
|
|
||||||
// Summary outputs a summary of the specified TimedRun.
|
// Summary outputs a summary of the specified TimedRun.
|
||||||
func (tr *TimedRun) Summary() string {
|
func (tr *TimedRun) Summary() string {
|
||||||
b := bytes.Buffer{}
|
b := bytes.Buffer{}
|
||||||
|
|
@ -86,3 +91,11 @@ func (tr *TimedRun) Summary() string {
|
||||||
DefaultFormat.Execute(&b, tr.categories)
|
DefaultFormat.Execute(&b, tr.categories)
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tr *TimedRun) JSON() (string, error) {
|
||||||
|
b, err := json.Marshal(tr.categories)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(b), nil
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue