mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-12-23 08:45:39 +00:00
Allow PPROFLISTEN
on all builds
This commit is contained in:
parent
6a9493757d
commit
80e56eafcd
@ -1,6 +1,3 @@
|
|||||||
//go:build debug
|
|
||||||
// +build debug
|
|
||||||
|
|
||||||
package core
|
package core
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -8,12 +5,9 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
|
|
||||||
"github.com/gologme/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Start the profiler in debug builds, if the required environment variable is set.
|
// Start the profiler if the required environment variable is set.
|
||||||
func init() {
|
func init() {
|
||||||
envVarName := "PPROFLISTEN"
|
envVarName := "PPROFLISTEN"
|
||||||
hostPort := os.Getenv(envVarName)
|
hostPort := os.Getenv(envVarName)
|
||||||
@ -22,14 +16,6 @@ func init() {
|
|||||||
fmt.Fprintf(os.Stderr, "DEBUG: %s not set, profiler not started.\n", envVarName)
|
fmt.Fprintf(os.Stderr, "DEBUG: %s not set, profiler not started.\n", envVarName)
|
||||||
default:
|
default:
|
||||||
fmt.Fprintf(os.Stderr, "DEBUG: Starting pprof on %s\n", hostPort)
|
fmt.Fprintf(os.Stderr, "DEBUG: Starting pprof on %s\n", hostPort)
|
||||||
go func() { fmt.Println(http.ListenAndServe(hostPort, nil)) }()
|
go fmt.Println(http.ListenAndServe(hostPort, nil))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starts the function profiler. This is only supported when built with
|
|
||||||
// '-tags build'.
|
|
||||||
func StartProfiler(log *log.Logger) error {
|
|
||||||
runtime.SetBlockProfileRate(1)
|
|
||||||
go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }()
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user