aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-10-19 19:29:24 +0800
committerGitHub <noreply@github.com>2016-10-19 19:29:24 +0800
commit8e52c2e754cdb343d0eb880a33251e1ba593d327 (patch)
tree1435066b5021fa49d7d16558440ac8ccfd3a6831
parentc9471e778209e16442a530820fb90c01cd47c369 (diff)
parent2bb5ec1e41ed8c1e56e31639fec87710e81d3977 (diff)
downloadgo-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar.gz
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar.bz2
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar.lz
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar.xz
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.tar.zst
go-tangerine-8e52c2e754cdb343d0eb880a33251e1ba593d327.zip
Merge pull request #3161 from karalabe/trie-cache-counters
cmd/geth, trie: track and report trie cache misses
-rw-r--r--cmd/geth/chaincmd.go18
-rw-r--r--trie/trie.go14
2 files changed, 28 insertions, 4 deletions
diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go
index 5ef278a64..d7cdf1064 100644
--- a/cmd/geth/chaincmd.go
+++ b/cmd/geth/chaincmd.go
@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/logger/glog"
+ "github.com/ethereum/go-ethereum/trie"
"github.com/syndtr/goleveldb/leveldb/util"
"gopkg.in/urfave/cli.v1"
)
@@ -89,21 +90,30 @@ func importChain(ctx *cli.Context) error {
if err := utils.ImportChain(chain, ctx.Args().First()); err != nil {
utils.Fatalf("Import error: %v", err)
}
- fmt.Printf("Import done in %v, compacting...\n", time.Since(start))
+ fmt.Printf("Import done in %v.\n", time.Since(start))
- // Compact the entire database to more accurately measure disk io and print the stats
if db, ok := chainDb.(*ethdb.LDBDatabase); ok {
+ // Output pre-compaction stats mostly to see the import trashing
+ stats, err := db.LDB().GetProperty("leveldb.stats")
+ if err != nil {
+ utils.Fatalf("Failed to read database stats: %v", err)
+ }
+ fmt.Println(stats)
+
+ // Compact the entire database to more accurately measure disk io and print the stats
start = time.Now()
- if err := db.LDB().CompactRange(util.Range{}); err != nil {
+ fmt.Println("Compacting entire database...")
+ if err = db.LDB().CompactRange(util.Range{}); err != nil {
utils.Fatalf("Compaction failed: %v", err)
}
fmt.Printf("Compaction done in %v.\n", time.Since(start))
- stats, err := db.LDB().GetProperty("leveldb.stats")
+ stats, err = db.LDB().GetProperty("leveldb.stats")
if err != nil {
utils.Fatalf("Failed to read database stats: %v", err)
}
fmt.Println(stats)
+ fmt.Println("Trie cache misses:", trie.CacheMisses())
}
return nil
}
diff --git a/trie/trie.go b/trie/trie.go
index 65005bae8..5a4b6185d 100644
--- a/trie/trie.go
+++ b/trie/trie.go
@@ -20,6 +20,7 @@ package trie
import (
"bytes"
"fmt"
+ "sync/atomic"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/sha3"
@@ -34,6 +35,17 @@ var (
emptyState common.Hash
)
+// cacheMisses maintains the number of times a trie node was loaded from disk.
+// Always use atomic operations when accessing this global variable.
+var cacheMisses uint64
+
+// CacheMisses retrieves a global counter measuring the number of cache misses
+// the trie did since process startup. This isn't useful for anything apart from
+// trie debugging purposes.
+func CacheMisses() uint64 {
+ return atomic.LoadUint64(&cacheMisses)
+}
+
func init() {
sha3.NewKeccak256().Sum(emptyState[:0])
}
@@ -419,6 +431,8 @@ func (t *Trie) resolve(n node, prefix, suffix []byte) (node, error) {
}
func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
+ atomic.AddUint64(&cacheMisses, 1)
+
enc, err := t.db.Get(n)
if err != nil || enc == nil {
return nil, &MissingNodeError{