git » firstones » commit e564b02

pprof: Add optional http pprof support (enabled via build tag)

author Alberto Bertogli
2026-07-26 12:19:32 UTC
committer Alberto Bertogli
2026-07-26 12:19:32 UTC
parent 8312872ae4449efcb1067e4b00d50206faa41881

pprof: Add optional http pprof support (enabled via build tag)

Running with http pprof enabled can be useful to debug performance
issues while developing.

This patch adds that, gated behind a build tag.

It should not be used in production.

pprof.go +22 -0

diff --git a/pprof.go b/pprof.go
new file mode 100644
index 0000000..18eb996
--- /dev/null
+++ b/pprof.go
@@ -0,0 +1,22 @@
+// This file enables http pprof support. It's only used when the pprof build
+// tag is specified.
+//
+// To build:
+//   go build -tags pprof
+// Run as normal:
+//   ./firstones http :9595
+// CPU profile:
+//   go tool pprof -http localhost:9400 -no_browser 'http://localhost:9595/debug/pprof/profile?debug=1&seconds=60'
+
+//go:build pprof
+
+package main
+
+import (
+	"fmt"
+	_ "net/http/pprof"
+)
+
+func init() {
+	fmt.Println("pprof enabled")
+}