2
0
mirror of synced 2025-02-23 14:18:13 +00:00

Track posted message type counts

This commit is contained in:
Matt Joiner 2016-02-10 00:45:47 +11:00
parent 317783091d
commit 26fa2c4af8
2 changed files with 5 additions and 0 deletions

View File

@ -71,6 +71,8 @@ var (
receivedMessageTypes = expvar.NewMap("receivedMessageTypes")
receivedKeepalives = expvar.NewInt("receivedKeepalives")
supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
postedMessageTypes = expvar.NewMap("postedMessageTypes")
postedKeepalives = expvar.NewInt("postedKeepalives")
)
const (

View File

@ -10,6 +10,7 @@ import (
"fmt"
"io"
"net"
"strconv"
"time"
"github.com/anacrolix/missinggo"
@ -258,6 +259,7 @@ func (c *connection) PeerHasPiece(piece int) bool {
func (c *connection) Post(msg pp.Message) {
select {
case c.post <- msg:
postedMessageTypes.Add(strconv.FormatInt(int64(msg.Type), 10), 1)
case <-c.closed.C():
}
}
@ -492,6 +494,7 @@ func (conn *connection) writeOptimizer(keepAliveDelay time.Duration) {
break
}
pending.PushBack(pp.Message{Keepalive: true})
postedKeepalives.Add(1)
case msg, ok := <-conn.post:
if !ok {
return