aboutsummaryrefslogtreecommitdiffstats
path: root/trie
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-10-18 19:44:41 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-10-19 19:12:35 +0800
commit2bb5ec1e41ed8c1e56e31639fec87710e81d3977 (patch)
tree1435066b5021fa49d7d16558440ac8ccfd3a6831 /trie
parentc9471e778209e16442a530820fb90c01cd47c369 (diff)
downloaddexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar.gz
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar.bz2
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar.lz
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar.xz
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.tar.zst
dexon-2bb5ec1e41ed8c1e56e31639fec87710e81d3977.zip
cmd/geth, trie: track and report trie cache misses
Diffstat (limited to 'trie')
-rw-r--r--trie/trie.go14
1 files changed, 14 insertions, 0 deletions
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{