signal/grpc: ability to pprof the server
Thanks !
@@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
+ _ "net/http/pprof"
"os"
"github.com/pion/ion-sfu/pkg/middlewares/datachannel"
@@ -37,6 +38,8 @@ var (
addr string
metricsAddr string
verbosityLevel int
+ paddr string
+
logger = log.New()
)
@@ -50,6 +53,7 @@ func showHelp() {
fmt.Println(" -a {listen addr}")
fmt.Println(" -h (show help info)")
fmt.Println(" -v {0-10} (verbosity level, default 0)")
+ fmt.Println(" -paddr {pprof listen addr}")
}
@@ -97,8 +101,14 @@ func parse() bool {
flag.StringVar(&addr, "a", ":50051", "address to use")
flag.StringVar(&metricsAddr, "m", ":8100", "merics to use")
flag.IntVar(&verbosityLevel, "v", -1, "verbosity level, higher value - more logs")
+ flag.StringVar(&paddr, "paddr", "", "pprof listening address")
help := flag.Bool("h", false, "help info")
flag.Parse()
+
+ if paddr == "" {
+ paddr = getEnv("paddr")
+ }
+
if !load() {
return false
}
@@ -109,6 +119,14 @@ func parse() bool {
return true
}
+func getEnv(key string) string {
+ if value, exists := os.LookupEnv(key); exists {
+ return value
+ }
+
+ return ""
+}
+
func startMetrics(addr string) {
// start metrics server
m := http.NewServeMux()
@@ -151,6 +169,13 @@ func main() {
os.Exit(1)
}
+ if paddr != "" {
+ go func() {
+ logger.Info("PProf Listening", "addr", paddr)
+ _ = http.ListenAndServe(paddr, http.DefaultServeMux)
+ }()
+ }
+
s := grpc.NewServer(
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
)
