use profiler

This commit is contained in:
Egor Aristov 2025-03-21 13:28:50 +03:00
parent 0d787c90cb
commit b87642b5b2
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
2 changed files with 15 additions and 0 deletions

1
.gitignore vendored
View File

@ -9,3 +9,4 @@
node_modules node_modules
.vite .vite
*~ *~
*.prof

View File

@ -13,6 +13,7 @@ import (
"github.com/labstack/gommon/log" "github.com/labstack/gommon/log"
"io" "io"
"os" "os"
"runtime/pprof"
"time" "time"
) )
@ -22,8 +23,21 @@ func main() {
outFile := flag.String("o", "", "Output file name") outFile := flag.String("o", "", "Output file name")
skipOutput := flag.Bool("s", false, "Skip json output; show just logs") skipOutput := flag.Bool("s", false, "Skip json output; show just logs")
useProfiler := flag.Bool("p", false, "Use profiler")
flag.Parse() flag.Parse()
if *useProfiler {
profFile, err := os.Create("cpu.prof")
if err != nil {
log.Fatalf("Profile create file: %v", err)
}
defer profFile.Close()
if err := pprof.StartCPUProfile(profFile); err != nil {
log.Fatalf("Start CPU profile: %v", err)
}
defer pprof.StopCPUProfile()
}
taskFileName := "task.json" taskFileName := "task.json"
if flag.NArg() > 0 { if flag.NArg() > 0 {
taskFileName = flag.Arg(0) taskFileName = flag.Arg(0)