如何在 Stack 中使用分析构建?

How to build with profiling in Stack?

我正在努力构建具有分析功能的应用程序,因为我需要堆栈跟踪。

$ stack new prof 
$ cd prof
$ stack build --profile --executable-profiling --library-profiling 
$ stack exec prof-exe +RTS -p
stack: the flag -p requires the program to be built with -prof

$ stack --version
Version 2.7.1, Git revision 8afe0c2932716b0441cf4440d6942c59568b6b19 x86_64 hpack-0.34.4

ghc 8.10.7

Stack 本身是用 Haskell 编写的,因此它也接受 +RTS -p 参数。要将 +RTS -p 传递给您的 prof-exe,您应该使用 -- 分隔符:

stack exec prof-exe -- +RTS -p

但是,我认为 run 命令应该用于 运行 可执行文件,我认为您也需要在那里添加 --profile 标志。对我有用的命令是:

stack run --profile prof-exe -- +RTS -p