mirror of https://github.com/hashicorp/boundary
Backport of feat(pprof): Enable pprof endpoints behind flag into release/0.19.x (#6646)
* no-op commit due to failed cherry-picking * feat(pprof): Enable pprof endpoints behind flag (#6644) --------- Co-authored-by: temp <temp@hashicorp.com> Co-authored-by: Louis Ruch <louisruch@gmail.com>pull/6658/head
parent
60a0fd2f1c
commit
95d6b8f550
@ -1,14 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
//go:build !pprof
|
||||
// +build !pprof
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
func StartPprof(_ context.Context) {
|
||||
}
|
||||
@ -1,39 +0,0 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
//go:build pprof
|
||||
// +build pprof
|
||||
|
||||
package base
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/event"
|
||||
)
|
||||
|
||||
func StartPprof(ctx context.Context) {
|
||||
const op = "base.StartPprof"
|
||||
go func() {
|
||||
const addr = "localhost:6060"
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/debug/pprof/", pprof.Index)
|
||||
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
|
||||
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
|
||||
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
|
||||
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
|
||||
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
|
||||
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
|
||||
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
|
||||
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
|
||||
mux.Handle("/debug/pprof/mutex", pprof.Handler("mutex"))
|
||||
mux.Handle("/debug/pprof/allocs", pprof.Handler("allocs"))
|
||||
event.WriteSysEvent(ctx, op, "starting pprof HTTP server", "addr", addr)
|
||||
if err := http.ListenAndServe(addr, mux); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||
event.WriteSysEvent(ctx, op, "failed to serve pprof HTTP server", "error", err.Error())
|
||||
}
|
||||
}()
|
||||
}
|
||||
Loading…
Reference in new issue