本文介绍了在没有为所有依赖项安装性能分析库的情况下对Haskell进行概要分析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望介绍我用Haskell编写的程序.

I wish to profile my program written in Haskell.

在编译时,我被告知我没有针对某些依赖项(例如criterion)安装的概要分析库,并且cabal中止.

On compilation, I am told that I do not have profiling libraries for certain dependencies (e.g., criterion) installed and cabal aborts.

我对剖析部分依赖项没有兴趣;从main调用的代码甚至没有使用它们.

I have no interest in profiling parts of those dependencies; code called from main doesn't even use them.

如何在不安装不需要的分析库且不删除所有那些依赖关系的情况下对应用程序进行概要分析?

How can I profile my application without installing profiling libraries I don't need and without removing all those dependencies?

推荐答案

要避免必须通过分析编译一切的好方法是使用cabal沙箱.它仅允许您为一个应用程序设置沙箱,因此您不必重新安装整个~/.cabal前缀.您将需要Cabal的最新版本,因此请先运行cabal update && cabal install cabal-install.

A good way to circumvent having to compile everything with profiling is to use cabal sandbox. It allows you to set up a sandbox for one application only, and thereby you won't have to re-install your entire ~/.cabal prefix. You'll need a recent version of Cabal, so run cabal update && cabal install cabal-install first.

初始化沙箱后,请创建文件cabal.config以包含必要的指令(在您的情况下为library-profiling: Trueexecutable-profiling: True也可能很方便.)

Once you initialise a sandbox, create a file cabal.config to include the necessary directives (in your case library-profiling: True; executable-profiling: True may also be handy.)

这样做的副作用是,您可以使用不需要全局安装的依赖项(例如,实验版本或过时的版本)来测试代码.

A side-effect of this is that you can test your code with dependencies that need not be installed globally, for example, experimental versions, or outdated versions.

顺便说一句,我不认为您需要启用分析才能使criterion工作.无论如何,它在没有启用分析的情况下都对我有效.只需编写一个包含main = defaultMain benchmarksMain模块,其中benchmarks的类型为[Benchmark],即您已编写的基准列表.

btw, I don't think you need to have profiling enabled for criterion to work. In any case, it works for me without profiling being enabled. Just write a Main module that contains main = defaultMain benchmarks where benchmarks has type [Benchmark], i.e. a list of benchmarks that you've written.

然后,您编译该文件(例如,我们将其与ghc --make -o bench benchmarks.hs一起命名为benchmarks.hs,并使用适当的参数运行程序./bench(有关详细信息,请咨询标准文档.一个很好的默认参数是./bench -o benchmarks.html会生成类似于这一个)

You then compile that file (say, we call it benchmarks.hs with ghc --make -o bench benchmarks.hs, and run the program, ./bench with the appropriate arguments (consult the criterion documentation for details. A good default argument is, say ./bench -o benchmarks.html which will generate a nifty report similar to this one)

这篇关于在没有为所有依赖项安装性能分析库的情况下对Haskell进行概要分析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 07:03