Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are there so many backslashes (\) in the *.prof file?

Tags:

haskell

Looking into the *.prof file generated using +RTS -p with profiling enabled compilation, I see a lot of these sub-routines that named \:

COST CENTRE           MODULE                         %time %alloc

main.\.\.\            Main                            74.1   85.8
unstreamChunks/inner  Data.Text.Internal.Lazy.Fusion  11.9    8.6 
inverseLetters.\      Main                             4.5    1.7 
main.\.\.\.(...)      Main                             2.9    1.0 
main.\.\.\.(...)      Main                             2.8    1.0 
unstreamChunks/resize Data.Text.Internal.Lazy.Fusion   1.2    0.8 
unstreamChunks/outer  Data.Text.Internal.Lazy.Fusion   1.1    0.5 

which looks cryptic to me. What do these represent?

like image 389
xzhu Avatar asked Sep 29 '15 07:09

xzhu


1 Answers

Let

import Control.Monad

main = do
    forM_ [1..1000] $ \i ->
        if mod i 2 == 0 then putStrLn "Foo"
                        else print i

and run with

ghc -rtsopts -prof -fprof-auto z.hs && ./z +RTS -p && cat z.prof

then, following rules to set cost centres

COST CENTRE MODULE           %time %alloc
main.\      Main              80.0   84.4
main        Main              20.0   13.2
CAF         GHC.IO.Handle.FD   0.0    2.1

the backslashes show that stack level, you can set names for each one

forM_ [1..1000] $ \i ->
    {-# SCC "myBranch" #-}
    if mod i 2 == 0 then putStrLn "Foo"
                    else print i

and now

COST CENTRE MODULE           %time %alloc
myBranch    Main              90.0   84.4
main        Main              10.0   13.2
CAF         GHC.IO.Handle.FD   0.0    2.1

(Added @trVoldemort comment)

Also, (...) seems to be used for let assignments with computations involved

data T = T Int (IO ()) (IO ())
main =
   forM_ [T (mod i 2) (putStrLn "Foo") (print i) | i <- [1..1000]] $ \q ->
        let T a b c = q -- Will be `(...)`
        in  if a == 0 then b else c

with profile output

main.\        Main
 main.\.b     Main
 main.\.c     Main
 main.\.(...) Main
 main.\.a     Main

with SCC pragma

forM_ [T (mod i 2) (putStrLn "Foo") (print i) | i <- [1..1000]] $ \q ->
     let T a b c = {-# SCC "myBind" #-} q
     in  if a == 0 then b else c

and output

main.\.b     Main
main.\.c     Main
main.\.(...) Main
 myBind      Main
main.\.a     Main
like image 74
josejuan Avatar answered Nov 16 '22 14:11

josejuan