在简单的R文件上运行Callgrind

时间:2015-02-26 15:51:33

标签: r profiling valgrind callgrind

我想使用Callgrind找到一些复杂的Rcpp代码中的瓶颈。由于我无法使其工作,我决定编写一个简单的R文件,以确保它正在做它应该做的事情。

但是,我仍然无法让它发挥作用。

我的简单功能是:

args <- commandArgs(trailingOnly=T)
test_callgrind <- function(args) {
  x <- args[1]
  a <- 0
  for (i in 1:x) {
    a <- i
  }
  return(a)
}
a <- test_callgrind(args)
save(a, file="a.rdata")
然后我输入:

valgrind --tool=callgrind Rscript filename.R 1000

这似乎运行正常,并产生callgrind.out.XYZ,正如documentation所说的那样。

然后我输入:

callgrind_annotate callgrind.out.XYZ

并获得以下内容:

Use of uninitialized value $events in string ne at /usr/bin/callgrind_annotate line 446.
Line 0: missing events line

这与我使用更复杂的代码完全相同,所以除了函数之外还有一些错误。

有人有任何想法,我做错了吗?感谢。

1 个答案:

答案 0 :(得分:3)

可能有点太晚了,但如果你改为使用

会怎么样
R -d "valgrind --tool=callgrind" -f filename.R
相关问题