Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running Callgrind on simple R file

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.

like image 733
Jack13 Avatar asked Feb 26 '15 15:02

Jack13


People also ask

How to run callgrind?

To use Callgrind, you must specify --tool=callgrind on the Valgrind command line or use the supplied script callgrind . Callgrind's cache simulation is based on the Cachegrind tool of the Valgrind package.

How do I run KCacheGrind?

You can launch KCacheGrind using command line or in the program menu if your system installed it here. Then, you have to open your profile file. The first view present a list of all the profiled functions. You can see the inclusive and the self cost of each function and the location of each one.

How callgrind works?

Overview. Callgrind is a profiling tool that records the call history among functions in a program's run as a call-graph. By default, the collected data consists of the number of instructions executed, their relationship to source lines, the caller/callee relationship between functions, and the numbers of such calls.

What is IR in callgrind?

Ir: The number of instructions executed in total by the selected function after being called by this caller.


1 Answers

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

R -d "valgrind --tool=callgrind" -f filename.R
like image 50
mikldk Avatar answered Oct 23 '22 06:10

mikldk