From b8c456ef66310a7f658e01f58d0f2132aca263c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Fri, 20 Nov 2020 14:22:58 +0100 Subject: [PATCH] Merge pull request #4140 from filecoin-project/feat/mutex-fraction Add options to set BlockProfileRate and MutexProfileFraction --- cmd/epik/pprof.go | 33 +++++++++++++++++++++++++++++++++ cmd/epik/rpc.go | 5 +++++ 2 files changed, 38 insertions(+) create mode 100644 cmd/epik/pprof.go diff --git a/cmd/epik/pprof.go b/cmd/epik/pprof.go new file mode 100644 index 0000000000..ea6823e48e --- /dev/null +++ b/cmd/epik/pprof.go @@ -0,0 +1,33 @@ +package main + +import ( + "net/http" + "strconv" +) + +func handleFractionOpt(name string, setter func(int)) http.HandlerFunc { + return func(rw http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Error(rw, "only POST allowed", http.StatusMethodNotAllowed) + return + } + if err := r.ParseForm(); err != nil { + http.Error(rw, err.Error(), http.StatusBadRequest) + return + } + + asfr := r.Form.Get("x") + if len(asfr) == 0 { + http.Error(rw, "parameter 'x' must be set", http.StatusBadRequest) + return + } + + fr, err := strconv.Atoi(asfr) + if err != nil { + http.Error(rw, err.Error(), http.StatusBadRequest) + return + } + log.Infof("setting %s to %d", name, fr) + setter(fr) + } +} diff --git a/cmd/epik/rpc.go b/cmd/epik/rpc.go index dd619764f7..bdfe3d089e 100644 --- a/cmd/epik/rpc.go +++ b/cmd/epik/rpc.go @@ -8,6 +8,7 @@ import ( _ "net/http/pprof" "os" "os/signal" + "runtime" "syscall" "github.com/ipfs/go-cid" @@ -67,6 +68,10 @@ func serveRPC(a api.FullNode, stop node.StopFunc, addr multiaddr.Multiaddr, shut } http.Handle("/debug/metrics", exporter) + http.Handle("/debug/pprof-set/block", handleFractionOpt("BlockProfileRate", runtime.SetBlockProfileRate)) + http.Handle("/debug/pprof-set/mutex", handleFractionOpt("MutexProfileFraction", + func(x int) { runtime.SetMutexProfileFraction(x) }, + )) lst, err := manet.Listen(addr) if err != nil {