Profiling report broken with foreign exported functions
Save the following Haskell source as wrapper.hs:
import Foreign.Ptr
import Control.Monad
main = do
fptr <- wrap wrapped
replicateM 100 $ (return$!) =<< dyn fptr 4
wrapped :: Double -> IO Double
wrapped x = return $ f 10000 x
f :: Int -> Double -> Double
f 0 u = u
f n u = (u / fromIntegral n) * f (n-1) u
foreign import ccall "wrapper" wrap :: (Double -> IO Double) -> IO (FunPtr (Double -> IO Double))
foreign import ccall "dynamic" dyn :: FunPtr (Double -> IO Double) -> Double -> IO Double
Then compile and run it with:
$ ghc -O2 wrapper.hs -fprof-auto -prof
$ ./wrapper +RTS -p
It generates wrapper.prof (attached). The file contains the following lines:
CAF GHC.IO.Encoding.Iconv 58 0 0.0 0.2 0.0 0.2
wrapped Main 80 100 0.0 1.1 0.0 0.0
f Main 81 1000100 100.0 0.0 0.0 0.0
I see two problems here, (1) the inherited column is 0 for 'wrapped' and 'f' but this is incorrect, and (2) 'wrapped' and 'f' belongs to the wrong cost center, 'GHC.IO.Encoding.Iconv'.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.6.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Profiling |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |