From 164cb5bfff587ba2e99cbfe971dcb73bafffed20 Mon Sep 17 00:00:00 2001 From: Stuart Douglas Date: Mon, 23 Sep 2024 16:12:43 +1000 Subject: [PATCH] feat: print time taken to start (#2784) 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. --- frontend/cli/cmd_dev.go | 4 ++-- internal/buildengine/engine.go | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/frontend/cli/cmd_dev.go b/frontend/cli/cmd_dev.go index d11b19a8cb..f16d8c9ea9 100644 --- a/frontend/cli/cmd_dev.go +++ b/frontend/cli/cmd_dev.go @@ -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() @@ -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)) diff --git a/internal/buildengine/engine.go b/internal/buildengine/engine.go index 768ff16aef..d0448d5149 100644 --- a/internal/buildengine/engine.go +++ b/internal/buildengine/engine.go @@ -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" @@ -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) @@ -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 @@ -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() }