Skip to content

Commit

Permalink
chore(stagedsync): record major page faults
Browse files Browse the repository at this point in the history
  • Loading branch information
ty-sentio-xyz committed Apr 12, 2023
1 parent 21bd1db commit ce5b870
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion eth/stagedsync/stage_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/ledgerwatch/erigon-lib/kv/temporal/historyv2"
libstate "github.com/ledgerwatch/erigon-lib/state"
"github.com/ledgerwatch/log/v3"
"golang.org/x/sys/unix"

"github.com/ledgerwatch/erigon/common/changeset"
"github.com/ledgerwatch/erigon/common/dbutils"
Expand Down Expand Up @@ -371,6 +372,14 @@ func senderStageProgress(tx kv.Tx, db kv.RoDB) (prevStageProgress uint64, err er

// ================ Erigon3 End ================

func getPageFaultCounter() (int64, int64) {
var rusage unix.Rusage
if err := unix.Getrusage(unix.RUSAGE_SELF, &rusage); err != nil {
return 0, 0
}
return rusage.Minflt, rusage.Majflt

}
func SpawnExecuteBlocksStage(s *StageState, u Unwinder, tx kv.RwTx, toBlock uint64, ctx context.Context, cfg ExecuteBlockCfg, initialCycle bool, quiet bool) (err error) {
if cfg.historyV3 {
if err = ExecBlockV3(s, u, tx, toBlock, ctx, cfg, initialCycle); err != nil {
Expand Down Expand Up @@ -435,6 +444,7 @@ func SpawnExecuteBlocksStage(s *StageState, u Unwinder, tx kv.RwTx, toBlock uint
}()

var stageCounters ExeuctionPerformanceCounters
lastMinflt, lastMajflt := getPageFaultCounter()
Loop:
for blockNum := stageProgress + 1; blockNum <= to; blockNum++ {
if stoppedErr = common.Stopped(quit); stoppedErr != nil {
Expand Down Expand Up @@ -506,7 +516,11 @@ Loop:
select {
default:
case <-logEvery.C:
logBlock, logTx, logTime = logProgress(logPrefix, logBlock, logTime, blockNum, logTx, lastLogTx, gas, float64(currentStateGas)/float64(gasState), batch, stageCounters)
minflt, majflt := getPageFaultCounter()
logBlock, logTx, logTime = logProgress(logPrefix, logBlock, logTime, blockNum, logTx, lastLogTx, gas,
float64(currentStateGas)/float64(gasState), batch, stageCounters,
minflt-lastMinflt, majflt-lastMajflt)
lastMinflt, lastMajflt = minflt, majflt
gas = 0
stageCounters.Reset()
tx.CollectMetrics()
Expand Down Expand Up @@ -541,6 +555,7 @@ Loop:
func logProgress(logPrefix string, prevBlock uint64, prevTime time.Time, currentBlock uint64, prevTx, currentTx uint64, gas uint64,
gasState float64, batch ethdb.DbWithPendingMutations,
counters ExeuctionPerformanceCounters,
minflt, majflt int64,
) (uint64, uint64, time.Time) {
currentTime := time.Now()
interval := currentTime.Sub(prevTime)
Expand All @@ -551,6 +566,7 @@ func logProgress(logPrefix string, prevBlock uint64, prevTime time.Time, current
sloadSpeed := float64(counters.NumSload) / (float64(interval) / float64(time.Second))
sstoreSpeed := float64(counters.NumSstore) / (float64(interval) / float64(time.Second))
opSpeed := float64(counters.NumOp) / (float64(interval) / float64(time.Second))
majfltSpeed := float64(majflt) / (float64(interval) / float64(time.Second))
var m runtime.MemStats
dbg.ReadMemStats(&m)
var logpairs = []interface{}{
Expand All @@ -562,6 +578,8 @@ func logProgress(logPrefix string, prevBlock uint64, prevTime time.Time, current
"sstore/s", fmt.Sprintf("%.1f", sstoreSpeed),
"op/s", fmt.Sprintf("%.1f", opSpeed),
"calls", counters.NumCall,
"majflt/s", fmt.Sprintf("%.1f", majfltSpeed),
"majflt", majflt,
"gasState", fmt.Sprintf("%.2f", gasState),
}
if batch != nil {
Expand Down

0 comments on commit ce5b870

Please sign in to comment.