whisper: statistics updated

This commit is contained in:
Vlad 2017-03-16 20:55:53 +01:00
parent 74678aacc9
commit 8a1f1c557e

View file

@ -647,14 +647,13 @@ func (w *Whisper) expire() {
now := uint32(time.Now().Unix()) now := uint32(time.Now().Unix())
for expiry, hashSet := range w.expirations { for expiry, hashSet := range w.expirations {
if expiry < now { if expiry < now {
w.stats.messagesCleared++
// Dump all expired messages and remove timestamp // Dump all expired messages and remove timestamp
hashSet.Each(func(v interface{}) bool { hashSet.Each(func(v interface{}) bool {
sz := w.envelopes[v.(common.Hash)].size() sz := w.envelopes[v.(common.Hash)].size()
delete(w.envelopes, v.(common.Hash))
w.stats.messagesCleared++
w.stats.memoryCleared += sz w.stats.memoryCleared += sz
w.stats.memoryUsed -= sz w.stats.memoryUsed -= sz
delete(w.envelopes, v.(common.Hash))
return true return true
}) })
w.expirations[expiry].Clear() w.expirations[expiry].Clear()
@ -664,10 +663,10 @@ func (w *Whisper) expire() {
} }
func (w *Whisper) Stats() string { func (w *Whisper) Stats() string {
result := fmt.Sprintf("Memory usage: %d bytes.\nAverage messages cleared per expiry cycle: %d.", result := fmt.Sprintf("Memory usage: %d bytes. Average messages cleared per expiry cycle: %d. Total messages cleared: %d.",
w.stats.memoryUsed, w.stats.totalMessagesCleared/w.stats.cycles) w.stats.memoryUsed, w.stats.totalMessagesCleared/w.stats.cycles, w.stats.totalMessagesCleared)
if w.stats.messagesCleared > 0 { if w.stats.messagesCleared > 0 {
result += fmt.Sprintf("\nLatest expiry cycle cleared %d messages (%d bytes).", result += fmt.Sprintf(" Latest expiry cycle cleared %d messages (%d bytes).",
w.stats.messagesCleared, w.stats.memoryCleared) w.stats.messagesCleared, w.stats.memoryCleared)
} }
return result return result