Skip to content

Commit 882c699

Browse files
authored
show gas/s (#1279)
1 parent 2c72579 commit 882c699

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

lib/Echidna/Campaign.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ runSymWorker callback vm dict workerId initialCorpus name cs = do
137137
, newCoverage = False
138138
, ncallseqs = 0
139139
, ncalls = 0
140+
, totalGas = 0
140141
, runningThreads = []
141142
}
142143

@@ -213,6 +214,7 @@ runFuzzWorker callback vm world dict workerId initialCorpus testLimit = do
213214
, newCoverage = False
214215
, ncallseqs = 0
215216
, ncalls = 0
217+
, totalGas = 0
216218
, runningThreads = []
217219
}
218220

@@ -453,6 +455,7 @@ evalSeq vm0 execFunc = go vm0 [] where
453455
[] -> pure ([], vm)
454456
(tx:remainingTxs) -> do
455457
(result, vm') <- execFunc vm tx
458+
modify' $ \workerState -> workerState { totalGas = workerState.totalGas + fromIntegral (vm'.burned - vm.burned) }
456459
-- NOTE: we don't use the intermediate VMs, just the last one. If any of
457460
-- the intermediate VMs are needed, they can be put next to the result
458461
-- of each transaction - `m ([(Tx, result, VM)])`

lib/Echidna/Types/Campaign.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ data WorkerState = WorkerState
168168
-- ^ Number of times the callseq is called
169169
, ncalls :: !Int
170170
-- ^ Number of calls executed while fuzzing
171+
, totalGas :: !Int
172+
-- ^ Total gas consumed while fuzzing
171173
, runningThreads :: [ThreadId]
172174
-- ^ Extra threads currently being run,
173175
-- aside from the main worker thread
@@ -181,6 +183,7 @@ initialWorkerState =
181183
, newCoverage = False
182184
, ncallseqs = 0
183185
, ncalls = 0
186+
, totalGas = 0
184187
, runningThreads = []
185188
}
186189

lib/Echidna/UI/Widgets.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ summaryWidget env uiState =
173173
<=>
174174
perfWidget uiState
175175
<=>
176+
gasPerfWidget uiState
177+
<=>
176178
str ("Total calls: " <> progress (sum $ (.ncalls) <$> uiState.campaigns)
177179
env.cfg.campaignConf.testLimit)
178180
middle =
@@ -234,6 +236,18 @@ perfWidget uiState =
234236
diffLocalTime (fromMaybe uiState.now uiState.timeStopped)
235237
uiState.timeStarted
236238

239+
gasPerfWidget :: UIState -> Widget n
240+
gasPerfWidget uiState =
241+
str $ "Gas/s: " <>
242+
if totalTime > 0
243+
then show $ totalGas `div` totalTime
244+
else "-"
245+
where
246+
totalGas = sum $ (.totalGas) <$> uiState.campaigns
247+
totalTime = round $
248+
diffLocalTime (fromMaybe uiState.now uiState.timeStopped)
249+
uiState.timeStarted
250+
237251
ppSeed :: [WorkerState] -> String
238252
ppSeed campaigns = show (head campaigns).genDict.defSeed
239253

0 commit comments

Comments
 (0)