Add a lot more timing data. (#518)

This commit is contained in:
dlorenc 2019-01-10 13:27:55 -07:00 committed by GitHub
parent 9ab66560db
commit 170e0a2d94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 16 deletions

View File

@ -24,6 +24,8 @@ import (
"strings" "strings"
"time" "time"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/buildcontext" "github.com/GoogleContainerTools/kaniko/pkg/buildcontext"
"github.com/GoogleContainerTools/kaniko/pkg/config" "github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants" "github.com/GoogleContainerTools/kaniko/pkg/constants"
@ -87,6 +89,21 @@ var RootCmd = &cobra.Command{
if err := executor.DoPush(image, opts); err != nil { if err := executor.DoPush(image, opts); err != nil {
exit(errors.Wrap(err, "error pushing image")) exit(errors.Wrap(err, "error pushing image"))
} }
benchmarkFile := os.Getenv("BENCHMARK_FILE")
// false is a keyword for integration tests to turn off benchmarking
if benchmarkFile != "" && benchmarkFile != "false" {
f, err := os.Create(benchmarkFile)
if err != nil {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
}
defer f.Close()
s, err := timing.JSON()
if err != nil {
logrus.Warnf("Unable to write benchmark file: %s", err)
}
f.WriteString(s)
}
}, },
} }

View File

@ -382,20 +382,6 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
} }
} }
timing.DefaultRun.Stop(t) timing.DefaultRun.Stop(t)
benchmarkFile := os.Getenv("BENCHMARK_FILE")
// false is a keyword for integration tests to turn off benchmarking
if benchmarkFile != "" && benchmarkFile != "false" {
f, err := os.Create(benchmarkFile)
if err != nil {
logrus.Warnf("Unable to create benchmarking file %s: %s", benchmarkFile, err)
}
defer f.Close()
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
} }
if stage.SaveStage { if stage.SaveStage {

View File

@ -25,6 +25,7 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/cache" "github.com/GoogleContainerTools/kaniko/pkg/cache"
"github.com/GoogleContainerTools/kaniko/pkg/config" "github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants" "github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/version" "github.com/GoogleContainerTools/kaniko/pkg/version"
"github.com/google/go-containerregistry/pkg/authn" "github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/authn/k8schain" "github.com/google/go-containerregistry/pkg/authn/k8schain"
@ -53,6 +54,7 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
logrus.Info("Skipping push to container registry due to --no-push flag") logrus.Info("Skipping push to container registry due to --no-push flag")
return nil return nil
} }
t := timing.Start("Total Push Time")
destRefs := []name.Tag{} destRefs := []name.Tag{}
for _, destination := range opts.Destinations { for _, destination := range opts.Destinations {
destRef, err := name.NewTag(destination, name.WeakValidation) destRef, err := name.NewTag(destination, name.WeakValidation)
@ -103,6 +105,7 @@ func DoPush(image v1.Image, opts *config.KanikoOptions) error {
return errors.Wrap(err, fmt.Sprintf("failed to push to destination %s", destRef)) return errors.Wrap(err, fmt.Sprintf("failed to push to destination %s", destRef))
} }
} }
timing.DefaultRun.Stop(t)
return nil return nil
} }

View File

@ -23,6 +23,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util" "github.com/GoogleContainerTools/kaniko/pkg/util"
) )
@ -124,6 +125,8 @@ func (l *LayeredMap) Add(s string) error {
// was added. // was added.
func (l *LayeredMap) MaybeAdd(s string) (bool, error) { func (l *LayeredMap) MaybeAdd(s string) (bool, error) {
oldV, ok := l.Get(s) oldV, ok := l.Get(s)
t := timing.Start("Hashing files")
defer timing.DefaultRun.Stop(t)
newV, err := l.hasher(s) newV, err := l.hasher(s)
if err != nil { if err != nil {
return false, err return false, err

View File

@ -22,6 +22,8 @@ import (
"path/filepath" "path/filepath"
"syscall" "syscall"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/karrick/godirwalk" "github.com/karrick/godirwalk"
"github.com/GoogleContainerTools/kaniko/pkg/constants" "github.com/GoogleContainerTools/kaniko/pkg/constants"
@ -141,6 +143,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
t := util.NewTar(f) t := util.NewTar(f)
defer t.Close() defer t.Close()
timer := timing.Start("Walking filesystem")
// Save the fs state in a map to iterate over later. // Save the fs state in a map to iterate over later.
memFs := map[string]*godirwalk.Dirent{} memFs := map[string]*godirwalk.Dirent{}
godirwalk.Walk(s.directory, &godirwalk.Options{ godirwalk.Walk(s.directory, &godirwalk.Options{
@ -158,6 +161,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
Unsorted: true, Unsorted: true,
}, },
) )
timing.DefaultRun.Stop(timer)
// First handle whiteouts // First handle whiteouts
for p := range memFs { for p := range memFs {
@ -176,6 +180,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
} }
} }
timer = timing.Start("Writing tar file")
// Now create the tar. // Now create the tar.
for path := range memFs { for path := range memFs {
whitelisted, err := util.CheckWhitelist(path) whitelisted, err := util.CheckWhitelist(path)
@ -198,6 +203,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
} }
} }
} }
timing.DefaultRun.Stop(timer)
return f.Name(), nil return f.Name(), nil
} }

View File

@ -39,11 +39,11 @@ type TimedRun struct {
// Stop stops the specified timer and increments the time spent in that category. // Stop stops the specified timer and increments the time spent in that category.
func (tr *TimedRun) Stop(t *Timer) { func (tr *TimedRun) Stop(t *Timer) {
stop := currentTimeFunc() stop := currentTimeFunc()
tr.cl.Lock()
defer tr.cl.Unlock()
if _, ok := tr.categories[t.category]; !ok { if _, ok := tr.categories[t.category]; !ok {
tr.categories[t.category] = 0 tr.categories[t.category] = 0
} }
tr.cl.Lock()
defer tr.cl.Unlock()
tr.categories[t.category] += stop.Sub(t.startTime) tr.categories[t.category] += stop.Sub(t.startTime)
} }