diff --git a/cmd/opera/launcher/launcher.go b/cmd/opera/launcher/launcher.go index c81100659..5cf6d0d4a 100644 --- a/cmd/opera/launcher/launcher.go +++ b/cmd/opera/launcher/launcher.go @@ -14,6 +14,7 @@ import ( "github.com/ethereum/go-ethereum/console/prompt" "github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/log" + gmetrics "github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/p2p/discover/discfilter" "github.com/ethereum/go-ethereum/params" @@ -299,7 +300,10 @@ func makeNode(ctx *cli.Context, cfg *config, genesisStore *genesisstore.Store) ( if genesisStore != nil { _ = genesisStore.Close() } - metrics.SetDataDir(cfg.Node.DataDir) + + if gmetrics.Enabled { + metrics.SetDataDir(cfg.Node.DataDir) + } memorizeDBPreset(cfg) // substitute default bootnodes if requested diff --git a/cmd/opera/launcher/metrics/metrics.go b/cmd/opera/launcher/metrics/metrics.go index edc74a873..7daa7829a 100644 --- a/cmd/opera/launcher/metrics/metrics.go +++ b/cmd/opera/launcher/metrics/metrics.go @@ -26,10 +26,10 @@ func measureDbDir(name, datadir string) { rescan = (len(datadir) > 0 && datadir != "inmemory") ) for { - time.Sleep(time.Second) + time.Sleep(10 * time.Second) if rescan { - size := sizeOfDir(datadir) + size := sizeOfDir(datadir, new(int)) atomic.StoreInt64(&dbSize, size) } @@ -45,8 +45,12 @@ func measureDbDir(name, datadir string) { } } -func sizeOfDir(dir string) (size int64) { +func sizeOfDir(dir string, counter *int) (size int64) { err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error { + *counter++ + if *counter % 100 == 0 { + time.Sleep(100 * time.Millisecond) + } if err != nil { log.Debug("datadir walk", "path", path, "err", err) return filepath.SkipDir @@ -58,7 +62,7 @@ func sizeOfDir(dir string) (size int64) { dst, err := filepath.EvalSymlinks(path) if err == nil && dst != path { - size += sizeOfDir(dst) + size += sizeOfDir(dst, counter) } else { size += info.Size() }