Skip to content

Commit

Permalink
feat: add Profiling support
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyag authored and CarlJi committed Jun 15, 2024
1 parent 6e2f76e commit 25e42d0
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ package main

import (
"errors"
"expvar"
"flag"
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"

"github.com/google/go-github/v57/github"
Expand Down Expand Up @@ -142,6 +145,22 @@ func main() {
mux.Handle("/metrics", promhttp.Handler())
log.Infof("listening on port %d", o.port)

debugMux := http.NewServeMux()
debugMux.HandleFunc("/debug/pprof/", pprof.Index)
debugMux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
debugMux.HandleFunc("/debug/pprof/profile", pprof.Profile)
debugMux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
debugMux.HandleFunc("/debug/pprof/trace", pprof.Trace)
debugMux.Handle("/debug/vars", http.HandlerFunc(expvar.Handler().ServeHTTP))
listener, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
log.Fatalf("failed to listen: %v\n", err)
}
defer listener.Close()
log.Infof("debug port running in: %s\n", listener.Addr().String())
go func() {
log.Fatal(http.Serve(listener, debugMux))
}()
// TODO(CarlJi): graceful shutdown
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", o.port), mux))
}

0 comments on commit 25e42d0

Please sign in to comment.