【问题标题】:Profiling executable with criterion使用标准分析可执行文件
【发布时间】:2016-01-10 01:46:36
【问题描述】:

我需要分析大量的 haskell 可执行文件,希望是并行的。我能够使用 Criterion 库中的 measuremeasTime 获取时钟时间,但无法让 measCpuTime 或任何 GC 报告正常工作(measCpuTime 返回的时间非常短)。代码如下:

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 

简而言之,我使用System.Process.system 作为 IO 操作运行可执行文件,并且我已将ExitCode 声明为NFData 以使nfIO 工作。我做错了什么?有更好的工具来完成这项任务吗?

文件的here 如果你想玩它。

【问题讨论】:

  • 好吧,你的子进程的 CPU 时间不是你的 CPU 时间,所以measCpuTime 没有做你想做的事情也就不足为奇了。不确定如何测量子进程的 CPU 时间,但显然可以,因为 time 会这样做。
  • 我正在考虑使用 GHC API 进行配置文件,但不知道从哪里开始查找

标签: haskell lazy-evaluation criterion


【解决方案1】:

我看了this SO question 并得到了一些想法。首先注意criterion使用cbits来启用系统依赖的cpu时间功能。让我们假装你在unix上。最简单的做法是在运行的开始和结束时直接从/proc/PID/stat/cutime 读取并获取差异。除此之外,您实际上可以使用该问题中提供的c 代码,将其作为外部导入链接到自己中,然后直接从您自己的代码中调用。

【讨论】:

    猜你喜欢
    • 2013-10-07
    • 2012-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-14
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多