【问题标题】:Profiling with Stack使用堆栈进行分析
【发布时间】:2016-10-21 21:42:11
【问题描述】:

我正在尝试在 Stack 中进行分析,以便获得与 RWH 的 Chapter 25 上指示的指标相同的指标。我开始了一个新的Stack项目,如下:

stack new test

然后,如here所示,我跑了:

stack install --executable-profiling --library-profiling --ghc-options="-rtsopts"

但是此命令失败并出现以下错误:

    While constructing the BuildPlan the following exceptions were encountered:

--  While attempting to add dependency,
    Could not find package base in known packages

--  Failure when adding dependencies:    
      base: needed (>=4.7 && <5), stack configuration has no specified version (latest applicable is 4.9.0.0)
    needed for package test-0.1.0.0

Recommended action: try adding the following to your extra-deps in /home/damian/test/stack.yaml
- base-4.9.0.0

You may also want to try the 'stack solver' command

我已经尝试了上面的建议,但没有成功。

如果我运行stack build,那么程序就不会出错。

作为另一个问题,我想知道是否无法使用上述标志运行 stack teststack exec(这似乎比安装可执行文件以对其进行分析更合乎逻辑)。

【问题讨论】:

  • 当您尝试stack build 时会发生什么?
  • 另外,我发现如果您使用上述选项运行stack build,那么它会将可执行文件编译到.stack-work/ 下的位置,您无需安装即可运行它。
  • stack build 可以毫无问题地构建代码。我忘记添加该信息,谢谢!

标签: debugging haskell profiling haskell-stack


【解决方案1】:

它适用于lts-6.4。对我来说,这表明您没有安装基本的分析版本。这需要在安装 GHC 时安装。 stack exec -- which ghc 说什么?如果 ghc 不在您的堆栈根目录中,~/.stack/programs,那么这意味着您正在使用自定义 GHC 安装,它可能缺少基本的分析版本。要解决,要么:

1) 删除自定义安装并运行“堆栈设置” 2) 或者,设置system-ghc: false 并运行“堆栈设置”

【讨论】:

  • 这解决了问题。我使用的是位于/usr/binghc。然后,在使用@Vaibhav 建议的标志运行堆栈构建后,我能够获得分析信息。
【解决方案2】:

stack install 等价于stack build --copy-bins,所以应该可以运行

stack build --executable-profiling --library-profiling --ghc-options="-rtsopts"

这将在您的.stack-work/ 目录下的某个位置生成一个已编译的可执行文件(stack 会告诉您在哪里)。然后您应该能够运行它并获得您期望的.prof 文件。

【讨论】:

    【解决方案3】:

    似乎对我有用的唯一选择是:

    stack exec --profile NameOfYourAppGoesHere -- +RTS -p

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-14
      • 2021-09-03
      • 2021-11-02
      • 2011-06-17
      • 2018-08-11
      • 2011-11-29
      • 2012-12-02
      • 1970-01-01
      相关资源
      最近更新 更多