Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redudant func #900

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cmd/aida-stochastic-sdb/stochastic/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion executor/extension/tracker/progress_tracker.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tracker

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -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)
Expand Down
22 changes: 3 additions & 19 deletions utils/statedb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package utils

import (
"fmt"
"io/fs"
"os"
"path/filepath"

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down