diff options
| author | 2026-03-08 13:03:55 +0800 | |
|---|---|---|
| committer | 2026-03-08 13:03:55 +0800 | |
| commit | 0bf0a124641dc5f7594b65a3991a43f0ecc07ddb (patch) | |
| tree | 586012a23f65e761caf3284e2e141d91017835d3 /cmd/receivepack9418/main.go | |
| parent | TODO: Improve delta resolution perf (diff) | |
| signature | No signature | |
cmd/receivepack9418: Profile
Diffstat (limited to 'cmd/receivepack9418/main.go')
| -rw-r--r-- | cmd/receivepack9418/main.go | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/cmd/receivepack9418/main.go b/cmd/receivepack9418/main.go index 377bf7d4..6884f326 100644 --- a/cmd/receivepack9418/main.go +++ b/cmd/receivepack9418/main.go @@ -4,20 +4,58 @@ package main import ( "flag" "log" + "os" ) func main() { + os.Exit(runMain()) +} + +func runMain() int { listenAddr := flag.String("listen", ":9418", "listen address") repoPath := flag.String("repo", "", "path to git dir (.git or bare repo root)") + cpuProfilePath := flag.String("cpuprofile", "", "write CPU profile to file") + memProfilePath := flag.String("memprofile", "", "write heap profile to file at exit") flag.Parse() if *repoPath == "" { - log.Fatal("must provide -repo <path-to-git-dir>") + log.Print("must provide -repo <path-to-git-dir>") + + return 2 + } + + if *cpuProfilePath != "" { + stopCPUProfile, err := startCPUProfile(*cpuProfilePath) + if err != nil { + log.Printf("cpuprofile: %v", err) + + return 1 + } + + defer func() { + stopErr := stopCPUProfile() + if stopErr != nil { + log.Printf("cpuprofile: %v", stopErr) + } + }() + } + + if *memProfilePath != "" { + defer func() { + memErr := writeMemProfile(*memProfilePath) + if memErr != nil { + log.Printf("memprofile: %v", memErr) + } + }() } err := run(*listenAddr, *repoPath) if err != nil { - log.Fatalf("run: %v", err) + log.Printf("run: %v", err) + + return 1 } + + return 0 } |
