当我将"--profile"选项传递给"stack exec"时,找不到可执行文



有人能帮我理解吗?

$ stack exec -- mvm4x4_amf +RTS -sstderr
mvm4x4_amf: Most RTS options are disabled. Link with -rtsopts to enable them.
$ stack exec --profile -- mvm4x4_amf +RTS -sstderr                                                                                                         
Executable named mvm4x4_amf not found on path: [{snip}]

我在调试部分找到了上面尝试的第二个命令的建议。(搜索词13个匹配项中的第10个:"rts"(

使用:stack build --profile重建Stack项目后,我得到:

$ stack exec --profile -- mvm4x4_amf +RTS -sstderr                                                                                                         
mvm4x4_amf: Most RTS options are disabled. Link with -rtsopts to enable them.

如果我用这个代替:

$ stack exec --profile mvm4x4_amf +RTS -sstderr

我的程序运行,但我没有得到任何分析信息输出。

如果我"进入".stack-work/目录并"手动执行"(正如我在其他一些与此问题相关的帖子中看到的建议(:

$ .stack-work/dist/x86_64-osx/Cabal-2.4.0.1/build/mvm4x4_amf/mvm4x4_amf +RTS -sstderr
mvm4x4_amf: Most RTS options are disabled. Link with -rtsopts to enable them.

然后我的可执行文件实际上并不是为分析而构建的。但是,试图明确地重建它以进行分析不会产生任何行动:

$ stack build --profile :mvm4x4_amf
$

哦,这有帮助吗

$ stack exec mvm4x4_amf --rts-options --info
[("GHC RTS", "YES")
,("GHC version", "8.6.5")
,("RTS way", "rts_v")
,("Build platform", "x86_64-apple-darwin")
,("Build architecture", "x86_64")
,("Build OS", "darwin")
,("Build vendor", "apple")
,("Host platform", "x86_64-apple-darwin")
,("Host architecture", "x86_64")
,("Host OS", "darwin")
,("Host vendor", "apple")
,("Target platform", "x86_64-apple-darwin")
,("Target architecture", "x86_64")
,("Target OS", "darwin")
,("Target vendor", "apple")
,("Word size", "64")
,("Compiler unregisterised", "NO")
,("Tables next to code", "YES")
]

嗯,在更改阴谋集团文件选项和重建时,我注意到了一些奇怪的东西:

$ stack build --profile :mvm4x4_amf
luminous-0.5.0.0: unregistering (local file changes: luminous.cabal)
luminous> configure (lib + exe)
Configuring luminous-0.5.0.0...
luminous> build (lib + exe)
Preprocessing library for luminous-0.5.0.0..
Building library for luminous-0.5.0.0..
Preprocessing executable 'mvm4x4_amf' for luminous-0.5.0.0..
Building executable 'mvm4x4_amf' for luminous-0.5.0.0..
luminous> copy/register
Installing library in .../.stack-work/install/x86_64-osx/2428dc603454d346facf6484280fa92531e4d7789d3
3c4dd56c39cf70d79bd7e/8.6.5/lib/x86_64-osx-ghc-8.6.5/luminous-0.5.0.0-9ABiH0AyDmV25JxAv1cFEI                                                              
{snip}
Installing executable mvm4x4_amf in .../.stack-work/install/x86_64-osx/2428dc603454d346facf6484280fa
92531e4d7789d33c4dd56c39cf70d79bd7e/8.6.5/bin                                                                                                             
{snip}
Registering library for luminous-0.5.0.0..
$ stack exec which mvm4x4_amf
.../.stack-work/install/x86_64-osx/9af8b70f7f84a02189b610f95c8d289ab7d743df5c23a5d5d43b30afe0c02b7c/
8.6.5/bin/mvm4x4_amf                                                                                                                                      

Stack似乎在不同于安装它的目录中找到了我的mvm4x4_amf可执行文件!我读对了吗?我应该担心吗?

哦,供参考:

$ stack --version
Version 2.1.3, Git revision 0fa51b9925decd937e4a993ad90cb686f88fa282 (7739 commits) x86_64 hpack-0.31.2

啊哈!你必须这样做:

$ stack exec --profile mvm4x4_amf --rts-options -sstderr

通过该命令,我得到了预期的分析结果:

294,885,845,152 bytes allocated in the heap
3,900,063,256 bytes copied during GC
160,061,616 bytes maximum residency (57 sample(s))
6,223,696 bytes maximum slop
152 MB total memory in use (0 MB lost due to fragmentation)
Tot time (elapsed)  Avg pause  Max pause
Gen  0     282964 colls,     0 par    6.696s   6.863s     0.0000s    0.0013s
Gen  1        57 colls,     0 par    0.928s   1.048s     0.0184s    0.1195s
INIT    time    0.000s  (  0.003s elapsed)
MUT     time  217.655s  (221.658s elapsed)
GC      time    7.624s  (  7.911s elapsed)
RP      time    0.000s  (  0.000s elapsed)
PROF    time    0.000s  (  0.000s elapsed)
EXIT    time    0.000s  (  0.000s elapsed)
Total   time  225.279s  (229.571s elapsed)
%GC     time       0.0%  (0.0% elapsed)
Alloc rate    1,354,833,854 bytes per MUT second
Productivity  96.6% of total user, 96.6% of total elapsed

在我的正常程序输出之后。

还有:

$ stack exec --profile which mvm4x4_amf                                                                                                                    
.../.stack-work/install/x86_64-osx/2428dc603454d346facf6484280fa92531e4d7789d33c4dd56c39cf70d79bd7e/
8.6.5/bin/mvm4x4_amf                                                                                                                                      

所以,我想,--profile选项将stack exec命令"引导"到不同的install/子目录?我想这是有道理的。

$ stack exec -- mvm4x4_amf +RTS -sstderr
mvm4x4_amf: Most RTS options are disabled. Link with -rtsopts to enable them.
$ stack exec --profile -- mvm4x4_amf +RTS -sstderr
Executable named mvm4x4_amf not found on path: [{snip}]

之所以会发生这种情况,是因为使用和不使用分析信息构建的可执行文件实际上是非常不同的可执行程序。这是因为发出分析信息的成本非常高,因此可能会显著降低执行速度,因此当您在没有--profile的情况下进行构建时,所有这些额外的代码都会被剥离以提高性能。

您的第二次调用失败,因为您没有为程序构建可执行的评测。简单地说,.stack-work中有多个目录,其中包含多组使用不同选项构建的二进制文件,因此stack exec --profile会查找"profiling binaries"目录,在您的情况下该目录是空的。

使用:Stack-build--profile重建我的Stack项目后,我得到:

$ stack exec --profile -- mvm4x4_amf +RTS -sstderr                    
mvm4x4_amf: Most RTS options are disabled. Link with -rtsopts to enable them.

此调用是正确的。正如错误所示,您现在需要使用-rtsopts构建可执行文件,以使您的可执行文件接受您想要传递给它的RTS选项。

如果我使用这个:

$ stack exec --profile mvm4x4_amf +RTS -sstderr

我的程序运行,但我没有得到任何分析信息输出。

这里的问题是stack本身就是一个Haskell问题,所以您的+RTS -sstderr操作被stack消耗,而不是传递给您的二进制文件。您绝对需要这些--(或者,您也可以使用--rts-options <options>,它告诉堆栈将+RTS <options>传递给您的二进制文件

最新更新