Skip to content

Commit

Permalink
Added switches for verbosity and pprof profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrz1 committed Sep 25, 2022
1 parent c9aa085 commit bd1fb04
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 7 deletions.
6 changes: 2 additions & 4 deletions code/go/0chain.net/chaincore/transaction/entity.go
@@ -1,6 +1,7 @@
package transaction

import (
"0chain.net/core/viper"
"context"
"errors"
"fmt"
Expand Down Expand Up @@ -412,10 +413,7 @@ func (t *Transaction) GetSummary() *TransactionSummary {
- applicable only when running in test mode and the transaction_data string contains debug keyword somewhere in it
*/
func (t *Transaction) DebugTxn() bool {
if !config.Development() {
return false
}
return strings.Contains(t.TransactionData, "debug")
return config.Development() && viper.GetBool("logging.verbose")
}

/*ComputeOutputHash - compute the hash from the transaction output */
Expand Down
35 changes: 34 additions & 1 deletion code/go/0chain.net/miner/miner/main.go
Expand Up @@ -7,7 +7,7 @@ import (
"flag"
"fmt"
"net/http"
_ "net/http/pprof"
"net/http/pprof"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -204,7 +204,28 @@ func main() {
initIntegrationsTests(node.Self.Underlying().GetKey())

var server *http.Server
var profServer *http.Server

mux := http.NewServeMux()
http.DefaultServeMux = mux

if config.Development() {
if viper.GetBool("development.pprof") {
// start pprof server
pprofMux := http.NewServeMux()
profServer = &http.Server{
Addr: fmt.Sprintf(":%d", node.Self.Underlying().Port+10),
ReadTimeout: 30 * time.Second,
MaxHeaderBytes: 1 << 20,
Handler: pprofMux,
}
initProfHandlers(pprofMux)
go func() {
err2 := profServer.ListenAndServe()
logging.Logger.Info("Http server shut down", zap.Error(err2))
}()
}

// No WriteTimeout setup to enable pprof
server = &http.Server{
Addr: address,
Expand Down Expand Up @@ -328,6 +349,10 @@ func main() {
}

shutdown := common.HandleShutdown(server, []func(){shutdownIntegrationTests, done, chain.CloseStateDB})
if profServer != nil {
shutdownProf := common.HandleShutdown(profServer, nil)
<-shutdownProf
}
<-shutdown
time.Sleep(2 * time.Second)
logging.Logger.Info("0chain miner shut down gracefully")
Expand Down Expand Up @@ -464,3 +489,11 @@ func initWorkers(ctx context.Context) {
//miner.SetupWorkers(ctx)
transaction.SetupWorkers(ctx)
}

func initProfHandlers(mux *http.ServeMux) {
mux.HandleFunc("/debug/pprof/", pprof.Index)
mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
}
9 changes: 7 additions & 2 deletions code/go/0chain.net/smartcontract/dbs/postgresql/postresql.go
@@ -1,6 +1,7 @@
package postgresql

import (
"0chain.net/core/viper"
"database/sql"
"errors"
"fmt"
Expand Down Expand Up @@ -40,9 +41,13 @@ func (store *PostgresStore) Open(config config.DbAccess) error {
var sqldb *sql.DB
var err error

lgr := logger.Default.LogMode(logger.Silent)
if viper.GetBool("logging.verbose") {
lgr = logger.Default.LogMode(logger.Info)
}

maxRetries := 60 * 1 // 1 minutes
for i := 0; i < maxRetries; i++ {

db, err = gorm.Open(postgres.Open(fmt.Sprintf(
"host=%v port=%v user=%v dbname=%v password=%v sslmode=disable",
config.Host,
Expand All @@ -51,7 +56,7 @@ func (store *PostgresStore) Open(config config.DbAccess) error {
config.Name,
config.Password)),
&gorm.Config{
Logger: logger.Default.LogMode(logger.Silent),
Logger: lgr,
SkipDefaultTransaction: true,
PrepareStmt: true,
})
Expand Down
1 change: 1 addition & 0 deletions docker.local/build.miner/b0docker-compose.yml
Expand Up @@ -48,6 +48,7 @@ services:
- ../miner${MINER}/log:/0chain/log
ports:
- "707${MINER}:707${MINER}"
- "708${MINER}:708${MINER}"
networks:
default:
testnet0:
Expand Down
2 changes: 2 additions & 0 deletions docker.local/config/0chain.yaml
Expand Up @@ -2,6 +2,7 @@ version: 1.0

logging:
level: "debug"
verbose: false
console: false # printing log to console is only supported in development mode
goroutines: false
memlog: false
Expand All @@ -18,6 +19,7 @@ development:
min_txn_value: 100
faucet:
refill_amount: 1000000000000000
pprof: true

zerochain:
id: "0afc093ffb509f059c55478bc1a60351cef7b4e9c008a53a6cc8241ca8617dfe"
Expand Down

0 comments on commit bd1fb04

Please sign in to comment.