pprof.go 793 B

12345678910111213141516171819202122232425262728293031323334
  1. package debug
  2. import (
  3. "log"
  4. "net/http"
  5. "net/http/pprof"
  6. //"runtime/pprof"
  7. )
  8. type mode int
  9. const (
  10. // ModeProd 生产模式
  11. ModeProd mode = 1
  12. // ModeDev 开发模式
  13. ModeDev mode = 0
  14. )
  15. // Mode 运行模式
  16. var Mode = ModeDev
  17. // StartHTTPPprof
  18. func StartHTTPPprof(debugaddr string) {
  19. debugServeMux := http.NewServeMux()
  20. debugServeMux.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
  21. debugServeMux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
  22. debugServeMux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
  23. debugServeMux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
  24. debugServeMux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
  25. go func() {
  26. log.Fatal(http.ListenAndServe(debugaddr, debugServeMux))
  27. }()
  28. }