Skip to content

Commit

Permalink
configure mutex and block profile rates
Browse files Browse the repository at this point in the history
  • Loading branch information
mastercactapus committed Feb 15, 2024
1 parent a66a44a commit 629eddc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ func init() {

RootCmd.PersistentFlags().StringP("listen-prometheus", "p", "", "Bind address for Prometheus metrics.")
RootCmd.PersistentFlags().String("listen-pprof", "", "Bind address for pprof.")
RootCmd.PersistentFlags().Int("pprof-block-profile-rate", 0, "Set the block profile rate in hz.")
RootCmd.PersistentFlags().Int("pprof-mutex-profile-fraction", 0, "Set the mutex profile fraction (rate is 1/this-value).")

RootCmd.Flags().String("tls-cert-file", "", "Specifies a path to a PEM-encoded certificate. Has no effect if --listen-tls is unset.")
RootCmd.Flags().String("tls-key-file", "", "Specifies a path to a PEM-encoded private key file. Has no effect if --listen-tls is unset.")
Expand Down
4 changes: 4 additions & 0 deletions app/pprof.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"
"net/http"
"net/http/pprof"
"runtime"

"github.com/spf13/viper"
)
Expand All @@ -28,6 +29,9 @@ func initPprofServer() error {
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)

runtime.SetBlockProfileRate(viper.GetInt("pprof-block-profile-rate"))
runtime.SetMutexProfileFraction(viper.GetInt("pprof-mutex-profile-fraction"))

srv := http.Server{
Handler: mux,
}
Expand Down

0 comments on commit 629eddc

Please sign in to comment.