on main help sign in
feat: profiling
75178a4Carlos Alexandro Becker
Taskfile.yaml+22
@@ -17,3 +17,25 @@ tasks:
17 desc: Run gofumpt
17 desc: Run gofumpt
18 cmds:
18 cmds:
19 - gofumpt -w .
19 - gofumpt -w .
20+
21+ dev:
22+ desc: Run with profiling enabled
23+ env:
24+ OPENCODE_PROFILE: true
25+ cmds:
26+ - go run .
27+
28+ profile:cpu:
29+ desc: 10s CPU profile
30+ cmds:
31+ - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/profile?seconds=10'
32+
33+ profile:heap:
34+ desc: Heap profile
35+ cmds:
36+ - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/heap'
37+
38+ profile:allocs:
39+ desc: Allocations profile
40+ cmds:
41+ - go tool pprof -http :6061 'http://localhost:6060/debug/pprof/allocs'
main.go+14
@@ -1,6 +1,11 @@
1package main
1package main
2
2
3import (
3import (
4+ "net/http"
5+ "os"
6+
7+ _ "net/http/pprof" // profiling
8+
4 "github.com/opencode-ai/opencode/cmd"
9 "github.com/opencode-ai/opencode/cmd"
5 "github.com/opencode-ai/opencode/internal/logging"
10 "github.com/opencode-ai/opencode/internal/logging"
6)
11)
@@ -10,5 +15,14 @@ func main() {
10 logging.ErrorPersist("Application terminated due to unhandled panic")
15 logging.ErrorPersist("Application terminated due to unhandled panic")
11 })
16 })
12
17
18+ if os.Getenv("OPENCODE_PROFILE") != "" {
19+ go func() {
20+ logging.Info("Serving pprof at localhost:6060")
21+ if httpErr := http.ListenAndServe("localhost:6060", nil); httpErr != nil {
22+ logging.Error("Failed to pprof listen: %v", httpErr)
23+ }
24+ }()
25+ }
26+
13 cmd.Execute()
27 cmd.Execute()
14}
28}