在简单的R文件上运行Callgrind

Jac*_*k13 7 profiling valgrind r 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")
Run Code Online (Sandbox Code Playgroud)

然后我输入:

valgrind --tool=callgrind Rscript filename.R 1000
Run Code Online (Sandbox Code Playgroud)

这似乎运行正常,并产生callgrind.out.XYZ,正如文档所说应该.

然后我输入:

callgrind_annotate callgrind.out.XYZ
Run Code Online (Sandbox Code Playgroud)

并获得以下内容:

Use of uninitialized value $events in string ne at /usr/bin/callgrind_annotate line 446.
Line 0: missing events line
Run Code Online (Sandbox Code Playgroud)

这与我使用更复杂的代码完全相同,所以除了函数之外的其他错误.

有没有人有任何想法,我做错了吗?谢谢.

mik*_*ldk 5

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

R -d "valgrind --tool=callgrind" -f filename.R
Run Code Online (Sandbox Code Playgroud)