p2p: measure subprotocol bandwidth usage

This commit is contained in:
Péter Szilágyi
2019-09-27 17:41:47 +03:00
parent df89233b57
commit a2a60869c8
3 changed files with 19 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/ethereum/go-ethereum/rlp"
@ -300,6 +301,9 @@ func (p *Peer) handle(msg Msg) error {
if err != nil {
return fmt.Errorf("msg code out of range: %v", msg.Code)
}
if metrics.Enabled {
metrics.GetOrRegisterMeter(fmt.Sprintf("%s/%s/%d/%#02x", MetricsInboundTraffic, proto.Name, proto.Version, msg.Code-proto.offset), nil).Mark(int64(msg.meterSize))
}
select {
case proto.in <- msg:
return nil
@ -398,7 +402,11 @@ func (rw *protoRW) WriteMsg(msg Msg) (err error) {
if msg.Code >= rw.Length {
return newPeerError(errInvalidMsgCode, "not handled")
}
msg.meterCap = rw.cap()
msg.meterCode = msg.Code
msg.Code += rw.offset
select {
case <-rw.wstart:
err = rw.w.WriteMsg(msg)