Skip to content

Commit

Permalink
fix(path): build directory
Browse files Browse the repository at this point in the history
  • Loading branch information
radkomih committed Jun 3, 2024
1 parent 9901cbe commit f557f22
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion benchmarking/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package benchmarking

import (
"flag"
"fmt"
"log"
"os"
"path/filepath"
)

// cmd flags and other options related to benchmarking
Expand All @@ -16,7 +20,13 @@ type benchmarkingConfig struct {

func initBenchmarkingConfig() benchmarkingConfig {
cfg := benchmarkingConfig{}
cfg.WasmRuntime = "../../../build/runtime.wasm"

buildDir, err := getBuildDir()
if err != nil {
log.Fatal(err)
}
cfg.WasmRuntime = filepath.Join(buildDir, "runtime.wasm")

flag.IntVar(&cfg.Steps, "steps", 50, "Select how many samples we should take across the variable components.")
flag.IntVar(&cfg.Repeat, "repeat", 20, "Select how many repetitions of this benchmark should run from within the wasm.")
flag.IntVar(&cfg.HeapPages, "heap-pages", 4096, "Cache heap allocation pages.")
Expand All @@ -42,3 +52,29 @@ func initOverheadConfig() overheadConfig {
flag.IntVar(&cfg.MaxExtPerBlock, "overhead.maxExtPerBlock", 200, "Maximum number of extrinsics per block")
return cfg
}

func getBuildDir() (string, error) {
currentDir, err := os.Getwd()
if err != nil {
return "", fmt.Errorf("failed to get current directory: %v", err)
}

for {
// check if the directory exists
buildDirPath := filepath.Join(currentDir, "build")
stat, err := os.Stat(buildDirPath)
if err == nil && stat.IsDir() {
return buildDirPath, nil
}

// move up one level
parentDir := filepath.Dir(currentDir)
if parentDir == currentDir {
// reached the root directory
break
}
currentDir = parentDir
}

return "", fmt.Errorf("could not find \"build\" directory")
}

0 comments on commit f557f22

Please sign in to comment.