mirror of
https://codeberg.org/scip/esctl.git
synced 2026-08-24 06:34:18 +02:00
feature/add-profiler (#42)
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,3 +30,5 @@ esctl
|
|||||||
*.sh
|
*.sh
|
||||||
*.json
|
*.json
|
||||||
*.log
|
*.log
|
||||||
|
|
||||||
|
cpu.profile
|
||||||
|
|||||||
7
Makefile
7
Makefile
@@ -106,5 +106,8 @@ show-versions: buildlocal
|
|||||||
@echo "### go version used for building:"
|
@echo "### go version used for building:"
|
||||||
@grep -m 1 go go.mod
|
@grep -m 1 go go.mod
|
||||||
|
|
||||||
# lint:
|
.PHONY: profile
|
||||||
# golangci-lint run -p bugs -p unused
|
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 (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
golog "log"
|
||||||
"os"
|
"os"
|
||||||
|
"runtime/pprof"
|
||||||
|
|
||||||
"codeberg.org/scip/esctl/pkg/cfg"
|
"codeberg.org/scip/esctl/pkg/cfg"
|
||||||
"codeberg.org/scip/esctl/pkg/es"
|
"codeberg.org/scip/esctl/pkg/es"
|
||||||
@@ -83,6 +85,12 @@ func Main() int {
|
|||||||
Usage: "output mode (tsv, markdown, json, yaml) default: tsv",
|
Usage: "output mode (tsv, markdown, json, yaml) default: tsv",
|
||||||
Destination: &conf.Output,
|
Destination: &conf.Output,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "profile-file",
|
||||||
|
Usage: "golang profiler output file",
|
||||||
|
Destination: &conf.ProfileFile,
|
||||||
|
Hidden: true,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
Commands: []*cli.Command{
|
Commands: []*cli.Command{
|
||||||
@@ -115,6 +123,26 @@ func Main() int {
|
|||||||
|
|
||||||
log.Init(conf)
|
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
|
return nil, nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,8 @@ type Config struct {
|
|||||||
Output string // -o <mode>
|
Output string // -o <mode>
|
||||||
Clusters map[string]*Cluster
|
Clusters map[string]*Cluster
|
||||||
DefaultCluster *Cluster
|
DefaultCluster *Cluster
|
||||||
HaveJQ bool // determined at runtime by ourselfes
|
HaveJQ bool // determined at runtime by ourselfes
|
||||||
|
ProfileFile string // for internal use (golang profiling)
|
||||||
|
|
||||||
Index string // index: -i
|
Index string // index: -i
|
||||||
Failed, Partials bool // index: flags
|
Failed, Partials bool // index: flags
|
||||||
|
|||||||
Reference in New Issue
Block a user