cost centres

costs are assigned to cost centres

They are program annotations around expressions, all costs incurred by the annotated expression are assigned to the enclosing cost centre.

GHC will remember the stack of enclosing cost centres for any given expression at run-time and generate a call-tree of cost attributions.

Annotations

Profiling function f:

f = ...
{-# scc f -#}

Doing -fprof-auto will mark ALL bindings (which are not INLINE), INLINE functions have to be manually given a cost centre.

To exploit this you can do some rewrites:

f = <expr1> <args> + <expr2> <args>

Into

f = b1 <args> + b2 <args>
  where
    b1 = expr1
    b2 = expr2