From b87642b5b2a4c1c305ad32b72b5bec8f769e1a01 Mon Sep 17 00:00:00 2001 From: Egor Aristov Date: Fri, 21 Mar 2025 13:28:50 +0300 Subject: [PATCH] use profiler --- .gitignore | 1 + cmd/extractor/extractor.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index ea6ad7d..12225c5 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ node_modules .vite *~ +*.prof diff --git a/cmd/extractor/extractor.go b/cmd/extractor/extractor.go index e6d4cba..7597325 100644 --- a/cmd/extractor/extractor.go +++ b/cmd/extractor/extractor.go @@ -13,6 +13,7 @@ import ( "github.com/labstack/gommon/log" "io" "os" + "runtime/pprof" "time" ) @@ -22,8 +23,21 @@ func main() { outFile := flag.String("o", "", "Output file name") skipOutput := flag.Bool("s", false, "Skip json output; show just logs") + useProfiler := flag.Bool("p", false, "Use profiler") 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" if flag.NArg() > 0 { taskFileName = flag.Arg(0)