mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-10 02:50:27 +00:00
start the pprof based on an env variable in debug builds, otherwise remove the flag/release.go stuff
This commit is contained in:
parent
7a19507665
commit
f599a1a2c1
@ -20,6 +20,20 @@ import "regexp"
|
||||
import _ "net/http/pprof"
|
||||
import "net/http"
|
||||
import "runtime"
|
||||
import "os"
|
||||
|
||||
// Start the profiler in debug builds, if the required environment variable is set.
|
||||
func init() {
|
||||
envVarName := "PPROFLISTEN"
|
||||
hostPort := os.Getenv(envVarName)
|
||||
switch {
|
||||
case hostPort == "":
|
||||
fmt.Printf("DEBUG: %s not set, profiler not started.\n", envVarName)
|
||||
default:
|
||||
fmt.Printf("DEBUG: Starting pprof on %s\n", hostPort)
|
||||
go func() { fmt.Println(http.ListenAndServe(hostPort, nil)) }()
|
||||
}
|
||||
}
|
||||
|
||||
// Starts the function profiler. This is only supported when built with
|
||||
// '-tags build'.
|
||||
|
@ -1,14 +0,0 @@
|
||||
// +build !debug
|
||||
|
||||
package yggdrasil
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"log"
|
||||
)
|
||||
|
||||
// Starts the function profiler. This is only supported when built with
|
||||
// '-tags build'.
|
||||
func StartProfiler(_ *log.Logger) error {
|
||||
return errors.New("Release builds do not support -pprof, build using '-tags debug'")
|
||||
}
|
@ -82,7 +82,6 @@ func doGenconf() string {
|
||||
// The main function is responsible for configuring and starting Yggdrasil.
|
||||
func main() {
|
||||
// Configure the command line parameters.
|
||||
pprof := flag.Bool("pprof", false, "Run pprof, see http://localhost:6060/debug/pprof/")
|
||||
genconf := flag.Bool("genconf", false, "print a new config to stdout")
|
||||
useconf := flag.Bool("useconf", false, "read config from stdin")
|
||||
useconffile := flag.String("useconffile", "", "read config from specified file path")
|
||||
@ -203,12 +202,6 @@ func main() {
|
||||
}
|
||||
// Create a new logger that logs output to stdout.
|
||||
logger := log.New(os.Stdout, "", log.Flags())
|
||||
// If the -pprof flag was provided then start the pprof service on port 6060.
|
||||
if *pprof {
|
||||
if err := yggdrasil.StartProfiler(logger); err != nil {
|
||||
logger.Println(err)
|
||||
}
|
||||
}
|
||||
// Setup the Yggdrasil node itself. The node{} type includes a Core, so we
|
||||
// don't need to create this manually.
|
||||
n := node{}
|
||||
|
Loading…
Reference in New Issue
Block a user