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 <vladislav.byrgazov@xored.com>

* Update listenOn param type from URL to string

Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>

---------

Signed-off-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
Co-authored-by: Vladislav Byrgazov <vladislav.byrgazov@xored.com>
  • Loading branch information
2 people authored and denis-tingaikin committed Sep 17, 2024
1 parent 9fc1b18 commit b2ac358
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 b2ac358

Please sign in to comment.