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"

This commit is contained in:
Neil Alexander 2018-05-27 23:22:50 +01:00
parent e9b1006dda
commit a9e61d0d37
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 31 additions and 6 deletions

View File

@ -1,3 +1,5 @@
// +build debug
package yggdrasil package yggdrasil
// These are functions that should not exist // These are functions that should not exist
@ -15,6 +17,20 @@ import "net"
import "log" import "log"
import "regexp" 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 // Core
func (c *Core) DEBUG_getSigningPublicKey() sigPubKey { func (c *Core) DEBUG_getSigningPublicKey() sigPubKey {

12
src/yggdrasil/release.go Normal file
View File

@ -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'")
}

View File

@ -11,11 +11,7 @@ import "syscall"
import "time" import "time"
import "regexp" import "regexp"
import "math/rand" import "math/rand"
import _ "net/http/pprof"
import "net/http"
import "log" import "log"
import "runtime"
import "yggdrasil" import "yggdrasil"
import "yggdrasil/config" import "yggdrasil/config"
@ -191,8 +187,9 @@ func main() {
logger := log.New(os.Stdout, "", log.Flags()) logger := log.New(os.Stdout, "", log.Flags())
// If the -pprof flag was provided then start the pprof service on port 6060. // If the -pprof flag was provided then start the pprof service on port 6060.
if *pprof { if *pprof {
runtime.SetBlockProfileRate(1) if err := yggdrasil.StartProfiler(logger); err != nil {
go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() logger.Println(err)
}
} }
// Setup the Yggdrasil node itself. The node{} type includes a Core, so we // Setup the Yggdrasil node itself. The node{} type includes a Core, so we
// don't need to create this manually. // don't need to create this manually.