Skip to content

Commit

Permalink
add block/mutex profile
Browse files Browse the repository at this point in the history
  • Loading branch information
mazrean committed Mar 4, 2023
1 parent 850fba3 commit b97c321
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"log"
"net/http"
"os"
"runtime"
"strconv"

_ "net/http/pprof"

Expand All @@ -22,6 +24,26 @@ func init() {
addr = ":6060"
}

strBlockRate, ok := os.LookupEnv("BLOCK_RATE")
if ok {
blockRate, err := strconv.Atoi(strBlockRate)
if err != nil {
log.Printf("failed to parse BLOCK_RATE(%s): %v", strBlockRate, err)
} else {
runtime.SetBlockProfileRate(blockRate)
}
}

strMutexRate, ok := os.LookupEnv("MUTEX_RATE")
if ok {
mutexRate, err := strconv.Atoi(strMutexRate)
if err != nil {
log.Printf("failed to parse MUTEX_RATE(%s): %v", strMutexRate, err)
} else {
runtime.SetMutexProfileFraction(mutexRate)
}
}

http.Handle("/metrics", promhttp.Handler())
http.Handle("/debug/fgprof", fgprof.Handler())

Expand Down

0 comments on commit b97c321

Please sign in to comment.