在简单R文件上运行Callgrind

在简单R文件上运行Callgrind,r,profiling,valgrind,callgrind,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(

我想使用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")
这似乎运行正常,并产生callgrind.out.XYZ,正如所说的那样

然后我键入:

valgrind --tool=callgrind Rscript filename.R 1000
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
这与我在更复杂的代码中遇到的错误完全相同,因此除了函数之外,还有一些东西出了故障


有人知道我做错了什么吗?谢谢。

可能有点晚了,但是如果你改用

R -d "valgrind --tool=callgrind" -f filename.R