Skip to content

Instantly share code, notes, and snippets.

@danidiaz
Last active June 6, 2021 18:20
Show Gist options
  • Save danidiaz/824c715816f16fdc43b43ab4a8c437e5 to your computer and use it in GitHub Desktop.
Save danidiaz/824c715816f16fdc43b43ab4a8c437e5 to your computer and use it in GitHub Desktop.
profiling confusion

The profile graphs shows empty :(

 $(cabal list-bin exe:arrayx) +RTS -h -p -N -RTS

RTS options to produce runtime statistics

 $(cabal list-bin exe:arrayx) +RTS -s -RTS     

-T collects the data but produces no output -t produces a single line of output in the same format as GHC’s -Rghc-timing option, -s produces a more detailed summary at the end of the program, and -S additionally produces information about each and every garbage collection.

If you use the -T flag then, you should access the statistics using GHC.Stats.

GHC.Stats

System.Mem.performGC

The GHC Runtime System

cabal-version: 3.4
name: arrayx
version: 0.1.0.0
executable arrayx
main-is: Main.hs
ghc-options: -threaded
build-depends:
base,
array
default-language: Haskell2010
packages: ./*.cabal
profiling: True
package arrayx
profiling-detail: all-functions
{-# LANGUAGE NumDecimals, BangPatterns #-}
module Main where
import Data.Array
import Control.Concurrent
import System.Mem
type A = Array Integer Integer
{-# NOINLINE makea #-}
makea :: Integer -> IO A
makea i = do
let !z = array (1, i) (do
v <- [1..i]
pure (v,v))
in pure z
-- https://tech.channable.com/posts/2020-04-07-lessons-in-managing-haskell-memory.html
-- https://ro-che.info/articles/2020-05-14-visualize-haskell-heap-profiles
-- https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/profiling.html
{-# NOINLINE foo #-}
foo :: A -> IO ()
foo _ = do
performGC
threadDelay 10e6
pure ()
main :: IO ()
main = do
!arr <- makea 100000
performGC
threadDelay 10e6
foo arr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment