在Hackage的24天内看到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"
Run Code Online (Sandbox Code Playgroud)
程序运行正常
% ghc --make Temp.hs -rtsopts && ./Temp +RTS -K32mM -RTS
00000400
00001000
00002400
...
Run Code Online (Sandbox Code Playgroud)
但是EKG似乎根本没有检测到我的内存使用情况

我究竟做错了什么?
Fed*_*lev 11
您需要使用-T或-t或-S或-s RTS选项来收集统计信息,例如:
ghc --make Temp.hs -rtsopts && ./Temp +RTS -T -K32mM -RTS
Run Code Online (Sandbox Code Playgroud)