如何从 Haskell 程序中访问“+RTS -s”或其他内存信息?

How to access "+RTS -s" or other memory information from within a Haskell program?

当运行一个Haskell程序时,+RTS -s 上报"bytes maximum residency"等信息。有没有办法从 Haskell 程序中访问此信息? Hackage 上是否有提供此功能的库?

如果不是,有没有办法访问当前使用的内存量?比如终端命令显示的金额"top"?

查看 GHC.Stats 包中的 getGCStats 函数。

currentBytesUsed 字段将报告最后一次主要 GC 结束时的活动字节数。

另请注意文档中关于必须启用 RTS -T 选项并可能事先调用 performGC 的注释。