Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show gas per second in the UI #1279

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading