[英]Profiling executable with criterion
I need to profile a large number of haskell executables, hopefully in parallel. 我需要分析大量的haskell可执行文件,希望并行。 I was able to get the clock time with
measure
and measTime
from the Criterion library, but couldn't get measCpuTime
or any GC report to work ( measCpuTime
returns a time that's impossibly short). 我能够通过Criterion库中的
measure
和measTime
获得时钟时间,但无法获得measCpuTime
或任何GC报告( measCpuTime
返回的时间不可能很短)。 The code looks like: 代码如下:
buildProj :: FilePath -> IO ExitCode
buildProj projDir = system $ "cd " ++ projDir ++ "; cabal sandbox init; cabal configure; cabal build"
-- Time a project
instance NFData ExitCode
where
rnf ExitSuccess = ()
rnf (ExitFailure _) = ()
benchmark :: FilePath -> Int64 -> IO Double
benchmark projDir runs = do
let runProj = "./" ++ projDir ++ "/dist/build/" ++ projDir ++ "/" ++ projDir ++ "> /dev/null"
exit <- timeout 17000000 $ system runProj -- TODO hardcode timeout
case exit of
Just ExitSuccess -> do {(m, _) <- measure (nfIO $ system runProj) runs;
return $! measTime m}
Just (ExitFailure _) -> return 100
Nothing -> return 100
In short, I'm running the executables with System.Process.system
as an IO action and I've declared ExitCode
as NFData
in order to get nfIO
to work. 简而言之,我正在使用
System.Process.system
作为IO操作运行可执行文件,并且我已将ExitCode
声明为NFData
以使nfIO
工作。 What have I done wrong? 我做错了什么? Are there better tools to do the task?
有没有更好的工具来完成任务?
I took a look at this SO question and got some ideas. 我看了看这个问题并得到了一些想法。 First note that
criterion
uses cbits to enable system-dependent cpu time functions. 首先请注意,
criterion
使用cbits来启用依赖于系统的cpu时间函数。 Let's pretend you're on unix. 让我们假装你在unix上。 The simplest thing to do is to directly read from
/proc/PID/stat/cutime
at the start and end of your runs and take the difference. 最简单的方法是在运行的开始和结束时直接从
/proc/PID/stat/cutime
读取并获取差异。 Beyond that, you can actually use the c
code provided in that question, link it in yourself as a foreign import, and then call that directly from your own code. 除此之外,您实际上可以使用该问题中提供的
c
代码,将其作为外部导入链接在自己中,然后直接从您自己的代码中调用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.