From 1291778032730fcd6d0b1bb4ae95a5f8e1f64987 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 21 Oct 2016 11:40:00 +0300 Subject: cmd/geth, code, eth/downloader: tune import logs and mem stats --- core/blockchain.go | 17 +++++++++++++++-- core/blockchain_test.go | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/blockchain.go b/core/blockchain.go index 5cf99cd8c..d806c143d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -774,7 +774,7 @@ func (self *BlockChain) InsertReceiptChain(blockChain types.Blocks, receiptChain if stats.ignored > 0 { ignored = fmt.Sprintf(" (%d ignored)", stats.ignored) } - glog.V(logger.Info).Infof("imported %d receipts%s in %9v. #%d [%x… / %x…]", stats.processed, ignored, common.PrettyDuration(time.Since(start)), last.Number(), first.Hash().Bytes()[:4], last.Hash().Bytes()[:4]) + glog.V(logger.Info).Infof("imported %d receipts in %9v. #%d [%x… / %x…]%s", stats.processed, common.PrettyDuration(time.Since(start)), last.Number(), first.Hash().Bytes()[:4], last.Hash().Bytes()[:4], ignored) return 0, nil } @@ -981,6 +981,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { stats.processed++ if glog.V(logger.Info) { + stats.usedGas += usedGas.Uint64() stats.report(chain, i) } } @@ -993,6 +994,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { // insertStats tracks and reports on block insertion. type insertStats struct { queued, processed, ignored int + usedGas uint64 lastIndex int startTime time.Time } @@ -1004,10 +1006,15 @@ const statsReportLimit = 8 * time.Second // report prints statistics if some number of blocks have been processed // or more than a few seconds have passed since the last message. func (st *insertStats) report(chain []*types.Block, index int) { + // Fetch the timings for the batch var ( now = time.Now() elapsed = now.Sub(st.startTime) ) + if elapsed == 0 { // Yes Windows, I'm looking at you + elapsed = 1 + } + // If we're at the last block of the batch or report period reached, log if index == len(chain)-1 || elapsed >= statsReportLimit { start, end := chain[st.lastIndex], chain[index] txcount := countTransactions(chain[st.lastIndex : index+1]) @@ -1016,7 +1023,13 @@ func (st *insertStats) report(chain []*types.Block, index int) { if st.queued > 0 || st.ignored > 0 { extra = fmt.Sprintf(" (%d queued %d ignored)", st.queued, st.ignored) } - glog.Infof("imported %d blocks%s, %5d txs in %9v. #%v [%x… / %x…]\n", st.processed, extra, txcount, common.PrettyDuration(elapsed), end.Number(), start.Hash().Bytes()[:4], end.Hash().Bytes()[:4]) + hashes := "" + if st.processed > 1 { + hashes = fmt.Sprintf("%x… / %x…", start.Hash().Bytes()[:4], end.Hash().Bytes()[:4]) + } else { + hashes = fmt.Sprintf("%x…", end.Hash().Bytes()[:4]) + } + glog.Infof("imported %d blocks, %5d txs (%7.3f Mg) in %9v (%6.3f Mg/s). #%v [%s]%s", st.processed, txcount, float64(st.usedGas)/1000000, common.PrettyDuration(elapsed), float64(st.usedGas)*1000/float64(elapsed), end.Number(), hashes, extra) *st = insertStats{startTime: now, lastIndex: index} } diff --git a/core/blockchain_test.go b/core/blockchain_test.go index de3ef0a9c..3c47b2fd9 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -436,7 +436,7 @@ func (bproc) ValidateState(block, parent *types.Block, state *state.StateDB, rec return nil } func (bproc) Process(block *types.Block, statedb *state.StateDB, cfg vm.Config) (types.Receipts, vm.Logs, *big.Int, error) { - return nil, nil, nil, nil + return nil, nil, new(big.Int), nil } func makeHeaderChainWithDiff(genesis *types.Block, d []int, seed byte) []*types.Header { -- cgit v1.2.3