diff options
author | Felix Lange <fjl@twurst.com> | 2016-10-19 21:22:37 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2016-10-19 21:22:37 +0800 |
commit | d48e6ae66f09b1061e2e7e54c750b20e14a1e45a (patch) | |
tree | 16ddc2493c2a89f3d753c325a6d9f873a4b96632 /trie/trie.go | |
parent | ca49510e6dd40e78e3e6827c6c4d7b2a3ec8ef5b (diff) | |
download | dexon-d48e6ae66f09b1061e2e7e54c750b20e14a1e45a.tar.gz dexon-d48e6ae66f09b1061e2e7e54c750b20e14a1e45a.tar.zst dexon-d48e6ae66f09b1061e2e7e54c750b20e14a1e45a.zip |
trie: make the cache miss counter a real metric
Diffstat (limited to 'trie/trie.go')
-rw-r--r-- | trie/trie.go | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/trie/trie.go b/trie/trie.go index 914bf20fa..632060543 100644 --- a/trie/trie.go +++ b/trie/trie.go @@ -20,12 +20,12 @@ package trie import ( "bytes" "fmt" - "sync/atomic" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto/sha3" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/logger/glog" + "github.com/rcrowley/go-metrics" ) var ( @@ -35,15 +35,13 @@ 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 +var cacheMissCounter = metrics.NewRegisteredCounter("trie/cachemiss", nil) // 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 CacheMisses() int64 { + return cacheMissCounter.Count() } func init() { @@ -432,7 +430,7 @@ 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) + cacheMissCounter.Inc(1) enc, err := t.db.Get(n) if err != nil || enc == nil { |