Skip to content

Commit

Permalink
show gas/s (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
samalws-tob authored Jun 26, 2024
1 parent 2c72579 commit 882c699
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Echidna/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ runSymWorker callback vm dict workerId initialCorpus name cs = do
, newCoverage = False
, ncallseqs = 0
, ncalls = 0
, totalGas = 0
, runningThreads = []
}

Expand Down Expand Up @@ -213,6 +214,7 @@ runFuzzWorker callback vm world dict workerId initialCorpus testLimit = do
, newCoverage = False
, ncallseqs = 0
, ncalls = 0
, totalGas = 0
, runningThreads = []
}

Expand Down Expand Up @@ -453,6 +455,7 @@ evalSeq vm0 execFunc = go vm0 [] where
[] -> pure ([], vm)
(tx:remainingTxs) -> do
(result, vm') <- execFunc vm tx
modify' $ \workerState -> workerState { totalGas = workerState.totalGas + fromIntegral (vm'.burned - vm.burned) }
-- NOTE: we don't use the intermediate VMs, just the last one. If any of
-- the intermediate VMs are needed, they can be put next to the result
-- of each transaction - `m ([(Tx, result, VM)])`
Expand Down
3 changes: 3 additions & 0 deletions lib/Echidna/Types/Campaign.hs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ data WorkerState = WorkerState
-- ^ Number of times the callseq is called
, ncalls :: !Int
-- ^ Number of calls executed while fuzzing
, totalGas :: !Int
-- ^ Total gas consumed while fuzzing
, runningThreads :: [ThreadId]
-- ^ Extra threads currently being run,
-- aside from the main worker thread
Expand All @@ -181,6 +183,7 @@ initialWorkerState =
, newCoverage = False
, ncallseqs = 0
, ncalls = 0
, totalGas = 0
, runningThreads = []
}

Expand Down
14 changes: 14 additions & 0 deletions lib/Echidna/UI/Widgets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ summaryWidget env uiState =
<=>
perfWidget uiState
<=>
gasPerfWidget uiState
<=>
str ("Total calls: " <> progress (sum $ (.ncalls) <$> uiState.campaigns)
env.cfg.campaignConf.testLimit)
middle =
Expand Down Expand Up @@ -234,6 +236,18 @@ perfWidget uiState =
diffLocalTime (fromMaybe uiState.now uiState.timeStopped)
uiState.timeStarted

gasPerfWidget :: UIState -> Widget n
gasPerfWidget uiState =
str $ "Gas/s: " <>
if totalTime > 0
then show $ totalGas `div` totalTime
else "-"
where
totalGas = sum $ (.totalGas) <$> uiState.campaigns
totalTime = round $
diffLocalTime (fromMaybe uiState.now uiState.timeStopped)
uiState.timeStarted

ppSeed :: [WorkerState] -> String
ppSeed campaigns = show (head campaigns).genDict.defSeed

Expand Down

0 comments on commit 882c699

Please sign in to comment.