Skip to content

Commit

Permalink
feat: allow easy generation of a trace file (#3736)
Browse files Browse the repository at this point in the history
If you start FTL with --trace=trace.out after execution you can look at
the execution time details via:

go tool trace trace.out
  • Loading branch information
stuartwdouglas authored Dec 13, 2024
1 parent 7eeef45 commit 621ffe3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frontend/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os/signal"
"path/filepath"
"runtime"
"runtime/trace"
"strconv"
"syscall"

Expand Down Expand Up @@ -44,6 +45,7 @@ type InteractiveCLI struct {
TimelineEndpoint *url.URL `help:"Timeline endpoint." env:"FTL_TIMELINE_ENDPOINT" default:"http://127.0.0.1:8894"`
LeaseEndpoint *url.URL `help:"Lease endpoint." env:"FTL_LEASE_ENDPOINT" default:"http://127.0.0.1:8895"`
AdminEndpoint *url.URL `help:"Admin endpoint." env:"FTL_ADMIN_ENDPOINT" default:"http://127.0.0.1:8896"`
Trace string `help:"File to write golang runtime/trace output to." hidden:""`

Ping pingCmd `cmd:"" help:"Ping the FTL cluster."`
Status statusCmd `cmd:"" help:"Show FTL status."`
Expand Down Expand Up @@ -106,6 +108,19 @@ func main() {
kctx, err := app.Parse(os.Args[1:])
app.FatalIfErrorf(err)

if cli.Trace != "" {
file, err := os.OpenFile(cli.Trace, os.O_CREATE|os.O_WRONLY, 0644) // #nosec
if err != nil {
kctx.Fatalf("failed to open trace file: %s", err.Error())
}
err = trace.Start(file)
if err != nil {
kctx.Fatalf("failed to start tracing: %s", err.Error())
return
}
defer trace.Stop()
}

if plugin, ok := languagePlugin.Get(); ok {
// Plugins take time to launch, so we bind the "ftl new" plugin to the kong context.
kctx.Bind(plugin)
Expand Down

0 comments on commit 621ffe3

Please sign in to comment.