Skip to content

Commit

Permalink
dbg: add periodic save heap routine (#12698)
Browse files Browse the repository at this point in the history
  • Loading branch information
taratorio authored Nov 14, 2024
1 parent c4f30a3 commit c843db5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions erigon-lib/common/dbg/experiments.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package dbg

import (
"context"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -233,3 +234,21 @@ func SaveHeapProfileNearOOM(opts ...SaveHeapOption) {
logger.Warn("[Experiment] could not write heap profile file", "err", err)
}
}

func SaveHeapProfileNearOOMPeriodically(ctx context.Context, opts ...SaveHeapOption) {
if !saveHeapProfile {
return
}

ticker := time.NewTicker(30 * time.Second)
defer ticker.Stop()

for {
select {
case <-ctx.Done():
return
case <-ticker.C:
SaveHeapProfileNearOOM(opts...)
}
}
}
1 change: 1 addition & 0 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ func New(ctx context.Context, stack *node.Node, config *ethconfig.Config, logger
// setup periodic logging and prometheus updates
go mem.LogMemStats(ctx, logger)
go disk.UpdateDiskStats(ctx, logger)
go dbg.SaveHeapProfileNearOOMPeriodically(ctx, dbg.SaveHeapWithLogger(&logger))

var currentBlock *types.Block
if err := backend.chainDB.View(context.Background(), func(tx kv.Tx) error {
Expand Down

0 comments on commit c843db5

Please sign in to comment.