From 629eddc7751593af1784b91410b594bd5b5a3972 Mon Sep 17 00:00:00 2001 From: Nathaniel Caza Date: Thu, 15 Feb 2024 09:51:14 -0600 Subject: [PATCH] configure mutex and block profile rates --- app/cmd.go | 2 ++ app/pprof.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/app/cmd.go b/app/cmd.go index e5086cee5b..3d67d3e418 100644 --- a/app/cmd.go +++ b/app/cmd.go @@ -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.") diff --git a/app/pprof.go b/app/pprof.go index e7d3c74548..e87a2f0a06 100644 --- a/app/pprof.go +++ b/app/pprof.go @@ -4,6 +4,7 @@ import ( "net" "net/http" "net/http/pprof" + "runtime" "github.com/spf13/viper" ) @@ -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, }