Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added config option to enable pprof #253

Merged
merged 2 commits into from
Mar 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ LDFLAGS = -ldflags "-w -s"
GCTPKG = github.com/thrasher-/gocryptotrader
LINTPKG = github.com/golangci/golangci-lint/cmd/[email protected]
LINTBIN = $(GOPATH)/bin/golangci-lint
GCTLISTENPORT=9050
GCTPROFILERLISTENPORT=8085

get:
GO111MODULE=on go get $(GCTPKG)
Expand Down Expand Up @@ -29,4 +31,12 @@ update_deps:
GO111MODULE=on go mod verify
GO111MODULE=on go mod tidy
rm -rf vendor
GO111MODULE=on go mod vendor
GO111MODULE=on go mod vendor

.PHONY: profile_heap
profile_heap:
go tool pprof -http "localhost:$(GCTPROFILERLISTENPORT)" 'http://localhost:$(GCTLISTENPORT)/debug/pprof/heap'

.PHONY: profile_cpu
profile_cpu:
go tool pprof -http "localhost:$(GCTPROFILERLISTENPORT)" 'http://localhost:$(GCTLISTENPORT)/debug/pprof/profile'
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ type Config struct {
EncryptConfig int `json:"encryptConfig"`
GlobalHTTPTimeout time.Duration `json:"globalHTTPTimeout"`
Logging log.Logging `json:"logging"`
Profiler ProfilerConfig `json:"profiler"`
Currency CurrencyConfig `json:"currencyConfig"`
Communications CommunicationsConfig `json:"communications"`
Portfolio portfolio.Base `json:"portfolioAddresses"`
Expand All @@ -118,6 +119,10 @@ type Config struct {
SMS *SMSGlobalConfig `json:"smsGlobal,omitempty"`
}

type ProfilerConfig struct {
Enabled bool `json:"enabled"`
}

// ExchangeConfig holds all the information needed for each enabled Exchange.
type ExchangeConfig struct {
Name string `json:"name"`
Expand Down
3 changes: 3 additions & 0 deletions config_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"level": "DEBUG|WARN|INFO|ERROR|FATAL",
"rotate": false
},
"profiler": {
"enabled": false
},
"currencyConfig": {
"forexProviders": [
{
Expand Down
8 changes: 8 additions & 0 deletions restful_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (

"github.com/gorilla/mux"
log "github.com/thrasher-/gocryptotrader/logger"

_ "net/http/pprof"
)

// RESTLogger logs the requests internally
Expand Down Expand Up @@ -114,6 +116,12 @@ func NewRouter() *mux.Router {
Name(route.Name).
Handler(RESTLogger(route.HandlerFunc, route.Name))
}

if bot.config.Profiler.Enabled {
log.Debugln("Profiler enabled")
router.PathPrefix("/debug").Handler(http.DefaultServeMux)
}

return router
}

Expand Down
3 changes: 3 additions & 0 deletions testdata/configtest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
"level": "DEBUG|WARN|INFO|ERROR|FATAL",
"rotate": true
},
"profiler": {
"enabled": false
},
"currencyConfig": {
"forexProviders": [
{
Expand Down