mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
whisper: statistics updated
This commit is contained in:
parent
5e5b2b1300
commit
cb7a6d43c5
1 changed files with 12 additions and 7 deletions
|
|
@ -37,8 +37,9 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Statistics struct {
|
type Statistics struct {
|
||||||
messages int
|
messagesCleared int
|
||||||
memory int
|
memoryCleared int
|
||||||
|
totalMemoryUsed int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whisper represents a dark communication interface through the Ethereum
|
// Whisper represents a dark communication interface through the Ethereum
|
||||||
|
|
@ -477,6 +478,7 @@ func (wh *Whisper) add(envelope *Envelope) (bool, error) {
|
||||||
glog.V(logger.Detail).Infof("whisper envelope already cached [%x]\n", envelope.Hash())
|
glog.V(logger.Detail).Infof("whisper envelope already cached [%x]\n", envelope.Hash())
|
||||||
} else {
|
} else {
|
||||||
glog.V(logger.Detail).Infof("cached whisper envelope [%x]: %v\n", envelope.Hash(), envelope)
|
glog.V(logger.Detail).Infof("cached whisper envelope [%x]: %v\n", envelope.Hash(), envelope)
|
||||||
|
wh.stats.totalMemoryUsed += envelope.size()
|
||||||
wh.postEvent(envelope, false) // notify the local node about the new message
|
wh.postEvent(envelope, false) // notify the local node about the new message
|
||||||
if wh.mailServer != nil {
|
if wh.mailServer != nil {
|
||||||
wh.mailServer.Archive(envelope)
|
wh.mailServer.Archive(envelope)
|
||||||
|
|
@ -561,11 +563,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.messages++
|
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 {
|
||||||
w.stats.memory += w.envelopes[v.(common.Hash)].size()
|
sz := w.envelopes[v.(common.Hash)].size()
|
||||||
|
w.stats.memoryCleared += sz
|
||||||
|
w.stats.totalMemoryUsed -= sz
|
||||||
delete(w.envelopes, v.(common.Hash))
|
delete(w.envelopes, v.(common.Hash))
|
||||||
delete(w.messages, v.(common.Hash))
|
delete(w.messages, v.(common.Hash))
|
||||||
return true
|
return true
|
||||||
|
|
@ -577,7 +581,8 @@ func (w *Whisper) expire() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *Whisper) Stats() string {
|
func (w *Whisper) Stats() string {
|
||||||
return fmt.Sprintf("Latest expiry cycle cleared %d messages (%d bytes)", w.stats.messages, w.stats.memory)
|
return fmt.Sprintf("Latest expiry cycle cleared %d messages (%d bytes). Memory usage: %d bytes.",
|
||||||
|
w.stats.messagesCleared, w.stats.memoryCleared, w.stats.totalMemoryUsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
// envelopes retrieves all the messages currently pooled by the node.
|
// envelopes retrieves all the messages currently pooled by the node.
|
||||||
|
|
@ -624,8 +629,8 @@ func (w *Whisper) addDecryptedMessage(msg *ReceivedMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Statistics) clear() {
|
func (s *Statistics) clear() {
|
||||||
s.memory = 0
|
s.memoryCleared = 0
|
||||||
s.messages = 0
|
s.messagesCleared = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidatePublicKey(k *ecdsa.PublicKey) bool {
|
func ValidatePublicKey(k *ecdsa.PublicKey) bool {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue