【发布时间】:2011-02-17 22:38:11
【问题描述】:
在分析用 GHC 编写的 Haskell 程序时,类型类函数的名称会在 .prof 文件中进行修改,以区分一个实例的实现与另一个实例的实现。我怎样才能解开这些名称以找出它是哪种类型的实例?
例如,假设我有以下程序,其中类型Fast 和Slow 都实现了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)
我使用-prof -auto-all -caf-all 编译并使用+RTS -p 运行。在生成的 .prof 文件中,我看到最高成本中心是:
COST CENTRE MODULE %time %alloc
show_an9 Main 71.0 83.3
sum' Main 29.0 16.7
在树中,我同样看到(省略不相关的行):
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
我如何确定show_an9 是Slow 的show 实现而不是Fast 的实现?
【问题讨论】:
标签: haskell profiler ghc name-mangling