Demangling typeclass functions in GHC profiler output

Posted by Paul Kuliniewicz on Stack Overflow See other posts from Stack Overflow or by Paul Kuliniewicz
Published on 2010-05-11T00:57:43Z Indexed on 2010/05/11 1:04 UTC
Read the original article Hit count: 287

Filed under:
|
|
|

When profiling a Haskell program written in GHC, the names of typeclass functions are mangled in the .prof file to distinguish one instance's implementations of them from another. How can I demangle these names to find out which type's instance it is?

For example, suppose I have the following program, where types Fast and Slow both implement Show:

import Data.List (foldl')

sum' = foldl' (+) 0

data Fast = Fast
instance Show Fast where
    show _ = show $ sum' [1 .. 10]

data Slow = Slow
instance Show Slow where
    show _ = show $ sum' [1 .. 100000000]

main = putStrLn (show Fast ++ show Slow)

I compile with -prof -auto-all -caf-all and run with +RTS -p. In the .prof file that gets generated, I see that the top cost centers are:

COST CENTRE                    MODULE               %time %alloc

show_an9                       Main                  71.0   83.3
sum'                           Main                  29.0   16.7

And in the tree, I likewise see (omitting irrelevant lines):

                                                individual    inherited
COST CENTRE       MODULE       no.    entries  %time %alloc   %time %alloc

  main            Main         232           1   0.0    0.0   100.0  100.0
   show_an9       Main         235           1  71.0   83.3   100.0  100.0
    sum'          Main         236           0  29.0   16.7    29.0   16.7
   show_anx       Main         233           1   0.0    0.0     0.0    0.0

How do I figure out that show_an9 is Slow's implementation of show and not Fast's?

© Stack Overflow or respective owner

Related posts about haskell

Related posts about ghc