summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-13 16:14:56 +0000
committerBen Gamari <ben@well-typed.com>2020-11-27 17:32:17 -0500
commit383155a2f7c28c7722f9d1574130c60cac709a3a (patch)
treea476f9dc50b42c87a45b3bcd5820b73957887888
parenta1a75aa9be2c133dd1372a08eeb6a92c31688df7 (diff)
downloadhaskell-wip/timings-allocations.tar.gz
withTimings: Emit allocations counterwip/timings-allocations
This will allow us to back out the allocations per compiler pass from the eventlog. Note that we dump the allocation counter rather than the difference since this will allow us to determine how much work is done *between* `withTiming` blocks.
-rw-r--r--compiler/GHC/Utils/Error.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/GHC/Utils/Error.hs b/compiler/GHC/Utils/Error.hs
index 25da8be3de..43c2cae4ad 100644
--- a/compiler/GHC/Utils/Error.hs
+++ b/compiler/GHC/Utils/Error.hs
@@ -536,14 +536,16 @@ withTiming' dflags what force_result prtimings action
logInfo dflags $ withPprStyle defaultUserStyle $
text "***" <+> what <> colon
let ctx = initDefaultSDocContext dflags
- eventBegins ctx what
alloc0 <- liftIO getAllocationCounter
start <- liftIO getCPUTime
+ eventBegins ctx what
+ recordAllocs alloc0
!r <- action
() <- pure $ force_result r
eventEnds ctx what
end <- liftIO getCPUTime
alloc1 <- liftIO getAllocationCounter
+ recordAllocs alloc1
-- recall that allocation counter counts down
let alloc = alloc0 - alloc1
time = realToFrac (end - start) * 1e-9
@@ -569,12 +571,19 @@ withTiming' dflags what force_result prtimings action
else action
where whenPrintTimings = liftIO . when (prtimings == PrintTimings)
+
+ recordAllocs alloc = do
+ liftIO $ traceMarkerIO $ "GHC:allocs:" ++ show alloc
+
eventBegins ctx w = do
- whenPrintTimings $ traceMarkerIO (eventBeginsDoc ctx w)
- liftIO $ traceEventIO (eventBeginsDoc ctx w)
+ let doc = eventBeginsDoc ctx w
+ whenPrintTimings $ traceMarkerIO doc
+ liftIO $ traceEventIO doc
+
eventEnds ctx w = do
- whenPrintTimings $ traceMarkerIO (eventEndsDoc ctx w)
- liftIO $ traceEventIO (eventEndsDoc ctx w)
+ let doc = eventEndsDoc ctx w
+ whenPrintTimings $ traceMarkerIO doc
+ liftIO $ traceEventIO doc
eventBeginsDoc ctx w = showSDocOneLine ctx $ text "GHC:started:" <+> w
eventEndsDoc ctx w = showSDocOneLine ctx $ text "GHC:finished:" <+> w