Skip to content

Commit

Permalink
tweak: Add stream tracer timer.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-smith committed Oct 6, 2023
1 parent c639cf8 commit 010a057
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
12 changes: 12 additions & 0 deletions eth/filters/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ var (
Help: "Number of dropped txs sent",
},
)

metricsTraceTxTimer = prometheus.NewHistogramVec(
prometheus.HistogramOpts{
Subsystem: streamSubsystem,
Name: "trace_tx_duration",
Help: "Trace tx duration in seconds",
Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10},
},
[]string{},
)
)

func init() {
Expand Down Expand Up @@ -173,4 +183,6 @@ func init() {
register(metricsDroppedTxsEnd)
register(metricsDroppedTxsReceived)
register(metricsDroppedTxsSent)

register(metricsTraceTxTimer)
}
8 changes: 7 additions & 1 deletion eth/filters/trace_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"fmt"
"math/big"

"github.com/prometheus/client_golang/prometheus"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus/misc/eip1559"
Expand Down Expand Up @@ -273,7 +275,11 @@ func traceTx(message *core.Message, txCtx *tracers.Context, vmctx vm.BlockContex
if _, err = core.ApplyMessage(vmenv, message, new(core.GasPool).AddGas(message.GasLimit)); err != nil {
return nil, fmt.Errorf("tracing failed: %w", err)
}
return tracer.GetTrace()

timer := prometheus.NewTimer(metricsTraceTxTimer.With(nil))
trace, err := tracer.GetTrace()
timer.ObserveDuration()
return trace, err
}

// traceBlock traces all transactions in a block.
Expand Down

0 comments on commit 010a057

Please sign in to comment.