Skip to content

Commit

Permalink
Add a lot more timing data. (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
dlorenc authored Jan 10, 2019
1 parent 9ab6656 commit 170e0a2
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
17 changes: 17 additions & 0 deletions cmd/executor/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"strings"
"time"

"github.com/GoogleContainerTools/kaniko/pkg/timing"

"github.com/GoogleContainerTools/kaniko/pkg/buildcontext"
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
Expand Down Expand Up @@ -87,6 +89,21 @@ var RootCmd = &cobra.Command{
if err := executor.DoPush(image, opts); err != nil {
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)
}
},
}

Expand Down
14 changes: 0 additions & 14 deletions pkg/executor/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,20 +382,6 @@ func DoBuild(opts *config.KanikoOptions) (v1.Image, error) {
}
}
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
}
if stage.SaveStage {
Expand Down
3 changes: 3 additions & 0 deletions pkg/executor/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/cache"
"github.com/GoogleContainerTools/kaniko/pkg/config"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/version"
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/authn/k8schain"
Expand Down Expand Up @@ -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")
return nil
}
t := timing.Start("Total Push Time")
destRefs := []name.Tag{}
for _, destination := range opts.Destinations {
destRef, err := name.NewTag(destination, name.WeakValidation)
Expand Down Expand Up @@ -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))
}
}
timing.DefaultRun.Stop(t)
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/snapshot/layered_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"path/filepath"
"strings"

"github.com/GoogleContainerTools/kaniko/pkg/timing"
"github.com/GoogleContainerTools/kaniko/pkg/util"
)

Expand Down Expand Up @@ -124,6 +125,8 @@ func (l *LayeredMap) Add(s string) error {
// was added.
func (l *LayeredMap) MaybeAdd(s string) (bool, error) {
oldV, ok := l.Get(s)
t := timing.Start("Hashing files")
defer timing.DefaultRun.Stop(t)
newV, err := l.hasher(s)
if err != nil {
return false, err
Expand Down
6 changes: 6 additions & 0 deletions pkg/snapshot/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"path/filepath"
"syscall"

"github.com/GoogleContainerTools/kaniko/pkg/timing"

"github.com/karrick/godirwalk"

"github.com/GoogleContainerTools/kaniko/pkg/constants"
Expand Down Expand Up @@ -141,6 +143,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
t := util.NewTar(f)
defer t.Close()

timer := timing.Start("Walking filesystem")
// Save the fs state in a map to iterate over later.
memFs := map[string]*godirwalk.Dirent{}
godirwalk.Walk(s.directory, &godirwalk.Options{
Expand All @@ -158,6 +161,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
Unsorted: true,
},
)
timing.DefaultRun.Stop(timer)

// First handle whiteouts
for p := range memFs {
Expand All @@ -176,6 +180,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
}
}

timer = timing.Start("Writing tar file")
// Now create the tar.
for path := range memFs {
whitelisted, err := util.CheckWhitelist(path)
Expand All @@ -198,6 +203,7 @@ func (s *Snapshotter) TakeSnapshotFS() (string, error) {
}
}
}
timing.DefaultRun.Stop(timer)

return f.Name(), nil
}
4 changes: 2 additions & 2 deletions pkg/timing/timing.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ type TimedRun struct {
// Stop stops the specified timer and increments the time spent in that category.
func (tr *TimedRun) Stop(t *Timer) {
stop := currentTimeFunc()
tr.cl.Lock()
defer tr.cl.Unlock()
if _, ok := tr.categories[t.category]; !ok {
tr.categories[t.category] = 0
}
tr.cl.Lock()
defer tr.cl.Unlock()
tr.categories[t.category] += stop.Sub(t.startTime)
}

Expand Down

0 comments on commit 170e0a2

Please sign in to comment.