Skip to content

Commit

Permalink
Merge pull request bnb-chain#13 from flywukong/IO-metrics
Browse files Browse the repository at this point in the history
fix IO metrics
  • Loading branch information
forcodedancing authored Mar 8, 2022
2 parents 78c4513 + f1d36b4 commit 52bdb5c
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions core/state/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (s *StateDB) GetBalance(addr common.Address) *big.Int {
start := time.Now()
stateObject := s.getStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
return stateObject.Balance()
}
Expand All @@ -367,7 +367,7 @@ func (s *StateDB) GetNonce(addr common.Address) uint64 {
start := time.Now()
stateObject := s.getStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
return stateObject.Nonce()
}
Expand All @@ -388,7 +388,7 @@ func (s *StateDB) GetCode(addr common.Address) []byte {
start := time.Now()
stateObject := s.getStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
return stateObject.Code(s.db)
}
Expand All @@ -399,7 +399,7 @@ func (s *StateDB) GetCodeSize(addr common.Address) int {
start := time.Now()
stateObject := s.getStateObject(addr)
end := time.Now()
defer s.markMetrics(start, end, false)
defer s.markMetrics(&start, &end, false)
if stateObject != nil {
return stateObject.CodeSize(s.db)
}
Expand All @@ -410,28 +410,28 @@ func (s *StateDB) GetCodeHash(addr common.Address) common.Hash {
start := time.Now()
stateObject := s.getStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject == nil {
return common.Hash{}
}
return common.BytesToHash(stateObject.CodeHash())
}

func (s *StateDB) markMetrics(start time.Time, end time.Time, reachStorage bool) {
func (s *StateDB) markMetrics(start *time.Time, end *time.Time, reachStorage bool) {
goid := cachemetrics.Goid()
isSyncMainProcess := cachemetrics.IsSyncMainRoutineID(goid)
isMinerMainProcess := cachemetrics.IsMinerMainRoutineID(goid)
// record metrics of syncing main process
if isSyncMainProcess {
totalSyncIOCounter.Inc((end.Sub(start)).Nanoseconds())
totalSyncIOCounter.Inc((*end).Sub(*start).Nanoseconds())
l1AccountMeter.Mark(1)
if reachStorage {
l1StorageMeter.Mark(1)
}
}
// record metrics of mining main process
if isMinerMainProcess {
totalMinerIOCounter.Inc((end.Sub(start)).Nanoseconds())
totalMinerIOCounter.Inc((*end).Sub(*start).Nanoseconds())
minerL1AccountMeter.Mark(1)
if reachStorage {
l1StorageMeter.Mark(1)
Expand Down Expand Up @@ -520,7 +520,7 @@ func (s *StateDB) GetCommittedState(addr common.Address, hash common.Hash) commo
start := time.Now()
var end time.Time
needStorage := false
defer s.markMetrics(start, end, needStorage)
defer s.markMetrics(&start, &end, needStorage)
stateObject := s.getStateObject(addr)
hit := false
end = time.Now()
Expand Down Expand Up @@ -567,7 +567,7 @@ func (s *StateDB) AddBalance(addr common.Address, amount *big.Int) {
start := time.Now()
stateObject := s.GetOrNewStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
stateObject.AddBalance(amount)
}
Expand All @@ -578,7 +578,7 @@ func (s *StateDB) SubBalance(addr common.Address, amount *big.Int) {
start := time.Now()
stateObject := s.GetOrNewStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
stateObject.SubBalance(amount)
}
Expand All @@ -588,7 +588,7 @@ func (s *StateDB) SetBalance(addr common.Address, amount *big.Int) {
start := time.Now()
stateObject := s.GetOrNewStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
stateObject.SetBalance(amount)
}
Expand All @@ -598,7 +598,7 @@ func (s *StateDB) SetNonce(addr common.Address, nonce uint64) {
start := time.Now()
stateObject := s.GetOrNewStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
stateObject.SetNonce(nonce)
}
Expand All @@ -608,7 +608,7 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
start := time.Now()
stateObject := s.GetOrNewStateObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if stateObject != nil {
stateObject.SetCode(crypto.Keccak256Hash(code), code)
}
Expand All @@ -618,7 +618,7 @@ func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
start := time.Now()
markStorage := false
var end time.Time
defer s.markMetrics(start, end, markStorage)
defer s.markMetrics(&start, &end, markStorage)
stateObject := s.GetOrNewStateObject(addr)
end = time.Now()
if stateObject != nil {
Expand Down Expand Up @@ -946,7 +946,7 @@ func (s *StateDB) CreateAccount(addr common.Address) {
start := time.Now()
newObj, prev := s.createObject(addr)
end := time.Now()
s.markMetrics(start, end, false)
s.markMetrics(&start, &end, false)
if prev != nil {
newObj.setBalance(prev.data.Balance)
}
Expand Down

0 comments on commit 52bdb5c

Please sign in to comment.