From a9e61d0d3749f675965ffcfa789ae433479015b5 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 27 May 2018 23:22:50 +0100 Subject: [PATCH] Add support for building "release" builds that don't contain pprof which are substantially smaller. To build a "debug" build, use "-tags debug" with "go build" --- src/yggdrasil/debug.go | 16 ++++++++++++++++ src/yggdrasil/release.go | 12 ++++++++++++ yggdrasil.go | 9 +++------ 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/yggdrasil/release.go diff --git a/src/yggdrasil/debug.go b/src/yggdrasil/debug.go index c687162c..bbdd0f69 100644 --- a/src/yggdrasil/debug.go +++ b/src/yggdrasil/debug.go @@ -1,3 +1,5 @@ +// +build debug + package yggdrasil // These are functions that should not exist @@ -15,6 +17,20 @@ import "net" import "log" import "regexp" +import _ "net/http/pprof" +import "net/http" +import "runtime" + +// 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 +} + +//////////////////////////////////////////////////////////////////////////////// + // Core func (c *Core) DEBUG_getSigningPublicKey() sigPubKey { diff --git a/src/yggdrasil/release.go b/src/yggdrasil/release.go new file mode 100644 index 00000000..fdbe8d5f --- /dev/null +++ b/src/yggdrasil/release.go @@ -0,0 +1,12 @@ +// +build !debug + +package yggdrasil + +import "errors" +import "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'") +} diff --git a/yggdrasil.go b/yggdrasil.go index af6fc023..1fef8ac7 100644 --- a/yggdrasil.go +++ b/yggdrasil.go @@ -11,11 +11,7 @@ import "syscall" import "time" import "regexp" import "math/rand" - -import _ "net/http/pprof" -import "net/http" import "log" -import "runtime" import "yggdrasil" import "yggdrasil/config" @@ -191,8 +187,9 @@ func main() { logger := log.New(os.Stdout, "", log.Flags()) // If the -pprof flag was provided then start the pprof service on port 6060. if *pprof { - runtime.SetBlockProfileRate(1) - go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() + 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.