Skip to content

Instantly share code, notes, and snippets.

@DCRichards
Created February 16, 2018 13:05
Show Gist options
  • Save DCRichards/39ed4d420d302eec46872b49883c9571 to your computer and use it in GitHub Desktop.
Save DCRichards/39ed4d420d302eec46872b49883c9571 to your computer and use it in GitHub Desktop.
Golang profiling 1
package main
import (
"log"
"net/http"
pp "net/http/pprof"
"time"
)
func main() {
mux := http.NewServeMux()
// Your existing routes here
const basePath = "/pprof"
mux.HandleFunc(basePath, pp.Index)
mux.HandleFunc(basePath+"/cmdline", pp.Cmdline)
mux.HandleFunc(basePath+"/profile", pp.Profile)
mux.HandleFunc(basePath+"/symbol", pp.Symbol)
mux.HandleFunc(basePath+"/trace", pp.Trace)
server := &http.Server{
Addr: ":80",
Handler: mux,
ReadTimeout: 10 * time.Second,
WriteTimeout: 120 * time.Second,
}
log.Fatal(server.ListenAndServe())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment