如何描述图书馆?

时间:2014-11-19 11:13:21

标签: haskell cabal

是否有任何隐藏选项将成本中心放入图书馆?目前我已经设置了这样的分析:

小集团:

ghc-prof-options:    -O2                                                                                                                                                                                                                   
                    -threaded                                                                                                                                                                                                             
                    -fexcess-precision                                                                                                                                                                                                    
                    -fprof-auto                                                                                                                                                                                                                                                                                                                                                                                                                     
                    -rtsopts                                                                                                                                                                                                              
                    "-with-rtsopts=-N -p -s -h -i0.1"        

EXEC:

# cabal sandbox init
# cabal install --enable-library-profiling --enable-executable-profiling
# cabal configure --enable-library-profiling --enable-executable-profiling
# cabal run

这可以在程序完成时创建预期的.prof文件,.hp文件和摘要。

问题是.prof文件不包含任何不属于当前项目的内容。我的猜测是,可能有一个选项可以将成本中心放在外部库代码中吗?

2 个答案:

答案 0 :(得分:4)

  

我的猜测是,可能有一个选项会将成本中心放在外部库代码中?

嗯,不是默认的。编译依赖项时需要添加成本中心。但是,您可以在-fprof-auto期间向ghc选项中添加cabal install

$ cabal sandbox init
$ cabal install --ghc-option=-fprof-auto -p --enable-executable-profiling

实施例

使用code from this question的示例,其中问题的代码包含在SO.h中:

$ cabal sandbox init
$ cabal install vector -p --ghc-options=-fprof-auto
$ cabal exec -- ghc --make SO.hs -prof -fprof-auto -O2
$ ./SO /usr/share/dict/words +RTS -s -p
$ cat SO.prof
    Tue Dec  2 15:01 2014 Time and Allocation Profiling Report  (Final)

       Test +RTS -s -p -RTS /usr/share/dict/words

    total time  =        0.70 secs   (698 ticks @ 1000 us, 1 processor)
    total alloc = 618,372,952 bytes  (excludes profiling overheads)

COST CENTRE            MODULE                        %time %alloc

letterCount            Main                           40.3   24.3
letterCount.letters1   Main                           13.2   18.2
basicUnsafeWrite       Data.Vector.Primitive.Mutable  10.0   12.1
basicUnsafeWrite       Data.Vector.Unboxed.Base        7.2    7.3
basicUnsafeRead        Data.Vector.Primitive.Mutable   5.4    4.9
>>=                    Data.Vector.Fusion.Util         5.0   13.4
basicUnsafeIndexM      Data.Vector.Unboxed.Base        4.9    0.0
basicUnsafeIndexM      Data.Vector.Primitive           2.7    4.9
basicUnsafeIndexM      Data.Vector.Unboxed.Base        2.3    0.0
letterCount.letters1.\ Main                            2.0    2.4
>>=                    Data.Vector.Fusion.Util         1.9    6.1
basicUnsafeWrite       Data.Vector.Unboxed.Base        1.7    0.0
letterCount.\          Main                            1.3    2.4
readByteArray#         Data.Primitive.Types            0.3    2.4
basicUnsafeNew         Data.Vector.Primitive.Mutable   0.0    1.2


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

MAIN                        MAIN                              72           0    0.0    0.0   100.0  100.0
 main                       Main                             145           0    0.1    0.2    99.9  100.0
  main.counts               Main                             148           1    0.0    0.0    99.3   99.6
   letterCount              Main                             149           1   40.3   24.3    99.3   99.6
    basicUnsafeFreeze       Data.Vector.Unboxed.Base         257           1    0.0    0.0     0.0    0.0
     primitive              Control.Monad.Primitive          259           1    0.0    0.0     0.0    0.0
     basicUnsafeFreeze      Data.Vector.Primitive            258           1    0.0    0.0     0.0    0.0
    letterCount.\           Main                             256      938848    1.3    2.4     1.3    2.4
    basicUnsafeWrite        Data.Vector.Unboxed.Base         252      938848    1.3    0.0     5.0    6.1
     basicUnsafeWrite       Data.Vector.Primitive.Mutable    253      938848    3.7    6.1     3.7    6.1
      writeByteArray#       Data.Primitive.Types             255      938848    0.0    0.0     0.0    0.0
      primitive             Control.Monad.Primitive          254      938848    0.0    0.0     0.0    0.0
    basicUnsafeRead         Data.Vector.Unboxed.Base         248      938848    0.7    0.0     6.6    7.3
     basicUnsafeRead        Data.Vector.Primitive.Mutable    249      938848    5.4    4.9     5.9    7.3
      readByteArray#        Data.Primitive.Types             251      938848    0.3    2.4     0.3    2.4
      primitive             Control.Monad.Primitive          250      938848    0.1    0.0     0.1    0.0
    >>=                     Data.Vector.Fusion.Util          243      938848    0.0    0.0     0.0    0.0
    basicUnsafeIndexM       Data.Vector.Unboxed.Base         242      938848    0.0    0.0     0.0    0.0
    basicUnsafeIndexM       Data.Vector.Unboxed.Base         237      938848    4.9    0.0    11.7   10.9
     >>=                    Data.Vector.Fusion.Util          247      938848    1.9    6.1     1.9    6.1
     basicUnsafeIndexM      Data.Vector.Unboxed.Base         238      938848    2.3    0.0     5.0    4.9
      basicUnsafeIndexM     Data.Vector.Primitive            239      938848    2.7    4.9     2.7    4.9
       indexByteArray#      Data.Primitive.Types             240      938848    0.0    0.0     0.0    0.0
    >>=                     Data.Vector.Fusion.Util          236      938849    3.4    7.3     3.4    7.3
    unId                    Data.Vector.Fusion.Util          235      938849    0.0    0.0     0.0    0.0
    basicLength             Data.Vector.Unboxed.Base         234           1    0.0    0.0     0.0    0.0
    basicLength             Data.Vector.Primitive.Mutable    233           1    0.0    0.0     0.0    0.0
    basicUnsafeCopy         Data.Vector.Unboxed.Base         222           1    0.0    0.0     0.0    0.0
     basicUnsafeCopy        Data.Vector.Primitive            223           1    0.0    0.0     0.0    0.0
      unI#                  Data.Primitive.ByteArray         226           3    0.0    0.0     0.0    0.0
    basicLength             Data.Vector.Unboxed.Base         214           1    0.0    0.0     0.0    0.0
     basicLength            Data.Vector.Primitive            215           1    0.0    0.0     0.0    0.0
    basicUnsafeNew          Data.Vector.Unboxed.Base         212           1    0.0    0.0     0.0    0.0
     primitive              Control.Monad.Primitive          220           1    0.0    0.0     0.0    0.0
     basicUnsafeNew         Data.Vector.Primitive.Mutable    216           1    0.0    0.0     0.0    0.0
      sizeOf                Data.Primitive                   217           1    0.0    0.0     0.0    0.0
       sizeOf#              Data.Primitive.Types             218           1    0.0    0.0     0.0    0.0
        unI#                Data.Primitive.Types             219           1    0.0    0.0     0.0    0.0
    basicLength             Data.Vector.Unboxed.Base         211           1    0.0    0.0     0.0    0.0
    letterCount.len         Main                             178           1    0.0    0.0     0.0    0.0
    letterCount.letters1    Main                             177           1   13.2   18.2    30.9   41.3
     basicUnsafeFreeze      Data.Vector.Unboxed.Base         204           1    0.0    0.0     0.0    0.0
      basicUnsafeFreeze     Data.Vector.Unboxed.Base         210           1    0.0    0.0     0.0    0.0
      primitive             Control.Monad.Primitive          207           1    0.0    0.0     0.0    0.0
      basicUnsafeFreeze     Data.Vector.Primitive            206           1    0.0    0.0     0.0    0.0
      basicUnsafeFreeze     Data.Vector.Unboxed.Base         205           1    0.0    0.0     0.0    0.0
       basicUnsafeFreeze    Data.Vector.Primitive            208           0    0.0    0.0     0.0    0.0
     basicUnsafeSlice       Data.Vector.Unboxed.Base         200           1    0.0    0.0     0.0    0.0
      basicUnsafeSlice      Data.Vector.Unboxed.Base         203           1    0.0    0.0     0.0    0.0
      basicUnsafeSlice      Data.Vector.Unboxed.Base         201           1    0.0    0.0     0.0    0.0
       basicUnsafeSlice     Data.Vector.Primitive.Mutable    202           1    0.0    0.0     0.0    0.0
     basicUnsafeWrite       Data.Vector.Unboxed.Base         193      938848    7.2    7.3    14.2   13.4
      basicUnsafeWrite      Data.Vector.Unboxed.Base         198      938848    0.0    0.0     0.0    0.0
      basicUnsafeWrite      Data.Vector.Unboxed.Base         194      938848    0.4    0.0     7.0    6.1
       basicUnsafeWrite     Data.Vector.Primitive.Mutable    195      938848    6.3    6.1     6.6    6.1
        writeByteArray#     Data.Primitive.Types             197      938848    0.3    0.0     0.3    0.0
        primitive           Control.Monad.Primitive          196      938848    0.0    0.0     0.0    0.0
     letterCount.letters1.\ Main                             192      938848    2.0    2.4     2.0    2.4
     >>=                    Data.Vector.Fusion.Util          191      938848    1.6    6.1     1.6    6.1
     unId                   Data.Vector.Fusion.Util          190      938849    0.0    0.0     0.0    0.0
     upperBound             Data.Vector.Fusion.Stream.Size   180           1    0.0    0.0     0.0    0.0
     basicUnsafeNew         Data.Vector.Unboxed.Base         179           1    0.0    0.0     0.0    1.2
      basicUnsafeNew        Data.Vector.Unboxed.Base         189           1    0.0    0.0     0.0    0.0
      primitive             Control.Monad.Primitive          187           1    0.0    0.0     0.0    0.0
      basicUnsafeNew        Data.Vector.Primitive.Mutable    182           1    0.0    0.0     0.0    0.0
      basicUnsafeNew        Data.Vector.Unboxed.Base         181           1    0.0    0.0     0.0    1.2
       basicUnsafeNew       Data.Vector.Primitive.Mutable    183           0    0.0    1.2     0.0    1.2
        sizeOf              Data.Primitive                   184           1    0.0    0.0     0.0    0.0
         sizeOf#            Data.Primitive.Types             185           1    0.0    0.0     0.0    0.0
          unI#              Data.Primitive.Types             186           1    0.0    0.0     0.0    0.0
  printCounts               Main                             146           1    0.4    0.2     0.4    0.2
   basicUnsafeIndexM        Data.Vector.Unboxed.Base         266         256    0.0    0.0     0.0    0.0
    basicUnsafeIndexM       Data.Vector.Primitive            267           0    0.0    0.0     0.0    0.0
     indexByteArray#        Data.Primitive.Types             268         256    0.0    0.0     0.0    0.0
   basicUnsafeIndexM        Data.Vector.Primitive            265         256    0.0    0.0     0.0    0.0
   >>=                      Data.Vector.Fusion.Util          264         256    0.0    0.0     0.0    0.0
   unId                     Data.Vector.Fusion.Util          263         256    0.0    0.0     0.0    0.0
   basicLength              Data.Vector.Unboxed.Base         262           1    0.0    0.0     0.0    0.0
   basicLength              Data.Vector.Primitive            261           1    0.0    0.0     0.0    0.0
 CAF                        Main                             143           0    0.0    0.0     0.0    0.0
  main                      Main                             144           1    0.0    0.0     0.0    0.0
   main.counts              Main                             150           0    0.0    0.0     0.0    0.0
    letterCount             Main                             151           0    0.0    0.0     0.0    0.0
     basicUnsafeIndexM      Data.Vector.Unboxed.Base         244           0    0.0    0.0     0.0    0.0
      >>=                   Data.Vector.Fusion.Util          245           0    0.0    0.0     0.0    0.0
       basicUnsafeIndexM    Data.Vector.Unboxed.Base         246           0    0.0    0.0     0.0    0.0
     primitive              Control.Monad.Primitive          224           1    0.0    0.0     0.0    0.0
     basicUnsafeFreeze      Data.Vector.Unboxed.Base         173           1    0.0    0.0     0.0    0.0
      primitive             Control.Monad.Primitive          175           1    0.0    0.0     0.0    0.0
      basicUnsafeFreeze     Data.Vector.Primitive            174           1    0.0    0.0     0.0    0.0
     basicUnsafeSlice       Data.Vector.Unboxed.Base         171           1    0.0    0.0     0.0    0.0
      basicUnsafeSlice      Data.Vector.Primitive.Mutable    172           1    0.0    0.0     0.0    0.0
     basicUnsafeWrite       Data.Vector.Unboxed.Base         167         256    0.0    0.0     0.0    0.0
      basicUnsafeWrite      Data.Vector.Primitive.Mutable    168         256    0.0    0.0     0.0    0.0
       writeByteArray#      Data.Primitive.Types             170         256    0.0    0.0     0.0    0.0
       primitive            Control.Monad.Primitive          169         256    0.0    0.0     0.0    0.0
     >>=                    Data.Vector.Fusion.Util          165         256    0.0    0.0     0.0    0.0
     unId                   Data.Vector.Fusion.Util          164         257    0.0    0.0     0.0    0.0
     basicUnsafeNew         Data.Vector.Unboxed.Base         156           1    0.0    0.0     0.0    0.0
      primitive             Control.Monad.Primitive          162           1    0.0    0.0     0.0    0.0
      basicUnsafeNew        Data.Vector.Primitive.Mutable    157           1    0.0    0.0     0.0    0.0
       sizeOf               Data.Primitive                   158           1    0.0    0.0     0.0    0.0
        sizeOf#             Data.Primitive.Types             159           1    0.0    0.0     0.0    0.0
         unI#               Data.Primitive.Types             160           1    0.0    0.0     0.0    0.0
     upperBound             Data.Vector.Fusion.Stream.Size   153           1    0.0    0.0     0.0    0.0
     elemseq                Data.Vector.Unboxed.Base         152           1    0.0    0.0     0.0    0.0
   printCounts              Main                             147           0    0.0    0.0     0.0    0.0
 CAF                        Data.Vector.Internal.Check       142           0    0.0    0.0     0.0    0.0
  doBoundsChecks            Data.Vector.Internal.Check       213           1    0.0    0.0     0.0    0.0
  doUnsafeChecks            Data.Vector.Internal.Check       155           1    0.0    0.0     0.0    0.0
  doInternalChecks          Data.Vector.Internal.Check       154           1    0.0    0.0     0.0    0.0
 CAF                        Data.Vector.Fusion.Util          141           0    0.0    0.0     0.0    0.0
  return                    Data.Vector.Fusion.Util          241           1    0.0    0.0     0.0    0.0
  return                    Data.Vector.Fusion.Util          166           1    0.0    0.0     0.0    0.0
 CAF                        Data.Vector.Unboxed.Base         136           0    0.0    0.0     0.0    0.0
  basicUnsafeCopy           Data.Vector.Unboxed.Base         227           0    0.0    0.0     0.0    0.0
   basicUnsafeCopy          Data.Vector.Primitive            228           0    0.0    0.0     0.0    0.0
    basicUnsafeCopy.sz      Data.Vector.Primitive            229           1    0.0    0.0     0.0    0.0
     sizeOf                 Data.Primitive                   230           1    0.0    0.0     0.0    0.0
      sizeOf#               Data.Primitive.Types             231           1    0.0    0.0     0.0    0.0
       unI#                 Data.Primitive.Types             232           1    0.0    0.0     0.0    0.0
 CAF                        Data.Primitive.MachDeps          128           0    0.0    0.0     0.0    0.0
  sIZEOF_INT                Data.Primitive.MachDeps          161           1    0.0    0.0     0.0    0.0
 CAF                        Text.Printf                      118           0    0.0    0.0     0.0    0.0
 CAF                        GHC.Conc.Signal                  112           0    0.0    0.0     0.0    0.0
 CAF                        GHC.IO.Handle.FD                 109           0    0.1    0.0     0.1    0.0
 CAF                        GHC.IO.Encoding                   99           0    0.0    0.0     0.0    0.0
 CAF                        GHC.IO.Encoding.Iconv             98           0    0.0    0.0     0.0    0.0
 CAF                        GHC.IO.FD                         95           0    0.0    0.0     0.0    0.0

不幸的是,你依赖于cannot state --ghc-option=… as a flag

答案 1 :(得分:0)

您还需要-prof

GHC Users's Guide说"还有一些其他与性能分析相关的编译选项。 除-prof 外还使用它们。对于程序中的所有模块,不必一致地使用它们。

"

相关问题