Skip to content

Commit

Permalink
Update sdk/pkg/tools/pprofutils (#1657)
Browse files Browse the repository at this point in the history
* Updated pprof naming and method signature

Signed-off-by: Vladislav Byrgazov <[email protected]>

* Update listenOn param type from URL to string

Signed-off-by: Vladislav Byrgazov <[email protected]>

---------

Signed-off-by: Vladislav Byrgazov <[email protected]>
Co-authored-by: Vladislav Byrgazov <[email protected]>
  • Loading branch information
Ex4amp1e and Vladislav Byrgazov authored Aug 12, 2024
1 parent ce2c8f5 commit 7e0cf2c
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions pkg/tools/pprof/pprof.go → pkg/tools/pprofutils/pprofutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,21 @@
// 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"

"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)
Expand All @@ -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,
Expand Down

0 comments on commit 7e0cf2c

Please sign in to comment.