Pau*_*icz 8 profiler haskell name-mangling ghc
在分析用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)
Run Code Online (Sandbox Code Playgroud)
我编译-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
Run Code Online (Sandbox Code Playgroud)
在树中,我同样看到(省略不相关的行):
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
Run Code Online (Sandbox Code Playgroud)
我怎么知道这show_an9是Slow实施show而不是Fast?
不,你不能.的_an9和_anx部分是随机生成的.(当我重新编译我得到了_ane和_anC.)
您可以使用SCC(set-cost-center)pragma手动插入成本中心:
data Fast = Fast
instance Show Fast where
show _ = {-# SCC "show(Fast)" #-} show $ sum' [1 .. 10]
data Slow = Slow
instance Show Slow where
show _ = {-# SCC "show(Slow)" #-} show $ sum' [1 .. 100000000]
Run Code Online (Sandbox Code Playgroud)
该档案应显示:
main
show_an9
show(Slow)
sum'
show_anx
show(Fast)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
258 次 |
| 最近记录: |