Skip to content

Commit c5cce13

Browse files
authored
Merge pull request #904 from onflow/bastian/fix-computation-profiling
Fix and improve computation profiling
2 parents 1310af4 + 9cb5376 commit c5cce13

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
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424
"slices"
2525
"strconv"
26+
"strings"
2627

2728
"github.com/gorilla/mux"
2829
"github.com/onflow/cadence/runtime"
@@ -261,17 +262,30 @@ func (m EmulatorAPIServer) ComputationReport(w http.ResponseWriter, _ *http.Requ
261262
}
262263
}
263264

265+
const cadenceFileSuffix = ".cdc"
266+
264267
func (m EmulatorAPIServer) ComputationProfile(w http.ResponseWriter, _ *http.Request) {
268+
w.Header().Set("Content-Disposition", "attachment; filename=profile.pprof")
265269
w.Header().Set("Content-Type", "application/gzip")
266270

267271
computationProfile := m.emulator.ComputationProfile()
272+
if computationProfile == nil {
273+
w.WriteHeader(http.StatusNotFound)
274+
return
275+
}
268276

269277
pprofProfile, err := runtime.NewPProfExporter(computationProfile).Export()
270278
if err != nil {
271279
w.WriteHeader(http.StatusInternalServerError)
272280
return
273281
}
274282

283+
for _, function := range pprofProfile.Function {
284+
if !strings.HasSuffix(function.Filename, cadenceFileSuffix) {
285+
function.Filename += cadenceFileSuffix
286+
}
287+
}
288+
275289
err = pprofProfile.Write(w)
276290
if err != nil {
277291
w.WriteHeader(http.StatusInternalServerError)

0 commit comments

Comments
 (0)