使用堆栈进行性能分析

3

我正在尝试使Stack中的分析工具生效,以便获得与RWH第25章链接中指示的相同指标。我创建了一个新的Stack项目,如下所示:

stack new test

然后,如此处所示,我运行了:

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(这似乎比安装可执行文件以进行剖析更合理)。

1
当您尝试运行 stack build 时会发生什么? - Vaibhav Sagar
另外,我发现如果你使用上述选项运行 stack build,它会将可执行文件编译到 .stack-work/ 目录下的一个位置,你可以直接从那里运行它而无需安装。 - Vaibhav Sagar
stack build 没有任何问题地构建了代码。我忘记添加那个信息了,谢谢! - Damian Nadales
3个回答

3

对于我来说,这在上运行良好。这表明您没有安装基本的分析版本。 GHC安装时需要进行安装。 stack exec -- which ghc 输出什么?如果ghc不在您的堆根目录(~/.stack/programs)中,则表示您正在使用自定义GHC安装,可能缺乏有关基准的分析版本。要解决此问题,请执行以下操作之一:

1)删除自定义安装并运行“stack setup” 2)或者将system-ghc: false设置为“stack setup”


这解决了问题。我之前使用的是位于/usr/binghc。然后,在使用@Vaibhav建议的标志运行stack build之后,我成功获取了分析信息。 - Damian Nadales

1
似乎唯一可行的选择是: stack exec --profile NameOfYourAppGoesHere -- +RTS -p

1

stack install 相当于 stack build --copy-bins,因此您应该能够运行

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

这将导致一个已编译的可执行文件出现在您的.stack-work/目录中(stack会告诉您位置)。然后,您应该能够运行它并获得您期望的.prof文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接