summaryrefslogtreecommitdiff
path: root/ghc
diff options
context:
space:
mode:
authorSimon Marlow <marlowsd@gmail.com>2016-04-15 16:21:56 -0700
committerSimon Marlow <marlowsd@gmail.com>2016-04-26 16:00:43 +0100
commit95f9334aeeebc8708ed89a5d985b6be3e8a3f1da (patch)
treeb580464d9d948c06c9ebbeeedcc4f0f1f2f3e263 /ghc
parente68195a96529cf1cc2d9cc6a9bc05183fce5ecea (diff)
downloadhaskell-95f9334aeeebc8708ed89a5d985b6be3e8a3f1da.tar.gz
GHCi: use real time instead of CPU time for :set -s
CPU time is never very accurate, and it broke completely with -fexternal-interpreter which runs the interpreted computations in a separate process.
Diffstat (limited to 'ghc')
-rw-r--r--ghc/GHCi/UI/Monad.hs16
1 files changed, 8 insertions, 8 deletions
diff --git a/ghc/GHCi/UI/Monad.hs b/ghc/GHCi/UI/Monad.hs
index 824bba17a4..306fa2132f 100644
--- a/ghc/GHCi/UI/Monad.hs
+++ b/ghc/GHCi/UI/Monad.hs
@@ -48,7 +48,7 @@ import Exception
import Numeric
import Data.Array
import Data.IORef
-import System.CPUTime
+import Data.Time
import System.Environment
import System.IO
import Control.Monad
@@ -348,18 +348,18 @@ timeIt getAllocs action
= do b <- lift $ isOptionSet ShowTiming
if not b
then action
- else do time1 <- liftIO $ getCPUTime
+ else do time1 <- liftIO $ getCurrentTime
a <- action
let allocs = getAllocs a
- time2 <- liftIO $ getCPUTime
+ time2 <- liftIO $ getCurrentTime
dflags <- getDynFlags
- liftIO $ printTimes dflags allocs (time2 - time1)
+ let period = time2 `diffUTCTime` time1
+ liftIO $ printTimes dflags allocs (realToFrac period)
return a
-printTimes :: DynFlags -> Maybe Integer -> Integer -> IO ()
-printTimes dflags mallocs psecs
- = do let secs = (fromIntegral psecs / (10^(12::Integer))) :: Float
- secs_str = showFFloat (Just 2) secs
+printTimes :: DynFlags -> Maybe Integer -> Double -> IO ()
+printTimes dflags mallocs secs
+ = do let secs_str = showFFloat (Just 2) secs
putStrLn (showSDoc dflags (
parens (text (secs_str "") <+> text "secs" <> comma <+>
case mallocs of