mirror of
https://github.com/Luzifer/twitch-bot.git
synced 2024-12-20 11:51:17 +00:00
[core] Add way to enable profiling
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
a336772303
commit
3c158ef231
1 changed files with 15 additions and 0 deletions
15
main.go
15
main.go
|
@ -5,6 +5,7 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -174,6 +175,20 @@ func main() {
|
||||||
router.HandleFunc("/openapi.json", handleSwaggerRequest)
|
router.HandleFunc("/openapi.json", handleSwaggerRequest)
|
||||||
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(runID)) })
|
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(runID)) })
|
||||||
|
|
||||||
|
if os.Getenv("ENABLE_PROFILING") == "true" {
|
||||||
|
router.HandleFunc("/debug/pprof/", pprof.Index)
|
||||||
|
router.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
|
||||||
|
router.Handle("/debug/pprof/block", pprof.Handler("block"))
|
||||||
|
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||||
|
router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
|
||||||
|
router.Handle("/debug/pprof/heap", pprof.Handler("heap"))
|
||||||
|
router.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
|
||||||
|
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||||
|
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||||
|
router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
|
||||||
|
router.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||||
|
}
|
||||||
|
|
||||||
router.MethodNotAllowedHandler = corsMiddleware(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
|
router.MethodNotAllowedHandler = corsMiddleware(http.HandlerFunc(func(res http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodOptions {
|
if r.Method == http.MethodOptions {
|
||||||
// Most likely JS client asking for CORS headers
|
// Most likely JS client asking for CORS headers
|
||||||
|
|
Loading…
Reference in a new issue