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

fix(benchmarks): use correct path #413

Merged
merged 2 commits into from
Jun 3, 2024
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
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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func BenchmarkSessionPurgeKeys(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/session/call_purge_keys_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/session/call_purge_keys_weight.go", func(i *benchmarking.Instance) {
accountInfo := gossamertypes.AccountInfo{
Producers: 1,
Consumers: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

func BenchmarkSessionSetKeys(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/session/call_set_keys_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/session/call_set_keys_weight.go", func(i *benchmarking.Instance) {
accountInfo := gossamertypes.AccountInfo{
Producers: 1,
Data: gossamertypes.AccountData{
Expand Down
2 changes: 1 addition & 1 deletion runtime/templates/poa/benchmark_sudo_call_set_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func BenchmarkSudoSetKey(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_set_key_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/sudo/call_set_key_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

Expand Down
2 changes: 1 addition & 1 deletion runtime/templates/poa/benchmark_sudo_call_sudo_as_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func BenchmarkSudoSudoAs(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_sudo_as_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/sudo/call_sudo_as_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

Expand Down
2 changes: 1 addition & 1 deletion runtime/templates/poa/benchmark_sudo_call_sudo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

func BenchmarkSudoSudo(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_sudo_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/sudo/call_sudo_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

Expand Down
2 changes: 1 addition & 1 deletion runtime/templates/poa/benchmark_sudo_remove_key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

func BenchmarkSudoRemoveKey(b *testing.B) {
benchmarking.RunDispatchCall(b, "../frame/sudo/call_remove_key_weight.go", func(i *benchmarking.Instance) {
benchmarking.RunDispatchCall(b, "../../../frame/sudo/call_remove_key_weight.go", func(i *benchmarking.Instance) {
err := (*i.Storage()).Put(append(testhelpers.KeySudoHash, testhelpers.KeyKeyHash...), aliceAddress.AsID.ToBytes())
assert.NoError(b, err)

Expand Down