Skip to content

Commit

Permalink
perf: add pbss hash metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
will@2012 committed Sep 26, 2024
1 parent f5b5805 commit d4cff4b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions trie/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package trie

import (
"sync"
"time"

"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/rlp"
Expand Down Expand Up @@ -182,6 +183,11 @@ func (h *hasher) encodedBytes() []byte {

// hashData hashes the provided data
func (h *hasher) hashData(data []byte) hashNode {
defer func(start time.Time) {
hashQPS.Mark(1)
hashTime.Mark(time.Since(start).Nanoseconds())
}(time.Now())

n := make(hashNode, 32)
h.sha.Reset()
h.sha.Write(data)
Expand Down
8 changes: 8 additions & 0 deletions trie/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package trie

import "github.com/ethereum/go-ethereum/metrics"

var (
hashQPS = metrics.NewRegisteredMeter("pbss/hash/qps", nil)
hashTime = metrics.NewRegisteredMeter("pbss/hash/time", nil)
)

0 comments on commit d4cff4b

Please sign in to comment.