Skip to content

Commit

Permalink
withTiming: take startTime explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
9999years committed Sep 30, 2024
1 parent a10a2a3 commit 37cfe85
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cabal-validate/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ runStep opts step = do
SolverBenchmarksTests -> solverBenchmarksTests opts
SolverBenchmarksRun -> solverBenchmarksRun opts
TimeSummary -> timeSummary opts
withTiming opts title action
withTiming (startTime opts) title action
T.putStrLn ""

-- | Compiler with version number like @ghc-9.6.6@.
Expand Down
11 changes: 5 additions & 6 deletions cabal-validate/src/OutputUtil.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import qualified System.Console.Terminal.Size as Terminal
import System.Process.Typed (ExitCodeException)

import ANSI (SGR (BoldCyan, BoldGreen, BoldRed, Reset), setSGR)
import Cli (Opts (..))
import ClockUtil (diffAbsoluteTime, formatDiffTime, getAbsoluteTime)
import ClockUtil (AbsoluteTimediffAbsoluteTime, formatDiffTime, getAbsoluteTime)
import System.Exit (exitFailure)

-- | Get the width of the current terminal, or 80 if no width can be determined.
Expand Down Expand Up @@ -40,16 +39,16 @@ printHeader title = do

-- | Run an `IO` action and print duration information after it finishes.
withTiming
:: Opts
-- ^ @cabal-validate@ options.
:: AbsoluteTime
-- ^ Start time for the whole @cabal-validate@ run.
-> String
-- ^ Name for describing the action.
--
-- Used in a sentence like "@title@ finished after 16.34s".
-> IO a
-- ^ Action to time.
-> IO a
withTiming opts title action = do
withTiming startTime title action = do
startTime' <- getAbsoluteTime

result <-
Expand All @@ -59,7 +58,7 @@ withTiming opts title action = do
endTime <- getAbsoluteTime

let duration = diffAbsoluteTime endTime startTime'
totalDuration = diffAbsoluteTime endTime (startTime opts)
totalDuration = diffAbsoluteTime endTime startTime

case result of
Right inner -> do
Expand Down

0 comments on commit 37cfe85

Please sign in to comment.