From 7a259eb77a41669fa66cc7e88babd5c54ba61f34 Mon Sep 17 00:00:00 2001 From: Ardit Marku Date: Wed, 13 Mar 2024 16:24:41 +0200 Subject: [PATCH] Change naming from computation profiling to computation report for types and variables --- README.md | 12 ++++----- cmd/emulator/start/start.go | 4 +-- emulator/blockchain.go | 26 +++++++++---------- ...ation_profile.go => computation_report.go} | 24 +++++++++-------- ...ile_test.go => computation_report_test.go} | 24 ++++++++--------- emulator/emulator.go | 6 ++--- emulator/mocks/emulator.go | 14 +++++----- server/server.go | 8 +++--- server/utils/emulator.go | 6 ++--- 9 files changed, 63 insertions(+), 61 deletions(-) rename emulator/{computation_profile.go => computation_report.go} (91%) rename emulator/{computation_profile_test.go => computation_report_test.go} (87%) diff --git a/README.md b/README.md index e9da2c40..610086fa 100644 --- a/README.md +++ b/README.md @@ -72,7 +72,7 @@ and if you plan to run the emulator with Docker you must use the environment var | `--redis-url` | `FLOW_REDIS_URL` | '' | Redis-server URL for persisting redis storage backend ( `redis://[[username:]password@]host[:port][/database]` ) | | `--start-block-height` | `FLOW_STARTBLOCKHEIGHT` | `0` | Start block height to use when starting the network using 'testnet' or 'mainnet' as the chain-id | | `--legacy-upgrade` | `FLOW_LEGACYUPGRADE` | `false` | Enable upgrading of legacy contracts | -| `--computation-profiling` | `FLOW_COMPUTATIONPROFILING` | `false` | Enable reporting of computation profiles for Cadence scripts & transactions | +| `--computation-reporting` | `FLOW_COMPUTATIONREPORTING` | `false` | Enable computation reporting for Cadence scripts & transactions | ## Running the emulator with the Flow CLI @@ -202,16 +202,16 @@ To get better reports with source file references, you can utilize the `sourceFi #sourceFile("scripts/myScript.cdc") ``` -## Cadence Computation Profiling +## Cadence Computation Reporting -The admin API includes an endpoint for viewing the Cadence computation profiles for scripts & transactions. +The admin API includes an endpoint for viewing the Cadence computation reports for scripts & transactions. -In order to use this functionality you need to run the emulator with the respective flag which enables computation profiling: +In order to use this functionality you need to run the emulator with the respective flag which enables computation reporting: ```bash -flow emulator --computation-profiling +flow emulator --computation-reporting ``` -To view the computation profiling report, visit this URL: http://localhost:8080/emulator/profiling +To view the computation report, visit this URL: http://localhost:8080/emulator/computationReport ## Running the emulator with Docker diff --git a/cmd/emulator/start/start.go b/cmd/emulator/start/start.go index 38e96487..a99bff83 100644 --- a/cmd/emulator/start/start.go +++ b/cmd/emulator/start/start.go @@ -74,7 +74,7 @@ type Config struct { SqliteURL string `default:"" flag:"sqlite-url" info:"sqlite db URL for persisting sqlite storage backend "` CoverageReportingEnabled bool `default:"false" flag:"coverage-reporting" info:"enable Cadence code coverage reporting"` LegacyContractUpgradeEnabled bool `default:"false" flag:"legacy-upgrade" info:"enable Cadence legacy contract upgrade"` - ComputationProfilingEnabled bool `default:"false" flag:"computation-profiling" info:"enable Cadence computation profiling"` + ComputationReportingEnabled bool `default:"false" flag:"computation-reporting" info:"enable Cadence computation reporting"` // todo temporarily disabled until remote register endpoint is re-enabled // StartBlockHeight uint64 `default:"0" flag:"start-block-height" info:"block height to start the emulator at. only valid when forking Mainnet or Testnet"` } @@ -202,7 +202,7 @@ func Cmd(getServiceKey serviceKeyFunc) *cobra.Command { SqliteURL: conf.SqliteURL, CoverageReportingEnabled: conf.CoverageReportingEnabled, LegacyContractUpgradeEnabled: conf.LegacyContractUpgradeEnabled, - ComputationProfilingEnabled: conf.ComputationProfilingEnabled, + ComputationReportingEnabled: conf.ComputationReportingEnabled, // todo temporarily disabled until remote register endpoint is re-enabled // StartBlockHeight: conf.StartBlockHeight, } diff --git a/emulator/blockchain.go b/emulator/blockchain.go index 557071a6..9bbc5a70 100644 --- a/emulator/blockchain.go +++ b/emulator/blockchain.go @@ -95,7 +95,7 @@ func New(opts ...Option) (*Blockchain, error) { clock: NewSystemClock(), sourceFileMap: make(map[common.Location]string), entropyProvider: &blockHashEntropyProvider{}, - computationProfile: &ComputationProfile{ + computationReport: &ComputationReport{ Scripts: make(map[string]ProcedureReport), Transactions: make(map[string]ProcedureReport), }, @@ -304,9 +304,9 @@ func WithCoverageReport(coverageReport *runtime.CoverageReport) Option { } } -func WithComputationProfiling(enabled bool) Option { +func WithComputationReporting(enabled bool) Option { return func(c *config) { - c.ComputationProfilingEnabled = enabled + c.ComputationReportingEnabled = enabled } } @@ -353,8 +353,8 @@ type Blockchain struct { sourceFileMap map[common.Location]string - entropyProvider *blockHashEntropyProvider - computationProfile *ComputationProfile + entropyProvider *blockHashEntropyProvider + computationReport *ComputationReport } // config is a set of configuration options for an emulated emulator. @@ -379,7 +379,7 @@ type config struct { CoverageReport *runtime.CoverageReport AutoMine bool Contracts []ContractDescription - ComputationProfilingEnabled bool + ComputationReportingEnabled bool } func (conf config) GetStore() storage.Store { @@ -439,7 +439,7 @@ var defaultConfig = func() config { ChainID: flowgo.Emulator, CoverageReport: nil, AutoMine: false, - ComputationProfilingEnabled: false, + ComputationReportingEnabled: false, } }() @@ -1297,12 +1297,12 @@ func (b *Blockchain) executeNextTransaction(ctx fvm.Context) (*types.Transaction b.sourceFileMap[location] = sourceFile } - if b.conf.ComputationProfilingEnabled { + if b.conf.ComputationReportingEnabled { arguments := make([]string, 0) for _, argument := range txnBody.Arguments { arguments = append(arguments, string(argument)) } - b.computationProfile.ReportTransaction( + b.computationReport.ReportTransaction( tr, b.currentCode, arguments, @@ -1537,12 +1537,12 @@ func (b *Blockchain) executeScriptAtBlockID(script []byte, arguments [][]byte, i MemoryEstimate: output.MemoryEstimate, } - if b.conf.ComputationProfilingEnabled { + if b.conf.ComputationReportingEnabled { scriptArguments := make([]string, 0) for _, argument := range arguments { scriptArguments = append(scriptArguments, string(argument)) } - b.computationProfile.ReportScript( + b.computationReport.ReportScript( scriptResult, b.currentCode, scriptArguments, @@ -1648,8 +1648,8 @@ func (b *Blockchain) CoverageReport() *runtime.CoverageReport { return b.coverageReportedRuntime.CoverageReport } -func (b *Blockchain) ComputationProfile() *ComputationProfile { - return b.computationProfile +func (b *Blockchain) ComputationReport() *ComputationReport { + return b.computationReport } func (b *Blockchain) ResetCoverageReport() { diff --git a/emulator/computation_profile.go b/emulator/computation_report.go similarity index 91% rename from emulator/computation_profile.go rename to emulator/computation_report.go index 8720f138..3c6c214e 100644 --- a/emulator/computation_profile.go +++ b/emulator/computation_report.go @@ -26,20 +26,22 @@ import ( ) type ProcedureReport struct { - ID string `json:"ID"` - ComputationUsed uint64 `json:"computation"` - Intensities map[string]uint `json:"intensities"` - MemoryEstimate uint64 `json:"memory"` - Code string `json:"source"` - Arguments []string `json:"arguments"` + ID string `json:"ID"` + ComputationUsed uint64 `json:"computation"` + // To get the computation from the intensities map, see: + // https://github.com/onflow/flow-go/blob/master/fvm/meter/computation_meter.go#L32-L39 + Intensities map[string]uint `json:"intensities"` + MemoryEstimate uint64 `json:"memory"` + Code string `json:"source"` + Arguments []string `json:"arguments"` } -type ComputationProfile struct { +type ComputationReport struct { Scripts map[string]ProcedureReport `json:"scripts"` Transactions map[string]ProcedureReport `json:"transactions"` } -func (cp *ComputationProfile) ReportScript( +func (cr *ComputationReport) ReportScript( scriptResult *types.ScriptResult, code string, arguments []string, @@ -53,10 +55,10 @@ func (cp *ComputationProfile) ReportScript( Code: code, Arguments: arguments, } - cp.Scripts[scriptResult.ScriptID.String()] = scriptReport + cr.Scripts[scriptResult.ScriptID.String()] = scriptReport } -func (cp *ComputationProfile) ReportTransaction( +func (cr *ComputationReport) ReportTransaction( txResult *types.TransactionResult, code string, arguments []string, @@ -70,7 +72,7 @@ func (cp *ComputationProfile) ReportTransaction( Code: code, Arguments: arguments, } - cp.Transactions[txResult.TransactionID.String()] = txReport + cr.Transactions[txResult.TransactionID.String()] = txReport } // transformIntensities maps a numeric common.ComputationKind value diff --git a/emulator/computation_profile_test.go b/emulator/computation_report_test.go similarity index 87% rename from emulator/computation_profile_test.go rename to emulator/computation_report_test.go index 321d82c4..1be6ce5c 100644 --- a/emulator/computation_profile_test.go +++ b/emulator/computation_report_test.go @@ -33,12 +33,12 @@ import ( "github.com/onflow/flow-emulator/emulator" ) -func TestComputationProfileForScript(t *testing.T) { +func TestComputationReportingForScript(t *testing.T) { t.Parallel() b, err := emulator.New( - emulator.WithComputationProfiling(true), + emulator.WithComputationReporting(true), ) require.NoError(t, err) @@ -75,11 +75,11 @@ func TestComputationProfileForScript(t *testing.T) { require.NoError(t, err) assert.Equal(t, cadence.NewInt(0), scriptResult.Value) - computationProfile := b.ComputationProfile() - require.NotNil(t, computationProfile) - require.Len(t, computationProfile.Scripts, 1) + computationReport := b.ComputationReport() + require.NotNil(t, computationReport) + require.Len(t, computationReport.Scripts, 1) - scriptProfile := computationProfile.Scripts[scriptResult.ScriptID.String()] + scriptProfile := computationReport.Scripts[scriptResult.ScriptID.String()] assert.Equal(t, scriptResult.ScriptID.String(), scriptProfile.ID) assert.Equal(t, uint64(2), scriptProfile.ComputationUsed) @@ -95,12 +95,12 @@ func TestComputationProfileForScript(t *testing.T) { } } -func TestComputationProfileForTransaction(t *testing.T) { +func TestComputationReportingForTransaction(t *testing.T) { t.Parallel() b, err := emulator.New( - emulator.WithComputationProfiling(true), + emulator.WithComputationReporting(true), ) require.NoError(t, err) @@ -130,13 +130,13 @@ func TestComputationProfileForTransaction(t *testing.T) { require.NoError(t, err) AssertTransactionSucceeded(t, txResult) - computationProfile := b.ComputationProfile() - require.NotNil(t, computationProfile) + computationReport := b.ComputationReport() + require.NotNil(t, computationReport) // The 1st transaction creates a new account and deploys the Counting contract. // The 2nd transaction interacts with the Counting contract. - require.Len(t, computationProfile.Transactions, 2) + require.Len(t, computationReport.Transactions, 2) - txProfile := computationProfile.Transactions[txResult.TransactionID.String()] + txProfile := computationReport.Transactions[txResult.TransactionID.String()] assert.Equal(t, tx.ID().String(), txProfile.ID) assert.Equal(t, uint64(57), txProfile.ComputationUsed) diff --git a/emulator/emulator.go b/emulator/emulator.go index ef174c7d..1679b92e 100644 --- a/emulator/emulator.go +++ b/emulator/emulator.go @@ -100,8 +100,8 @@ type CoverageReportCapable interface { ResetCoverageReport() } -type ComputationProfileCapable interface { - ComputationProfile() *ComputationProfile +type ComputationReportCapable interface { + ComputationReport() *ComputationReport } type DebuggingCapable interface { @@ -180,7 +180,7 @@ type Emulator interface { AccessProvider CoverageReportCapable - ComputationProfileCapable + ComputationReportCapable DebuggingCapable SnapshotCapable RollbackCapable diff --git a/emulator/mocks/emulator.go b/emulator/mocks/emulator.go index 26454ac6..029a02bc 100644 --- a/emulator/mocks/emulator.go +++ b/emulator/mocks/emulator.go @@ -69,18 +69,18 @@ func (mr *MockEmulatorMockRecorder) CommitBlock() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CommitBlock", reflect.TypeOf((*MockEmulator)(nil).CommitBlock)) } -// ComputationProfile mocks base method. -func (m *MockEmulator) ComputationProfile() *emulator.ComputationProfile { +// ComputationReport mocks base method. +func (m *MockEmulator) ComputationReport() *emulator.ComputationReport { m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "ComputationProfile") - ret0, _ := ret[0].(*emulator.ComputationProfile) + ret := m.ctrl.Call(m, "ComputationReport") + ret0, _ := ret[0].(*emulator.ComputationReport) return ret0 } -// ComputationProfile indicates an expected call of ComputationProfile. -func (mr *MockEmulatorMockRecorder) ComputationProfile() *gomock.Call { +// ComputationReport indicates an expected call of ComputationReport. +func (mr *MockEmulatorMockRecorder) ComputationReport() *gomock.Call { mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ComputationProfile", reflect.TypeOf((*MockEmulator)(nil).ComputationProfile)) + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ComputationReport", reflect.TypeOf((*MockEmulator)(nil).ComputationReport)) } // CoverageReport mocks base method. diff --git a/server/server.go b/server/server.go index 33fb54f9..1a009e90 100644 --- a/server/server.go +++ b/server/server.go @@ -139,8 +139,8 @@ type Config struct { LegacyContractUpgradeEnabled bool // StartBlockHeight is the height at which to start the emulator. StartBlockHeight uint64 - // ComputationProfilingEnabled enables/disables Cadence computation profiling. - ComputationProfilingEnabled bool + // ComputationReportingEnabled enables/disables Cadence computation reporting. + ComputationReportingEnabled bool } type listener interface { @@ -416,10 +416,10 @@ func configureBlockchain(logger *zerolog.Logger, conf *Config, store storage.Sto ) } - if conf.ComputationProfilingEnabled { + if conf.ComputationReportingEnabled { options = append( options, - emulator.WithComputationProfiling(true), + emulator.WithComputationReporting(true), ) } diff --git a/server/utils/emulator.go b/server/utils/emulator.go index 55987045..676948d8 100644 --- a/server/utils/emulator.go +++ b/server/utils/emulator.go @@ -65,7 +65,7 @@ func NewEmulatorAPIServer(emulator emulator.Emulator, adapter *adapters.AccessAd router.HandleFunc("/emulator/codeCoverage", r.CodeCoverage).Methods("GET") router.HandleFunc("/emulator/codeCoverage/reset", r.ResetCodeCoverage).Methods("PUT") - router.HandleFunc("/emulator/profiling", r.ComputationProfiling).Methods("GET") + router.HandleFunc("/emulator/computationReport", r.ComputationReport).Methods("GET") return r } @@ -241,10 +241,10 @@ func (m EmulatorAPIServer) CodeCoverage(w http.ResponseWriter, r *http.Request) } } -func (m EmulatorAPIServer) ComputationProfiling(w http.ResponseWriter, r *http.Request) { +func (m EmulatorAPIServer) ComputationReport(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - err := json.NewEncoder(w).Encode(m.emulator.ComputationProfile()) + err := json.NewEncoder(w).Encode(m.emulator.ComputationReport()) if err != nil { w.WriteHeader(http.StatusInternalServerError) return