5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2025-01-11 11:55:41 +00:00
yggdrasil-go/src/core/debug.go

22 lines
467 B
Go
Raw Normal View History

2021-05-23 19:42:26 +00:00
package core
2017-12-29 04:16:20 +00:00
2022-04-17 17:02:25 +00:00
import (
"fmt"
"net/http"
_ "net/http/pprof"
"os"
)
2019-01-27 13:33:32 +00:00
2023-10-21 20:36:28 +00:00
// Start the profiler if the required environment variable is set.
func init() {
envVarName := "PPROFLISTEN"
hostPort := os.Getenv(envVarName)
switch {
case hostPort == "":
fmt.Fprintf(os.Stderr, "DEBUG: %s not set, profiler not started.\n", envVarName)
default:
fmt.Fprintf(os.Stderr, "DEBUG: Starting pprof on %s\n", hostPort)
2023-10-21 20:36:28 +00:00
go fmt.Println(http.ListenAndServe(hostPort, nil))
}
}