Skip to content

Commit 2754bfc

Browse files
committed
add ws metrics
1 parent 857f65f commit 2754bfc

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

state/factory/statedb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ func (sdb *stateDB) Mint(
256256
ap actpool.ActPool,
257257
pk crypto.PrivateKey,
258258
) (*block.Block, error) {
259+
timer := timerFactory.NewTimer("workingSet.Mint")
260+
defer timer.End()
259261
bcCtx := protocol.MustGetBlockchainCtx(ctx)
260262
expectedBlockHeight := bcCtx.Tip.Height + 1
261263
ctx = protocol.WithRegistry(ctx, sdb.registry)

state/factory/workingset.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
"github.com/iotexproject/iotex-core/v2/blockchain/genesis"
3232
"github.com/iotexproject/iotex-core/v2/db"
3333
"github.com/iotexproject/iotex-core/v2/pkg/log"
34+
"github.com/iotexproject/iotex-core/v2/pkg/prometheustimer"
3435
"github.com/iotexproject/iotex-core/v2/state"
3536
)
3637

@@ -49,6 +50,7 @@ var (
4950
},
5051
[]string{"type"},
5152
)
53+
timerFactory *prometheustimer.TimerFactory
5254

5355
errInvalidSystemActionLayout = errors.New("system action layout is invalid")
5456
errUnfoldTxContainer = errors.New("failed to unfold tx container")
@@ -58,6 +60,17 @@ var (
5860
func init() {
5961
prometheus.MustRegister(_stateDBMtc)
6062
prometheus.MustRegister(_mintAbility)
63+
64+
var err error
65+
timerFactory, err = prometheustimer.New(
66+
"iotex_mint_latency_nanoseconds",
67+
"Latency of mint operations in nanoseconds",
68+
[]string{"operation"},
69+
[]string{"unknown"},
70+
)
71+
if err != nil {
72+
log.L().Error("Failed to create proposal pool latency timer", zap.Error(err))
73+
}
6174
}
6275

6376
type (
@@ -692,6 +705,8 @@ func (ws *workingSet) pickAndRunActions(
692705
sign func(elp action.Envelope) (*action.SealedEnvelope, error),
693706
allowedBlockGasResidue uint64,
694707
) ([]*action.SealedEnvelope, error) {
708+
timer := timerFactory.NewTimer("workingSet.pickAndRunActions")
709+
defer timer.End()
695710
err := ws.validate(ctx)
696711
if err != nil {
697712
return nil, err
@@ -943,6 +958,8 @@ func (ws *workingSet) CreateBuilder(
943958
sign func(elp action.Envelope) (*action.SealedEnvelope, error),
944959
allowedBlockGasResidue uint64,
945960
) (*block.Builder, error) {
961+
timer := timerFactory.NewTimer("workingSet.CreateBuilder")
962+
defer timer.End()
946963
actions, err := ws.pickAndRunActions(ctx, ap, sign, allowedBlockGasResidue)
947964
if err != nil {
948965
return nil, err

0 commit comments

Comments
 (0)