-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
pprof.go
40 lines (34 loc) · 831 Bytes
/
pprof.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2020 Jorge Luis Betancourt. All rights reserved.
// Use of this source code is governed by the Apache License, Version 2.0
// that can be found in the LICENSE file.
package main
import (
"net/http"
"net/http/pprof"
"strings"
)
const (
pprofPath = "/debug/pprof/"
)
// RegisterDebugHandler registers the pprof handler with the given http mux.
func RegisterDebugHandler(mux *http.ServeMux) {
mux.Handle(pprofPath, handler())
}
func handler() http.Handler {
h := func(w http.ResponseWriter, r *http.Request) {
name := strings.TrimPrefix(r.URL.Path, pprofPath)
switch name {
case "cmdline":
pprof.Cmdline(w, r)
case "profile":
pprof.Profile(w, r)
case "symbol":
pprof.Symbol(w, r)
case "trace":
pprof.Trace(w, r)
default:
pprof.Index(w, r)
}
}
return http.HandlerFunc(h)
}