From a3bc6398c88c27e6fba75c1ef678ef47ef61cee8 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 29 Jun 2018 22:10:21 +1000 Subject: [PATCH] Merge messageTypes{Sent,Posted} into torrent expvar --- connection.go | 7 ++++--- global.go | 2 -- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/connection.go b/connection.go index 0c3bc1c4..54297b56 100644 --- a/connection.go +++ b/connection.go @@ -332,7 +332,7 @@ func (cn *connection) PeerHasPiece(piece int) bool { // Writes a message into the write buffer. func (cn *connection) Post(msg pp.Message) { - messageTypesPosted.Add(msg.Type.String(), 1) + torrent.Add(fmt.Sprintf("messages posted of type %s", msg.Type.String()), 1) // We don't need to track bytes here because a connection.w Writer wrapper // takes care of that (although there's some delay between us recording // the message, and the connection writer flushing it out.). @@ -604,7 +604,8 @@ func (cn *connection) writer(keepAliveTimeout time.Duration) { cn.fillWriteBuffer(func(msg pp.Message) bool { cn.wroteMsg(&msg) cn.writeBuffer.Write(msg.MustMarshalBinary()) - return cn.writeBuffer.Len() < 1<<16 + torrent.Add(fmt.Sprintf("messages filled of type %s", msg.Type.String()), 1) + return cn.writeBuffer.Len() < 1<<16 // 64KiB }) } if cn.writeBuffer.Len() == 0 && time.Since(lastWrite) >= keepAliveTimeout { @@ -923,7 +924,7 @@ func (c *connection) requestPendingMetadata() { } func (cn *connection) wroteMsg(msg *pp.Message) { - messageTypesSent.Add(msg.Type.String(), 1) + torrent.Add(fmt.Sprintf("messages written of type %s", msg.Type.String()), 1) cn.allStats(func(cs *ConnStats) { cs.wroteMsg(msg) }) } diff --git a/global.go b/global.go index bbec4b5f..ef7660fb 100644 --- a/global.go +++ b/global.go @@ -42,8 +42,6 @@ var ( requestedChunkLengths = expvar.NewMap("requestedChunkLengths") messageTypesReceived = expvar.NewMap("messageTypesReceived") - messageTypesSent = expvar.NewMap("messageTypesSent") - messageTypesPosted = expvar.NewMap("messageTypesPosted") // Track the effectiveness of Torrent.connPieceInclinationPool. pieceInclinationsReused = expvar.NewInt("pieceInclinationsReused")