Skip to content

Commit

Permalink
Added routes in http handle for pprof (#728)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefin9898 authored May 18, 2023
1 parent 5f0ee5a commit 72f6ece
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@ package main
import (
"math/rand"
"net"
"net/http"
"net/http/pprof"
"os"
"time"

"net/http"
_ "net/http/pprof"

"github.com/accuknox/auto-policy-discovery/src/cluster"
"github.com/accuknox/auto-policy-discovery/src/config"
"github.com/accuknox/auto-policy-discovery/src/libs"
Expand Down Expand Up @@ -38,14 +37,16 @@ func init() {
log = logger.GetInstance()

//Get pprof flag
pprof := viper.GetBool("pprof")
if pprof {
if viper.GetBool("pprof") {
// Server for pprof
go func() {
log.Info().Msgf("pprof enabled on :6060\n")
r := http.NewServeMux()
r.Handle("/debug/", http.DefaultServeMux)
http.ListenAndServe(":6060", r)
http.Handle("/debug/pprof/", http.HandlerFunc(pprof.Index))
http.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
http.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
http.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
http.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace))
http.ListenAndServe(":6060", nil)
}()
}

Expand Down

0 comments on commit 72f6ece

Please sign in to comment.