Skip to content

Cost centres registered after the program begins are missing from the eventlog

On initialization, the RTS dumps all registered cost centres to the eventlog (dumpCostCentresToEventLog), and if code is loaded after that point, any cost centres it registers won’t be included. This can be observed by compiling code that uses Template Haskell using a profiled GHC:

module A where

mkBigList :: Int -> [Int]
mkBigList x = {-# SCC "A.mkBigList" #-} go x
  where
    go 0 = []
    go x = x : go (x - 1)
{-# LANGUAGE TemplateHaskell #-}
module B where

import Control.Exception (evaluate)
import GHC.Profiling (requestHeapCensus)
import Language.Haskell.TH.Syntax (lift, runIO)
import System.Mem (performMajorGC)
import A

bigList :: [Int]
bigList = $(do let x = mkBigList 10000
               runIO $ do
                 evaluate (length x)
                 requestHeapCensus
                 performMajorGC
               lift x)
$ ghc -prof A B +RTS -l-a -hc -RTS

The .hp heap profile includes a sample that mentions mkBigList, but that cost centre’s definition is absent from the generated eventlog. Consequently, there is a HEAP_PROF_SAMPLE_COST_CENTRE event that includes a cost centre number without any corresponding definition. The RTS should probably keep track of how many cost centres have already been emitted to the eventlog and dump any that have been newly registered before writing a new heap sample.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information