Exposing pprof does not mean continuously running a CPU profiler. Import net/http/pprof and serve HTTP to make profiling endpoints available at /debug/pprof. Performance-impacting profiles are activated for a specific period rather than running by default. section 12.8.1
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof" #1
)
func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { #2
fmt.Fprintf(w, "")
})
log.Fatal(http.ListenAndServe(":80", nil))
}
The blank import registers the profiling handlers; the HTTP server makes them reachable. section 12.8.1
Choose a profile for the symptom: CPU for time spent executing, heap for allocation and possible leaks, goroutine for active stack traces, mutex for lock contention, or block for waits on synchronization primitives. Requesting /debug/pprof/profile runs CPU profiling for 30 seconds by default, sampling through OS signals every 10 ms. section 12.8.1
$ go tool pprof -http=:8080 <file>
Open a collected profile with go tool pprof to inspect its call graph. section 12.8.1

