Skip to content

Commit 3a0479e

Browse files
authored
Merge branch 'master' into bastian/add-all-contracts-endpoint
2 parents 358b7f5 + c5cce13 commit 3a0479e

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

emulator/blockchain.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,13 @@ func (conf config) GetServiceKey() ServiceKey {
446446
return serviceKey
447447
}
448448

449+
func (conf config) EffectiveExecutionEffortWeights() meter.ExecutionEffortWeights {
450+
if conf.ExecutionEffortWeights != nil {
451+
return conf.ExecutionEffortWeights
452+
}
453+
return environment.MainnetExecutionEffortWeights
454+
}
455+
449456
const defaultGenesisTokenSupply = "1000000000.0"
450457

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

644-
if conf.ExecutionEffortWeights != nil &&
645-
conf.ComputationProfile != nil {
646-
647-
conf.ComputationProfile.
648-
WithComputationWeights(conf.ExecutionEffortWeights)
651+
if conf.ComputationProfile != nil {
652+
executionEffortWeights := conf.EffectiveExecutionEffortWeights()
653+
conf.ComputationProfile.WithComputationWeights(executionEffortWeights)
649654
}
650655

651656
runtimeConfig := runtime.Config{
@@ -849,16 +854,11 @@ func configureBootstrapProcedure(
849854
fvm.WithTransactionFee(fvm.DefaultTransactionFees),
850855
fvm.WithExecutionMemoryLimit(math.MaxUint32),
851856
fvm.WithExecutionMemoryWeights(meter.DefaultMemoryWeights),
852-
fvm.WithExecutionEffortWeights(environment.MainnetExecutionEffortWeights),
857+
fvm.WithExecutionEffortWeights(conf.EffectiveExecutionEffortWeights()),
853858
fvm.WithSetupVMBridgeEnabled(cadence.NewBool(conf.SetupVMBridgeEnabled)),
854859
fvm.WithSetupEVMEnabled(cadence.NewBool(conf.SetupEVMEnabled)),
855860
)
856861

857-
if conf.ExecutionEffortWeights != nil {
858-
options = append(options,
859-
fvm.WithExecutionEffortWeights(conf.ExecutionEffortWeights),
860-
)
861-
}
862862
if conf.StorageLimitEnabled {
863863
options = append(options,
864864
fvm.WithAccountCreationFee(conf.MinimumStorageReservation),

server/utils/emulator.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net/http"
2525
"slices"
2626
"strconv"
27+
"strings"
2728

2829
"github.com/gorilla/mux"
2930
"github.com/onflow/cadence/common"
@@ -265,17 +266,30 @@ func (m EmulatorAPIServer) ComputationReport(w http.ResponseWriter, _ *http.Requ
265266
}
266267
}
267268

269+
const cadenceFileSuffix = ".cdc"
270+
268271
func (m EmulatorAPIServer) ComputationProfile(w http.ResponseWriter, _ *http.Request) {
272+
w.Header().Set("Content-Disposition", "attachment; filename=profile.pprof")
269273
w.Header().Set("Content-Type", "application/gzip")
270274

271275
computationProfile := m.emulator.ComputationProfile()
276+
if computationProfile == nil {
277+
w.WriteHeader(http.StatusNotFound)
278+
return
279+
}
272280

273281
pprofProfile, err := runtime.NewPProfExporter(computationProfile).Export()
274282
if err != nil {
275283
w.WriteHeader(http.StatusInternalServerError)
276284
return
277285
}
278286

287+
for _, function := range pprofProfile.Function {
288+
if !strings.HasSuffix(function.Filename, cadenceFileSuffix) {
289+
function.Filename += cadenceFileSuffix
290+
}
291+
}
292+
279293
err = pprofProfile.Write(w)
280294
if err != nil {
281295
w.WriteHeader(http.StatusInternalServerError)

0 commit comments

Comments
 (0)