From 882c6994d244ea38656c6c90fbf2bf1e3981d2b3 Mon Sep 17 00:00:00 2001 From: samalws-tob <129795909+samalws-tob@users.noreply.github.com> Date: Wed, 26 Jun 2024 16:49:59 -0400 Subject: [PATCH] show gas/s (#1279) --- lib/Echidna/Campaign.hs | 3 +++ lib/Echidna/Types/Campaign.hs | 3 +++ lib/Echidna/UI/Widgets.hs | 14 ++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/lib/Echidna/Campaign.hs b/lib/Echidna/Campaign.hs index 1b07cfa1e..83e522733 100644 --- a/lib/Echidna/Campaign.hs +++ b/lib/Echidna/Campaign.hs @@ -137,6 +137,7 @@ runSymWorker callback vm dict workerId initialCorpus name cs = do , newCoverage = False , ncallseqs = 0 , ncalls = 0 + , totalGas = 0 , runningThreads = [] } @@ -213,6 +214,7 @@ runFuzzWorker callback vm world dict workerId initialCorpus testLimit = do , newCoverage = False , ncallseqs = 0 , ncalls = 0 + , totalGas = 0 , runningThreads = [] } @@ -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)])` diff --git a/lib/Echidna/Types/Campaign.hs b/lib/Echidna/Types/Campaign.hs index b59815bd3..158b69f74 100644 --- a/lib/Echidna/Types/Campaign.hs +++ b/lib/Echidna/Types/Campaign.hs @@ -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 @@ -181,6 +183,7 @@ initialWorkerState = , newCoverage = False , ncallseqs = 0 , ncalls = 0 + , totalGas = 0 , runningThreads = [] } diff --git a/lib/Echidna/UI/Widgets.hs b/lib/Echidna/UI/Widgets.hs index 906b1a3a6..6426ef848 100644 --- a/lib/Echidna/UI/Widgets.hs +++ b/lib/Echidna/UI/Widgets.hs @@ -173,6 +173,8 @@ summaryWidget env uiState = <=> perfWidget uiState <=> + gasPerfWidget uiState + <=> str ("Total calls: " <> progress (sum $ (.ncalls) <$> uiState.campaigns) env.cfg.campaignConf.testLimit) middle = @@ -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