2
0
mirror of synced 2025-02-23 22:28:11 +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") receivedMessageTypes = expvar.NewMap("receivedMessageTypes")
receivedKeepalives = expvar.NewInt("receivedKeepalives") receivedKeepalives = expvar.NewInt("receivedKeepalives")
supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages") supportedExtensionMessages = expvar.NewMap("supportedExtensionMessages")
postedMessageTypes = expvar.NewMap("postedMessageTypes")
postedKeepalives = expvar.NewInt("postedKeepalives")
) )
const ( const (

View File

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