Skip to content
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
22 changes: 11 additions & 11 deletions emulator/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,13 @@ func (conf config) GetServiceKey() ServiceKey {
return serviceKey
}

func (conf config) EffectiveExecutionEffortWeights() meter.ExecutionEffortWeights {
if conf.ExecutionEffortWeights != nil {
return conf.ExecutionEffortWeights
}
return environment.MainnetExecutionEffortWeights
}

const defaultGenesisTokenSupply = "1000000000.0"

const defaultScriptGasLimit = 100000
Expand Down Expand Up @@ -641,11 +648,9 @@ func configureFVM(blockchain *Blockchain, conf config, blocks *blocks) (*fvm.Vir
}).
Level(zerolog.DebugLevel)

if conf.ExecutionEffortWeights != nil &&
conf.ComputationProfile != nil {

conf.ComputationProfile.
WithComputationWeights(conf.ExecutionEffortWeights)
if conf.ComputationProfile != nil {
executionEffortWeights := conf.EffectiveExecutionEffortWeights()
conf.ComputationProfile.WithComputationWeights(executionEffortWeights)
}

runtimeConfig := runtime.Config{
Expand Down Expand Up @@ -849,16 +854,11 @@ func configureBootstrapProcedure(
fvm.WithTransactionFee(fvm.DefaultTransactionFees),
fvm.WithExecutionMemoryLimit(math.MaxUint32),
fvm.WithExecutionMemoryWeights(meter.DefaultMemoryWeights),
fvm.WithExecutionEffortWeights(environment.MainnetExecutionEffortWeights),
fvm.WithExecutionEffortWeights(conf.EffectiveExecutionEffortWeights()),
fvm.WithSetupVMBridgeEnabled(cadence.NewBool(conf.SetupVMBridgeEnabled)),
fvm.WithSetupEVMEnabled(cadence.NewBool(conf.SetupEVMEnabled)),
)

if conf.ExecutionEffortWeights != nil {
options = append(options,
fvm.WithExecutionEffortWeights(conf.ExecutionEffortWeights),
)
}
if conf.StorageLimitEnabled {
options = append(options,
fvm.WithAccountCreationFee(conf.MinimumStorageReservation),
Expand Down
14 changes: 14 additions & 0 deletions server/utils/emulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"net/http"
"slices"
"strconv"
"strings"

"github.com/gorilla/mux"
"github.com/onflow/cadence/runtime"
Expand Down Expand Up @@ -261,17 +262,30 @@ func (m EmulatorAPIServer) ComputationReport(w http.ResponseWriter, _ *http.Requ
}
}

const cadenceFileSuffix = ".cdc"

func (m EmulatorAPIServer) ComputationProfile(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Disposition", "attachment; filename=profile.pprof")
w.Header().Set("Content-Type", "application/gzip")

computationProfile := m.emulator.ComputationProfile()
if computationProfile == nil {
w.WriteHeader(http.StatusNotFound)
return
}

pprofProfile, err := runtime.NewPProfExporter(computationProfile).Export()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

for _, function := range pprofProfile.Function {
if !strings.HasSuffix(function.Filename, cadenceFileSuffix) {
function.Filename += cadenceFileSuffix
}
}

err = pprofProfile.Write(w)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
Loading