diff --git a/cmd/aida-stochastic-sdb/stochastic/replay.go b/cmd/aida-stochastic-sdb/stochastic/replay.go index e47fccee7..4203c97d7 100644 --- a/cmd/aida-stochastic-sdb/stochastic/replay.go +++ b/cmd/aida-stochastic-sdb/stochastic/replay.go @@ -120,7 +120,12 @@ func stochasticReplayAction(ctx *cli.Context) error { log.Criticalf("Failed to close database; %v", err) } log.Infof("Closing DB took %v", time.Since(start)) - log.Noticef("Final disk usage: %v MiB", float32(utils.GetDirectorySize(stateDbDir))/float32(1024*1024)) + + size, err := utils.GetDirectorySize(stateDbDir) + if err != nil { + return fmt.Errorf("cannot size of state-db (%v); %v", stateDbDir, err) + } + log.Noticef("Final disk usage: %v MiB", float32(size)/float32(1024*1024)) return runErr } diff --git a/executor/extension/tracker/progress_tracker.go b/executor/extension/tracker/progress_tracker.go index 2c506cf66..e70af23c6 100644 --- a/executor/extension/tracker/progress_tracker.go +++ b/executor/extension/tracker/progress_tracker.go @@ -1,6 +1,7 @@ package tracker import ( + "fmt" "sync" "time" @@ -95,7 +96,10 @@ func (t *progressTracker) PostBlock(state executor.State[*substate.Substate], ct info := t.overallInfo t.lock.Unlock() - disk := utils.GetDirectorySize(ctx.StateDbPath) + disk, err := utils.GetDirectorySize(ctx.StateDbPath) + if err != nil { + return fmt.Errorf("cannot size of state-db (%v); %v", ctx.StateDbPath, err) + } m := ctx.State.GetMemoryUsage() memory := uint64(0) diff --git a/utils/statedb.go b/utils/statedb.go index 956a68972..dbab022ea 100644 --- a/utils/statedb.go +++ b/utils/statedb.go @@ -2,7 +2,6 @@ package utils import ( "fmt" - "io/fs" "os" "path/filepath" @@ -65,7 +64,7 @@ func useExistingStateDB(cfg *Config) (state.StateDB, string, error) { return nil, "", fmt.Errorf("failed to create a temporary directory; %v", err) } - size, err := FindDirSize(cfg.StateDbSrc) + size, err := GetDirectorySize(cfg.StateDbSrc) if err != nil { return nil, "", err } @@ -258,23 +257,8 @@ func DeleteDestroyedAccountsFromStateDB(db state.StateDB, cfg *Config, target ui return nil } -// GetDirectorySize computes the size of all files in the given directory in bytes. -func GetDirectorySize(directory string) int64 { - var sum int64 = 0 - filepath.Walk(directory, func(path string, info fs.FileInfo, err error) error { - if err != nil { - return nil - } - if !info.IsDir() { - sum += info.Size() - } - return nil - }) - return sum -} - -// FindDirSize iterates over all files inside given directory (including subdirectories) and returns size in bytes. -func FindDirSize(path string) (int64, error) { +// GetDirectorySize iterates over all files inside given directory (including subdirectories) and returns size in bytes. +func GetDirectorySize(path string) (int64, error) { var size int64 err := filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { if err != nil {