Skip to content

Commit

Permalink
Merge pull request filecoin-project#4140 from filecoin-project/feat/m…
Browse files Browse the repository at this point in the history
…utex-fraction

Add options to set BlockProfileRate and MutexProfileFraction
  • Loading branch information
magik6k authored and bibibong committed Jan 7, 2021
1 parent b2a05e0 commit b8c456e
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cmd/epik/pprof.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
5 changes: 5 additions & 0 deletions cmd/epik/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
_ "net/http/pprof"
"os"
"os/signal"
"runtime"
"syscall"

"github.com/ipfs/go-cid"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b8c456e

Please sign in to comment.