mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 05:36:46 +00:00
expose stats
This commit is contained in:
parent
48c3f91efc
commit
d74dd39131
1 changed files with 10 additions and 6 deletions
|
|
@ -235,6 +235,7 @@ type SizeTracker struct {
|
||||||
abort chan struct{}
|
abort chan struct{}
|
||||||
aborted chan struct{}
|
aborted chan struct{}
|
||||||
updateCh chan *stateUpdate
|
updateCh chan *stateUpdate
|
||||||
|
stats map[common.Hash]SizeStats // internal stats map
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSizeTracker creates a new state size tracker and starts it automatically
|
// NewSizeTracker creates a new state size tracker and starts it automatically
|
||||||
|
|
@ -248,6 +249,7 @@ func NewSizeTracker(db ethdb.KeyValueStore, triedb *triedb.Database) (*SizeTrack
|
||||||
abort: make(chan struct{}),
|
abort: make(chan struct{}),
|
||||||
aborted: make(chan struct{}),
|
aborted: make(chan struct{}),
|
||||||
updateCh: make(chan *stateUpdate),
|
updateCh: make(chan *stateUpdate),
|
||||||
|
stats: make(map[common.Hash]SizeStats),
|
||||||
}
|
}
|
||||||
go t.run()
|
go t.run()
|
||||||
return t, nil
|
return t, nil
|
||||||
|
|
@ -286,13 +288,14 @@ func (t *SizeTracker) run() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
t.stats = stats
|
||||||
h := sizeStatsHeap(slices.Collect(maps.Values(stats)))
|
h := sizeStatsHeap(slices.Collect(maps.Values(stats)))
|
||||||
heap.Init(&h)
|
heap.Init(&h)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case u := <-t.updateCh:
|
case u := <-t.updateCh:
|
||||||
base, found := stats[u.originRoot]
|
base, found := t.stats[u.originRoot]
|
||||||
if !found {
|
if !found {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
@ -301,15 +304,14 @@ func (t *SizeTracker) run() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
stat := base.add(diff)
|
stat := base.add(diff)
|
||||||
stats[u.root] = stat
|
t.stats[u.root] = stat
|
||||||
t.upload(stat)
|
t.upload(stat)
|
||||||
|
|
||||||
heap.Push(&h, stats[u.root])
|
heap.Push(&h, t.stats[u.root])
|
||||||
for u.blockNumber-h[0].BlockNumber > statEvictThreshold {
|
for len(h) > 0 && u.blockNumber-h[0].BlockNumber > statEvictThreshold {
|
||||||
delete(stats, h[0].StateRoot)
|
delete(t.stats, h[0].StateRoot)
|
||||||
heap.Pop(&h)
|
heap.Pop(&h)
|
||||||
}
|
}
|
||||||
|
|
||||||
case <-t.abort:
|
case <-t.abort:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -512,6 +514,8 @@ func (t *SizeTracker) Notify(update *stateUpdate) {
|
||||||
case t.updateCh <- update:
|
case t.updateCh <- update:
|
||||||
case <-t.abort:
|
case <-t.abort:
|
||||||
return
|
return
|
||||||
|
default:
|
||||||
|
// Drop update if channel is full
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue