feature/add-profiler (#42)

This commit is contained in:
T. von Dein
2026-06-18 08:54:00 +02:00
parent 5d345aaa9a
commit 802217158c
4 changed files with 37 additions and 3 deletions

View File

@@ -19,7 +19,9 @@ package cmd
import (
"context"
"fmt"
golog "log"
"os"
"runtime/pprof"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
@@ -83,6 +85,12 @@ func Main() int {
Usage: "output mode (tsv, markdown, json, yaml) default: tsv",
Destination: &conf.Output,
},
&cli.StringFlag{
Name: "profile-file",
Usage: "golang profiler output file",
Destination: &conf.ProfileFile,
Hidden: true,
},
},
Commands: []*cli.Command{
@@ -115,6 +123,26 @@ func Main() int {
log.Init(conf)
if conf.ProfileFile != "" {
// enable cpu profiling. Do NOT use q to stop the game but
// close the window to get a profile
fd, err := os.Create(conf.ProfileFile)
if err != nil {
return nil, err
}
defer func() {
if err := fd.Close(); err != nil {
golog.Fatal(err)
}
}()
if err := pprof.StartCPUProfile(fd); err != nil {
golog.Fatal(err)
}
defer pprof.StopCPUProfile()
}
return nil, nil
},
}