Skip to content

Commit

Permalink
tools: support profiling simulator (#5674)
Browse files Browse the repository at this point in the history
ref #5468

Signed-off-by: Ryan Leung <rleungx@gmail.com>
  • Loading branch information
rleungx committed Nov 3, 2022
1 parent 20efeca commit 6f0fb32
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tools/pd-simulator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"fmt"
"net/http"
"net/http/pprof"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -97,7 +98,7 @@ func main() {

func run(simCase string, simConfig *simulator.SimConfig) {
if *pdAddr != "" {
go runMetrics()
go runHTTPServer()
simStart(*pdAddr, simCase, simConfig)
} else {
local, clean := NewSingleServer(context.Background(), simConfig)
Expand All @@ -115,8 +116,17 @@ func run(simCase string, simConfig *simulator.SimConfig) {
}
}

func runMetrics() {
func runHTTPServer() {
http.Handle("/metrics", promhttp.Handler())
// profile API
http.HandleFunc("/pprof/profile", pprof.Profile)
http.HandleFunc("/pprof/trace", pprof.Trace)
http.HandleFunc("/pprof/symbol", pprof.Symbol)
http.Handle("/pprof/heap", pprof.Handler("heap"))
http.Handle("/pprof/mutex", pprof.Handler("mutex"))
http.Handle("/pprof/allocs", pprof.Handler("allocs"))
http.Handle("/pprof/block", pprof.Handler("block"))
http.Handle("/pprof/goroutine", pprof.Handler("goroutine"))
// nolint
http.ListenAndServe(*statusAddress, nil)
}
Expand Down

0 comments on commit 6f0fb32

Please sign in to comment.