From 7e0cf2c383fbdb5ee749df80c4896db68860c967 Mon Sep 17 00:00:00 2001 From: Vladislav Byrgazov <58589910+Ex4amp1e@users.noreply.github.com> Date: Mon, 12 Aug 2024 15:39:52 +0500 Subject: [PATCH] Update sdk/pkg/tools/pprofutils (#1657) * Updated pprof naming and method signature Signed-off-by: Vladislav Byrgazov * Update listenOn param type from URL to string Signed-off-by: Vladislav Byrgazov --------- Signed-off-by: Vladislav Byrgazov Co-authored-by: Vladislav Byrgazov --- .../{pprof/pprof.go => pprofutils/pprofutils.go} | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) rename pkg/tools/{pprof/pprof.go => pprofutils/pprofutils.go} (88%) diff --git a/pkg/tools/pprof/pprof.go b/pkg/tools/pprofutils/pprofutils.go similarity index 88% rename from pkg/tools/pprof/pprof.go rename to pkg/tools/pprofutils/pprofutils.go index 9adc18ecc..cbc23251e 100644 --- a/pkg/tools/pprof/pprof.go +++ b/pkg/tools/pprofutils/pprofutils.go @@ -14,12 +14,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package pprof provides ability to enable pprof if required -package pprof +// Package pprofutils provides ability to enable pprof if required +package pprofutils import ( "context" - "fmt" "net/http" "net/http/pprof" "time" @@ -27,9 +26,9 @@ import ( "github.com/networkservicemesh/sdk/pkg/tools/log" ) -// Init - configures pprof http handlers -func Init(ctx context.Context, port uint16) { - log.FromContext(ctx).Infof("Profiler is enabled. Listening on %d", port) +// ListenAndServe - configures pprof http handlers +func ListenAndServe(ctx context.Context, listenOn string) { + log.FromContext(ctx).Infof("Profiler is enabled. Listening on %s", listenOn) mux := http.NewServeMux() mux.HandleFunc("/debug/pprof/", pprof.Index) mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) @@ -43,7 +42,7 @@ func Init(ctx context.Context, port uint16) { mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex")) mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate")) server := &http.Server{ - Addr: fmt.Sprintf("localhost:%d", port), + Addr: listenOn, Handler: mux, ReadTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second,