Haskell / GHC能否自行报告其GC统计数据?

时间:2022-07-03 17:03:15

I'm thinking that having a server to self-report its memory usage would be handy.

我认为让服务器自我报告其内存使用情况会很方便。

I have read the section on memory profiling in the manual, but there are a few drawbacks with this:

我已经阅读了手册中关于内存分析的部分,但是有一些缺点:

  • First this seems to give only post-mortem stats.
  • 首先,这似乎只给出了验尸统计数据。

  • There is an overhead associated with enabling profiling.
  • 启用性能分析会产生开销。

  • I don't really need that much detail.
  • 我真的不需要那么多细节。

So that's my question, how can one track the different sets of memory in a running program compiled by GHC?

这就是我的问题,如何在GHC编译的正在运行的程序中跟踪不同的内存集?

2 个解决方案

#1


The GHC-specific module GHC.Stats provides a function getGCStats whichs returns (in IO) various GC statistics:

GHC特定模块GHC.Stats提供了一个函数getGCStats,它返回(在IO中)各种GC统计信息:

getGCStats :: IO GCStats

Retrieves garbage collection and memory statistics as of the last garbage collection. If you would like your statistics as recent as possible, first run a performGC.

检索上次垃圾回收中的垃圾收集和内存统计信息。如果您希望尽可能使用最新统计信息,请先运行performGC。

#2


If you integrate ekg into your server, you can access nice graphs and statistics about the runtime and even your own custom metrics via HTTP:

如果将ekg集成到服务器中,您可以通过HTTP访问有关运行时的精美图表和统计信息,甚至是您自己的自定义指标:

Haskell / GHC能否自行报告其GC统计数据?

(Image linked from Oliver Charles’ blogpost on ekg)

(图片链接自Oliver Charles在ekg上的博文)

#1


The GHC-specific module GHC.Stats provides a function getGCStats whichs returns (in IO) various GC statistics:

GHC特定模块GHC.Stats提供了一个函数getGCStats,它返回(在IO中)各种GC统计信息:

getGCStats :: IO GCStats

Retrieves garbage collection and memory statistics as of the last garbage collection. If you would like your statistics as recent as possible, first run a performGC.

检索上次垃圾回收中的垃圾收集和内存统计信息。如果您希望尽可能使用最新统计信息,请先运行performGC。

#2


If you integrate ekg into your server, you can access nice graphs and statistics about the runtime and even your own custom metrics via HTTP:

如果将ekg集成到服务器中,您可以通过HTTP访问有关运行时的精美图表和统计信息,甚至是您自己的自定义指标:

Haskell / GHC能否自行报告其GC统计数据?

(Image linked from Oliver Charles’ blogpost on ekg)

(图片链接自Oliver Charles在ekg上的博文)