forked from cerc-io/plugeth
trie: make the cache miss counter a real metric
This commit is contained in:
parent
ca49510e6d
commit
d48e6ae66f
12
trie/trie.go
12
trie/trie.go
@ -20,12 +20,12 @@ package trie
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"sync/atomic"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/crypto/sha3"
|
"github.com/ethereum/go-ethereum/crypto/sha3"
|
||||||
"github.com/ethereum/go-ethereum/logger"
|
"github.com/ethereum/go-ethereum/logger"
|
||||||
"github.com/ethereum/go-ethereum/logger/glog"
|
"github.com/ethereum/go-ethereum/logger/glog"
|
||||||
|
"github.com/rcrowley/go-metrics"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -35,15 +35,13 @@ var (
|
|||||||
emptyState common.Hash
|
emptyState common.Hash
|
||||||
)
|
)
|
||||||
|
|
||||||
// cacheMisses maintains the number of times a trie node was loaded from disk.
|
var cacheMissCounter = metrics.NewRegisteredCounter("trie/cachemiss", nil)
|
||||||
// Always use atomic operations when accessing this global variable.
|
|
||||||
var cacheMisses uint64
|
|
||||||
|
|
||||||
// CacheMisses retrieves a global counter measuring the number of cache misses
|
// 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
|
// the trie did since process startup. This isn't useful for anything apart from
|
||||||
// trie debugging purposes.
|
// trie debugging purposes.
|
||||||
func CacheMisses() uint64 {
|
func CacheMisses() int64 {
|
||||||
return atomic.LoadUint64(&cacheMisses)
|
return cacheMissCounter.Count()
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
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) {
|
func (t *Trie) resolveHash(n hashNode, prefix, suffix []byte) (node, error) {
|
||||||
atomic.AddUint64(&cacheMisses, 1)
|
cacheMissCounter.Inc(1)
|
||||||
|
|
||||||
enc, err := t.db.Get(n)
|
enc, err := t.db.Get(n)
|
||||||
if err != nil || enc == nil {
|
if err != nil || enc == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user