mirror of https://github.com/cbeuw/Cloak
Make pprof optional to halve the binary size
This commit is contained in:
parent
cb07e446b6
commit
3ee868da6d
5
Makefile
5
Makefile
|
|
@ -16,6 +16,11 @@ server:
|
||||||
go build -ldflags "-X main.version=${version}" ./cmd/ck-server
|
go build -ldflags "-X main.version=${version}" ./cmd/ck-server
|
||||||
mv ck-server* ./build
|
mv ck-server* ./build
|
||||||
|
|
||||||
|
server_pprof:
|
||||||
|
mkdir -p build
|
||||||
|
go build -ldflags "-X main.version=${version}" -tags pprof ./cmd/ck-server
|
||||||
|
mv ck-server* ./build
|
||||||
|
|
||||||
install:
|
install:
|
||||||
mv build/ck-* /usr/local/bin
|
mv build/ck-* /usr/local/bin
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,7 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
_ "net/http/pprof"
|
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -237,11 +234,7 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if *pprofAddr != "" {
|
if *pprofAddr != "" {
|
||||||
runtime.SetBlockProfileRate(5)
|
startPprof(*pprofAddr)
|
||||||
go func() {
|
|
||||||
log.Println(http.ListenAndServe(*pprofAddr, nil))
|
|
||||||
}()
|
|
||||||
log.Println("pprof listening on " + *pprofAddr)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if *localAddr == "" {
|
if *localAddr == "" {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
// +build !pprof
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "log"
|
||||||
|
|
||||||
|
func startPprof(x string) {
|
||||||
|
log.Println("pprof not available in release builds to reduce binary size")
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,18 @@
|
||||||
|
// +build pprof
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func startPprof(pprofAddr string) {
|
||||||
|
runtime.SetBlockProfileRate(5)
|
||||||
|
go func() {
|
||||||
|
log.Println(http.ListenAndServe(pprofAddr, nil))
|
||||||
|
}()
|
||||||
|
log.Println("pprof listening on " + pprofAddr)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue