From 50811f9cd63c6ca64a7eb435f5308dcd09649586 Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Wed, 21 Sep 2022 09:18:37 +0700 Subject: [PATCH] "erigon snapshots ram" command (#5449) * save * save * save --- turbo/app/snapshots.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/turbo/app/snapshots.go b/turbo/app/snapshots.go index 77274d6bc..2b44c7ebd 100644 --- a/turbo/app/snapshots.go +++ b/turbo/app/snapshots.go @@ -86,6 +86,12 @@ var snapshotCommand = cli.Command{ Before: func(ctx *cli.Context) error { return debug.Setup(ctx) }, Flags: append([]cli.Flag{utils.DataDirFlag}, debug.Flags...), }, + { + Name: "ram", + Action: doRam, + Before: func(ctx *cli.Context) error { return debug.Setup(ctx) }, + Flags: append([]cli.Flag{utils.DataDirFlag}, debug.Flags...), + }, }, } @@ -116,6 +122,26 @@ var ( } ) +func doRam(cliCtx *cli.Context) error { + args := cliCtx.Args() + if len(args) != 1 { + return fmt.Errorf("expecting .seg file path") + } + f := args[0] + var m runtime.MemStats + runtime.ReadMemStats(&m) + runtime.ReadMemStats(&m) + before := m.Alloc + log.Info("RAM before open", "alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys)) + decompressor, err := compress.NewDecompressor(f) + if err != nil { + return err + } + defer decompressor.Close() + runtime.ReadMemStats(&m) + log.Info("RAM after open", "alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys), "diff", common.ByteCount(m.Alloc-before)) + return nil +} func doIndicesCommand(cliCtx *cli.Context) error { ctx, cancel := common.RootContext() defer cancel()