mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 05:04:18 +02:00
feature/add-profiler (#42)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,3 +30,5 @@ esctl
|
||||
*.sh
|
||||
*.json
|
||||
*.log
|
||||
|
||||
cpu.profile
|
||||
|
||||
7
Makefile
7
Makefile
@@ -106,5 +106,8 @@ show-versions: buildlocal
|
||||
@echo "### go version used for building:"
|
||||
@grep -m 1 go go.mod
|
||||
|
||||
# lint:
|
||||
# golangci-lint run -p bugs -p unused
|
||||
.PHONY: profile
|
||||
profile: buildlocal
|
||||
./esctl api ls --profile-file cpu.profile
|
||||
go tool pprof -text esctl cpu.profile
|
||||
go tool pprof --http localhost:8888 ./esctl cpu.profile
|
||||
|
||||
28
cmd/root.go
28
cmd/root.go
@@ -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
|
||||
},
|
||||
}
|
||||
|
||||
@@ -55,6 +55,7 @@ type Config struct {
|
||||
Clusters map[string]*Cluster
|
||||
DefaultCluster *Cluster
|
||||
HaveJQ bool // determined at runtime by ourselfes
|
||||
ProfileFile string // for internal use (golang profiling)
|
||||
|
||||
Index string // index: -i
|
||||
Failed, Partials bool // index: flags
|
||||
|
||||
Reference in New Issue
Block a user