Skip to content

Commit

Permalink
feat: print time taken to start (#2784)
Browse files Browse the repository at this point in the history
I think this is important as if this starts to creep up it is bad for
developer experience, and printing it out each time makes us much more
likely to notice if things are slowing down.
  • Loading branch information
stuartwdouglas authored Sep 23, 2024
1 parent 05006b4 commit 164cb5b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/cli/cmd_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type devCmd struct {
}

func (d *devCmd) Run(ctx context.Context, k *kong.Kong, projConfig projectconfig.Config, cancel context.CancelFunc) error {

startTime := time.Now()
console.LaunchEmbeddedConsole(ctx, k, projConfig, bindContext, cancel)
if len(d.Build.Dirs) == 0 {
d.Build.Dirs = projConfig.AbsModuleDirs()
Expand Down Expand Up @@ -85,7 +85,7 @@ func (d *devCmd) Run(ctx context.Context, k *kong.Kong, projConfig projectconfig
}
starting.Close()

opts := []buildengine.Option{buildengine.Parallelism(d.Build.Parallelism), buildengine.BuildEnv(d.Build.BuildEnv), buildengine.WithDevMode(true)}
opts := []buildengine.Option{buildengine.Parallelism(d.Build.Parallelism), buildengine.BuildEnv(d.Build.BuildEnv), buildengine.WithDevMode(true), buildengine.WithStartTime(startTime)}
if d.Lsp {
d.languageServer = lsp.NewServer(ctx)
opts = append(opts, buildengine.WithListener(d.languageServer))
Expand Down
15 changes: 14 additions & 1 deletion internal/buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"connectrpc.com/connect"
"github.com/alecthomas/types/optional"
"github.com/alecthomas/types/pubsub"
"github.com/jpillora/backoff"
"github.com/puzpuzpuz/xsync/v3"
Expand Down Expand Up @@ -78,6 +79,7 @@ type Engine struct {
modulesToBuild *xsync.MapOf[string, bool]
buildEnv []string
devMode bool
startTime optional.Option[time.Time]
}

type Option func(o *Engine)
Expand Down Expand Up @@ -108,6 +110,13 @@ func WithDevMode(devMode bool) Option {
}
}

// WithStartTime sets the start time to report total startup time
func WithStartTime(startTime time.Time) Option {
return func(o *Engine) {
o.startTime = optional.Some(startTime)
}
}

// New constructs a new [Engine].
//
// Completely offline builds are possible if the full dependency graph is
Expand Down Expand Up @@ -368,7 +377,11 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
logger.Errorf(err, "initial deploy failed")
e.reportBuildFailed(err)
} else {
logger.Infof("All modules deployed, watching for changes...")
if start, ok := e.startTime.Get(); ok {
logger.Infof("All modules deployed in %s, watching for changes...", time.Since(start).String())
} else {
logger.Infof("All modules deployed, watching for changes...")
}
e.reportSuccess()
}

Expand Down

0 comments on commit 164cb5b

Please sign in to comment.