Running Callgrind on simple R file
Asked Answered
C

1

7

I want to use Callgrind to find bottlenecks in some complicated Rcpp code. Since I couldn't get it to work, I decided to write a simple R file instead, to make sure it was doing what it should.

However, I still can't get it to work.

My simple function is:

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")

I then type:

valgrind --tool=callgrind Rscript filename.R 1000

This seems to run fine, and produces callgrind.out.XYZ, as the documentation says it should.

I then type:

callgrind_annotate callgrind.out.XYZ

and get the following:

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

This is exactly the same error as I got with my more complicated code, so something besides the function is at fault.

Does anyone have any ideas what I'm doing wrong please? Thanks.

Canst answered 26/2, 2015 at 15:51 Comment(0)
D
5

May be a bit too late, but what if you instead use

R -d "valgrind --tool=callgrind" -f filename.R
Dupin answered 22/9, 2015 at 9:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.