on main help sign in
Merge pull request #19 from charmbracelet/profile

feat: profiling

commit54196417ec0d36f3c118e880a412570de8a54d21 authorKujtim Hoxha <kujtimii.h@gmail.com> dateSat 7 Jun 2025, 20:48 (1 year ago) parente74dddb25c6007
2 files changed+36
Taskfile.yaml+22 main.go+14
Taskfile.yaml+22
@@ -17,3 +17,25 @@ tasks:
1717 desc: Run gofumpt
1818 cmds:
1919 - gofumpt -w .
20+
21+ dev:
22+ desc: Run with profiling enabled
23+ env:
24+ CRUSH_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 @@
11package main
22
33import (
4+ "net/http"
5+ "os"
6+
7+ _ "net/http/pprof" // profiling
8+
49 "github.com/opencode-ai/opencode/cmd"
510 "github.com/opencode-ai/opencode/internal/logging"
611)
@@ -10,5 +15,14 @@ func main() {
1015 logging.ErrorPersist("Application terminated due to unhandled panic")
1116 })
1217
18+ if os.Getenv("CRUSH_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+
1327 cmd.Execute()
1428}