eth/protocols, metrics, p2p: add handler performance metrics

This commit is contained in:
Péter Szilágyi
2021-03-26 14:00:06 +02:00
parent 54c0d573d7
commit 6d7ff6acea
4 changed files with 38 additions and 2 deletions

View File

@ -19,12 +19,14 @@ package snap
import (
"bytes"
"fmt"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/light"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/enr"
@ -128,6 +130,14 @@ func handleMessage(backend Backend, peer *Peer) error {
}
defer msg.Discard()
// Track the emount of time it takes to serve the request and run the handler
if metrics.Enabled {
h := fmt.Sprintf("%s/%s/%d/%#02x", p2p.HandleHistName, ProtocolName, peer.Version(), msg.Code)
defer func(start time.Time) {
sampler := func() metrics.Sample { return metrics.NewExpDecaySample(1028, 0.015) }
metrics.GetOrRegisterHistogramLazy(h, nil, sampler).Update(time.Since(start).Microseconds())
}(time.Now())
}
// Handle the message depending on its contents
switch {
case msg.Code == GetAccountRangeMsg: