【问题标题】:How do I enable profiling in a cabal-dev installation?如何在 cabal-dev 安装中启用分析?
【发布时间】:2023-04-09 16:28:02
【问题描述】:

我正在尝试分析一个具有一些依赖项的程序 Windingnumber。根据 Aleksander Dmitrov 在Profile Haskell without installing installing profiling libraries for all dependencies 中的回答,我正在使用 cabal-dev 来(尝试)构建所有启用了分析的依赖项。我试过了

  • cabal-dev install --config=./cabal-dev.config,其中 cabal-dev.config 是

    library-profiling: True
    executable-profiling: True
    package-db: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/packages-7.6.1.conf
    local-repo: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/packages
    user-install: False
    remote-repo: hackage.haskell.org:http://hackage.haskell.org/packages/archive
    remote-repo-cache: /home/christopher/.cabal/packages
    optimization: True
    build-summary: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/logs/build.log
    remote-build-reporting: anonymous
    optimization: True
    
    install-dirs user
      prefix: /home/christopher/school/senior/senior_thesis/windingnumber_integration/cabal-dev/
    install-dirs global
    
  • cabal-dev install --cabal-install-arg='--enable-library-profiling' --cabal-install-arg='--enable-executable-profiling'

(当然,要从原始环境开始,在两者之间加上rm -rf cabal-dev。)在每种情况下,我都得到:

arch% cabal-dev/bin/windingnumber +RTS -p
cabal-dev/bin/windingnumber +RTS -p
windingnumber: the flag -p requires the program to be built with -prof
windingnumber: 
windingnumber: Usage: <prog> <args> [+RTS <rtsopts> | -RTS <args>] ... --RTS <args>
<snip>

---即未启用分析。如何启用它?

ETA 解决方案:-prof 添加到项目的 .cabal 文件中的 ghc-options 中。显然在 cabal-dev 配置中设置 `executable-profiling: True" 并没有这样做。感谢 Daniel Fischer。

【问题讨论】:

  • 看起来您没有使用-prof 标志构建可执行文件。你是如何构建windingnumber 的?
  • 啊哈。在我的 .cabal 文件中将 -prof 添加到 ghc-options 修复了一些问题。谢谢!
  • 您可能需要比默认更细粒度的分析,所以-fprof-auto 可能是一个不错的补充。
  • 是的。这确实更有用。
  • 不会这样调用 cabal-dev:cabal-dev install --enable-library-profiling --enable-executable-profiling 也可以吗?如果你想摆脱配置文件。

标签: haskell profiling cabal


【解决方案1】:

看起来cabal-dev 每次运行都会重写./cabal-dev/cabal.config。但是,您可以编辑 ~/.cabal/share/cabal-dev-$VERSION/admin/cabal-config.in 来设置默认值:

$  vim ~/.cabal/share/cabal-dev-0.9.1/admin/cabal-config.in
# Set executable-profiling and library-profiling to True
$ cabal unpack ghc-core
$ cd ghc-core-0.5.6
$ cabal-dev install --dependencies-only
$ cabal-dev configure -p
$ cabal-dev build
$ ./dist/build/ghc-core/ghc-core +RTS -p
# much success

如果您不想为使用cabal-dev 管理的所有项目启用分析,请使用--extra-config-file 选项(--config 只是设置自动生成的配置文件的位置):

$ cat cabal-dev.config 
executable-profiling: True
library-profiling: True
$ cabal-dev --extra-config-file='./cabal-dev.config' install
$ ./cabal-dev/bin/ghc-core +RTS -p
# success

不建议使用 .cabal 文件中的 ghc-options 字段来启用分析 - 您不希望从 Hackage 安装您的软件包的每个人都使用分析进行构建。使用 cabal-dev configure -p --ghc-options="-fprof-auto" 仅对当前构建启用分析。

【讨论】:

  • 啊。很高兴知道,虽然它不能解决我的问题(我正在使用 --config 指定一个备用配置文件。)
  • @ChristopherWhite 显然--config 只是设置了cabal-dev 配置文件的位置,该文​​件在每次启动时自动生成。您需要改用--extra-config-file。我已经更新了我的答案。
  • 这说明了事情;我应该更仔细地阅读文档。很抱歉,谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-14
  • 2020-03-15
  • 2015-01-22
  • 1970-01-01
相关资源
最近更新 更多