7

24 天的 Hackage 中看到 EKG 后,我尝试在我的一个程序中使用它,但它没有显示我的任何内存分配。

所以我用一个只占用内存的示例程序再次尝试:

{-# LANGUAGE OverloadedStrings #-}
module Main where

import System.Remote.Monitoring (forkServer)
import Control.Applicative ((<$>))
import Control.Monad (foldM, forM_)
import Control.Monad.Primitive (PrimMonad, PrimState)
import Data.Vector.Mutable (MVector, replicate, read, write, length)
import Prelude hiding (read, length, replicate)
import Text.Printf

accumBy :: (Functor m, PrimMonad m) => (a -> a -> a) -> MVector (PrimState m) a -> m a
accumBy f v = do
  a <- read v 0
  foldM (\a i -> do
    a' <- f a <$> read v i
    write v i a'
    return a'
    ) a [1 .. length v - 1]

main :: IO ()
main = do
  forkServer "localhost" 8000
  forM_ [1..] $ \n -> do
    v <- replicate (n*1024) (n :: Int)
    accumBy (+) v >>= printf "%08x\n"

程序运行良好

% ghc --make Temp.hs -rtsopts && ./Temp +RTS -K32mM -RTS
00000400
00001000
00002400
...

但心电图似乎根本没有检测到我的内存使用情况

心电图统计

我究竟做错了什么?

4

1 回答 1

11

您需要使用-Tor -tor or -Sor -s RTS 选项来收集统计信息,例如:

ghc --make Temp.hs -rtsopts && ./Temp +RTS -T -K32mM -RTS
于 2012-12-14T23:38:53.573 回答