From 950c08d0fd490f43a673c1bf5af124ecadcbe880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 6 Nov 2025 17:01:17 -0800 Subject: [PATCH 1/2] fix setting execution effort weights for computation profiling --- emulator/blockchain.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/emulator/blockchain.go b/emulator/blockchain.go index 6b3a39ab..9750f570 100644 --- a/emulator/blockchain.go +++ b/emulator/blockchain.go @@ -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 @@ -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{ @@ -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), From 9cb537644298cac9c6657fee42d3b79b1e7529e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Thu, 6 Nov 2025 17:01:57 -0800 Subject: [PATCH 2/2] improve computation profile endpoint --- server/utils/emulator.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/server/utils/emulator.go b/server/utils/emulator.go index d0a58b1f..f3c35288 100644 --- a/server/utils/emulator.go +++ b/server/utils/emulator.go @@ -23,6 +23,7 @@ import ( "net/http" "slices" "strconv" + "strings" "github.com/gorilla/mux" "github.com/onflow/cadence/runtime" @@ -261,10 +262,17 @@ 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 { @@ -272,6 +280,12 @@ func (m EmulatorAPIServer) ComputationProfile(w http.ResponseWriter, _ *http.Req 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)