Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#5705 closed bug (wontfix)

getGCStats only works with +RTS -s

Reported by: tibbe Owned by:
Priority: normal Milestone:
Component: Runtime System Version: 7.2.1
Keywords: Cc: johan.tibell@…, dterei
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Revisions:

Description (last modified by tibbe)

As the below program shows, GHC.Stats.getGCStats only returns non-zero values for e.g. gc_wall_time if the program is run with +RTS -s. I guess that's because the stats aren't tracked by the GC unless you specify +RTS -s. Are the stats expensive to maintain? If not could we always update these counters?

module Main where

import GHC.Stats
import System.Mem

main = do
    print $ let xs = [1..1000000]  -- allocation
            in fromIntegral (sum xs) / fromIntegral (length xs)
    performGC
    stats <- getGCStats
    putStrLn $ show stats
$ ./Repro
500000.5
GCStats {bytesAllocated = 0, numGcs = 184, maxBytesUsed = 0,
numByteUsageSamples = 0, cumulativeBytesUsed = 0, bytesCopied = 0,
currentBytesUsed = 0, currentBytesSlop = 0, maxBytesSlop = 0,
peakMegabytesAllocated = 63, mutatorCpuSeconds = 9.6468e-2,
mutatorWallSeconds = 0.115874, gcCpuSeconds = 0.0,
gcWallSeconds = 0.0, cpuSeconds = 9.7045e-2, wallSeconds = 0.115874,
parAvgBytesCopied = 0, parMaxBytesCopied = 0}
$ ./Repro +RTS -s
500000.5
GCStats {bytesAllocated = 96086504, numGcs = 184, maxBytesUsed = 27442272,
numByteUsageSamples = 7, cumulativeBytesUsed = 52228768, bytesCopied = 90580024,
currentBytesUsed = 74336, currentBytesSlop = 0, maxBytesSlop = 6803872,
peakMegabytesAllocated = 63, mutatorCpuSeconds = 2.523e-2,
mutatorWallSeconds = 2.5739e-2, gcCpuSeconds = 7.1919e-2,
gcWallSeconds = 9.126e-2, cpuSeconds = 9.7729e-2, wallSeconds = 0.116999,
parAvgBytesCopied = 0, parMaxBytesCopied = 0}
...

Change History (6)

comment:1 Changed 4 years ago by tibbe

  • Description modified (diff)

comment:2 Changed 4 years ago by ezyang

Yes, this is because the information is collected from GC statistics (note that you actually probably want -T, because that results in no extra output.)

I'm pretty sure this is WONTFIX, because GC statistics impose nontrivial overhead. Something that I've been meaning to do but haven't yet is have the function throw an exception if stats are not available.

comment:3 Changed 4 years ago by simonmar

  • difficulty set to Unknown
  • Resolution set to wontfix
  • Status changed from new to closed

I chatted with tibbe on IRC a bit about this yesterday. The conclusion is that

  • you can use +RTS -T, as ezyang noted above
  • you can set this at compile time with -with-rtsopts=-T

which addresses the main issues.

It's possible that we could enable +RTS -T by default, but someone needs to do the measurements to see if the impact is really negligible.

comment:4 Changed 4 years ago by dterei

Can we get the haddock documentation for GHC.Stats update please to include this information?

comment:5 Changed 4 years ago by dterei

  • Cc dterei added

comment:6 Changed 4 years ago by ezyang

I don't know how I failed to do this the first time around.

commit 8020e1e5eba5acf52af3b055422f93a738f95740
Author: Edward Z. Yang <[email protected]>
Date:   Fri Dec 16 14:50:40 2011 -0500

    Document that -T RTS flag is necessary.
    
    Signed-off-by: Edward Z. Yang <[email protected]>
Note: See TracTickets for help on using tickets.