Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Linux Tools Project » Using autotools & valgrind for compiling an R library
Using autotools & valgrind for compiling an R library [message #516677] Wed, 24 February 2010 13:18 Go to next message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Hi,

I am new to eclipse and autotools, so please be gentle. R is the GNU statistical computing environment (http://cran.r-project.org/). It provides an interactive environment for statistical computations.

I am able to compile and install R from the command-line and from within eclipse-autotools in three steps ./configure/make all/make install. (btw, Eclipse-autotools plugin is really fabulous). I am also able to compile, install and debug my own package for R from command line. I would like to do all of this from with Eclipse using linuxtools.

R requires source files of external packages to be structured a certain way (/somedir/my-pkg/src, /somedir/my-pkg/man, /somedir/my-pkg/data etc.) These can be compiled and installed via :

> cd /somedir
> R CMD install "my-pkg"


my-pkg directory contains the package source. The compiled package is installed as a library in "/usr/local/bin/R/library"

Is there any way in which I can accomplish this step from within Eclipse?


R scripts using the package can be debugged for example using valgrind or debug as:

>R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < my-pkg-Ex.R


Where my-pkg-Ex.R is the R script which uses the package.

Is there any way I can invoke R from within Eclipse and use valgrind to check memory?


The advantage are obvious. I just do not know how to set this up so that all steps of the workflow (Compile R with -g, Compile my-pkg, Debug my-pkg) are done from within Eclipse.

Any help will be greatly appreciated. Thanks in advance,

Russ
Re: Using autotools & valgrind for compiling an R library [message #516693 is a reply to message #516677] Wed, 24 February 2010 14:28 Go to previous messageGo to next message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
Hi Russ,

On 02/24/2010 01:18 PM, Russ wrote:
> R scripts using the package can be debugged for example using valgrind
> or debug as:
>
>> R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < my-pkg-Ex.R
>
> Where my-pkg-Ex.R is the R script which uses the package.
> Is there any way I can invoke R from within Eclipse and use valgrind to
> check memory?

Typical use of Valgrind involves prefixing the command line used to run
your program with "valgrind [options]", such as "valgrind
--leak-check=full ./myprog arg1 arg2". So you actually run valgrind,
which in turn instruments your target program.

I'm not very familiar with how R executes its programs, but it seems
from your example that you execute R, which instruments the target
program with valgrind and runs it.

The Eclipse Valgrind plugin expects the typical scenario I mentioned. My
only suggestion is to try instead of:
R -d "valgrind --tool=memcheck --leak-check=full" --vanilla < my-pkg-Ex.R
try
valgrind --tool=memcheck --leak-check=full R -d --vanilla < my-pkg-Ex.R

If this yields the same results you should be fine. However I suspect
the reason they chose the former is to avoid instrumenting the R runtime
itself. So trying the latter, you may end up with much, much more output
that you want. Let me know how it goes.

Thanks,
Elliott
Re: Using autotools & valgrind for compiling an R library [message #516737 is a reply to message #516693] Wed, 24 February 2010 18:05 Go to previous messageGo to next message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Hi Elliott,

Thanks for the quick response.

(1)

> R -d "valgrind --tool=memcheck --leak-check=full --log-file=logout" --vanilla --slave < simple.R

valgrind logfile is produced with full output.

(2)

> valgrind --tool=memcheck --leak-check=full --log-file=logout R --vanilla < simple.R


R runs the commands and produces correct results on console, but valgrind logfile includes only the banner:
==6863== Memcheck, a memory error detector
==6863== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==6863== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==6863== Command: R --vanilla
==6863== Parent PID: 6499
==6863==
No other output is produced.
including/excluding --slave has no effect. -d is the command to invoke debugger from R.

Does this have anything to do with the fact that R is an "interactive" program and the "main" really sets up a wait-loop?? As I understand it calling R allows interactive debugging.

How do I do this from within Eclipse, so that I can locate errors within source files etc.

thanks again for all your help,

Russ
Re: Using autotools & valgrind for compiling an R library [message #516770 is a reply to message #516737] Wed, 24 February 2010 23:56 Go to previous messageGo to next message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
Hi Russ,

On 02/24/2010 06:05 PM, Russ wrote:
>> valgrind --tool=memcheck --leak-check=full --log-file=logout R
>> --vanilla < simple.R
>
>
> R runs the commands and produces correct results on console, but
> valgrind logfile includes only the banner:
> ==6863== Memcheck, a memory error detector
> ==6863== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
> ==6863== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for
> copyright info
> ==6863== Command: R --vanilla
> ==6863== Parent PID: 6499
> ==6863== No other output is produced.
A guess is that R is spawning an process, which Valgrind is not
instrumenting. Try adding --trace-children=yes to the valgrind command line.

>
> Does this have anything to do with the fact that R is an "interactive"
> program and the "main" really sets up a wait-loop?? As I understand it
> calling R allows interactive debugging.
> How do I do this from within Eclipse, so that I can locate errors within
> source files etc.
Even for interactive programs, Valgrind should wait until the program
terminates.

Thanks,
Elliott
Re: Using autotools & valgrind for compiling an R library [message #516959 is a reply to message #516770] Thu, 25 February 2010 10:31 Go to previous messageGo to next message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Adding trace-children indeed produced complete output.


>valgrind --tool=memcheck --leak-check=full --trace-children=yes --log-file=logout R --vanilla < simple.R


I will now try to replicate it from within Eclipse. If I understand correctly. I would do the following:
Compile my-pkg as a dynamic library
Compile R
Call valgrind with appropriate parameters, and call R as an application, passing other arguments. I will report back the results.

Thanks again,

Russ
Re: Using autotools & valgrind for compiling an R library [message #517069 is a reply to message #516959] Thu, 25 February 2010 22:21 Go to previous messageGo to next message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
Hi Russ,

On 02/25/2010 10:31 AM, Russ wrote:
> Adding trace-children indeed produced complete output.
>
>> valgrind --tool=memcheck --leak-check=full --trace-children=yes
>> --log-file=logout R --vanilla < simple.R
That's great news!

> I will now try to replicate it from within Eclipse. If I understand
> correctly. I would do the following:
> Compile my-pkg as a dynamic library
> Compile R
> Call valgrind with appropriate parameters, and call R as an application,
> passing other arguments. I will report back the results.
Yes, in this case you would create a new Valgrind Profile Configuration
for R, in the arguments tab you could add --vanilla. To use your R file,
from what I read there is a -f option for R to specify a script to run.
So under the arguments tab put: --vanilla -f simple.R
Under the Valgrind Options tab make sure to check "Trace children on
exec", and you should be ready to go. The log file option is implicitly
used to gather the output to display. Let me know how it goes.

Thanks,
Elliott
Re: Using autotools & valgrind for compiling an R library [message #517480 is a reply to message #516677] Sun, 28 February 2010 10:39 Go to previous messageGo to next message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Thanks for your suggestions. It seems I am one step closer.

I tried several different ways of invoking R (RUN/DEBUG/PROFILE) from within Eclipse. I get the following error message each time:


/home/smeme/workspace/R/bin/exec/R: error while loading shared libraries: libRblas.so: cannot open shared object file: No such file or directory


Apart from teh executable, R creates a number of shared libraries, which are needed.

When R is invoked from the command-line (after sudo make install), it really calls a script which sets various paths and then runs the executable R. The script also correctly invokes valgrind.

Here is the script from the eclipse workspace:

#!/bin/bash
# Shell wrapper for R executable.

R_HOME_DIR="/home/smeme/workspace/R"
if test "${R_HOME_DIR}" = "/usr/local/lib/R"; then
case "linux-gnu" in
linux*)
run_arch=`uname -m`
case "$run_arch" in
x86_64|mips64|ppc64|powerpc64|sparc64|s390x)
libnn=lib64
libnn_fallback=lib
;;
*)
libnn=lib
libnn_fallback=lib64
;;
esac
if [ -x "/usr/local/${libnn}/R/bin/exec/R" ]; then
R_HOME_DIR="/usr/local/${libnn}/R"
elif [ -x "/usr/local/${libnn_fallback}/R/bin/exec/R" ]; then
R_HOME_DIR="/usr/local/${libnn_fallback}/R"
## else -- leave alone (might be a sub-arch)
fi
;;
esac
fi

if test -n "${R_HOME}" && \
test "${R_HOME}" != "${R_HOME_DIR}"; then
echo "WARNING: ignoring environment value of R_HOME"
fi
R_HOME="${R_HOME_DIR}"
export R_HOME
R_SHARE_DIR="${R_HOME_DIR}/share"
export R_SHARE_DIR
R_INCLUDE_DIR="${R_HOME_DIR}/include"
export R_INCLUDE_DIR
R_DOC_DIR="${R_HOME_DIR}/doc"
export R_DOC_DIR

# Since this script can be called recursively, we allow R_ARCH to
# be overridden from the environment.
# This script is shared by parallel installs, so nothing in it should
# depend on the sub-architecture except the default here.
: ${R_ARCH=}

usage="
Usage: R [options] [< infile] [> outfile]
or: R CMD command [arguments]

Start R, a system for statistical computation and graphics, with the
specified options, or invoke an R tool via the 'R CMD' interface.

Options:
-h, --help Print short help message and exit
--version Print version info and exit
--encoding=ENC Specify encoding to be used for stdin
RHOME Print path to R home directory and exit
--save Do save workspace at the end of the session
--no-save Don't save it
--no-environ Don't read the site and user environment files
--no-site-file Don't read the site-wide Rprofile
--no-init-file Don't read the user R profile
--restore Do restore previously saved objects at startup
--no-restore-data Don't restore previously saved objects
--no-restore-history Don't restore the R history file
--no-restore Don't restore anything
--vanilla Combine --no-save, --no-restore, --no-site-file,
--no-init-file and --no-environ
--no-readline Don't use readline for command-line editing
--min-vsize=N Set vector heap min to N bytes; '4M' = 4 MegaB
--max-vsize=N Set vector heap max to N bytes;
--min-nsize=N Set min number of cons cells to N
--max-nsize=N Set max number of cons cells to N
--max-ppsize=N Set max size of protect stack to N
-q, --quiet Don't print startup message
--silent Same as --quiet
--slave Make R run as quietly as possible
--interactive Force an interactive session
--verbose Print more information about progress
-d, --debugger=NAME Run R through debugger NAME
--debugger-args=ARGS Pass ARGS as arguments to the debugger
-g, --gui=TYPE Use TYPE as GUI; possible values are 'X11'
(default) and 'Tk'.
--arch=NAME Specify a sub-architecture
--args Skip the rest of the command line
-f, --file=FILE Take input from 'FILE'

Commands:
BATCH Run R in batch mode
COMPILE Compile files for use with R
SHLIB Build shared library for dynamic loading
INSTALL Install add-on packages
REMOVE Remove add-on packages
build Build add-on packages
check Check add-on packages
LINK Front-end for creating executable programs
Rprof Post-process R profiling files
Rdconv Convert Rd format to various other formats
Rd2dvi Convert Rd format to DVI
Rd2pdf Convert Rd format to PDF
Rd2txt Convert Rd format to pretty text
Sd2Rd Convert S documentation to Rd format
Stangle Extract S/R code from Sweave documentation
Sweave Process Sweave documentation
Rdiff Diff R output ignoring headers etc
config Obtain configuration information about R
javareconf Update the Java configuration variables
rtags Create Emacs-style tag files from C, R, and Rd files

Please use 'R CMD command --help' to obtain further information about
the usage of 'command'.

Report bugs to <r-bugs@r-project.org>."

### We also have this in compiled code -> use that one to always be in sync
# version="R 2.10.1 Patched (2010-02-20).
# Copyright (C) 2010 R Development Core Team

# R is free software and comes with ABSOLUTELY NO WARRANTY.
# You are welcome to redistribute it under the terms of the GNU
# General Public License. For more information about these matters,
# see http://www.gnu.org/copyleft/gpl.html."


## some systems have a more portable sed, e.g. /usr/xpg4/bin/sed on Solaris,
## so make sure that is used.
SED=/bin/sed
export SED

error () {
echo "ERROR: $*" >&2
exit 1
}

### Argument loop
args=
debugger=
debugger_args=
gui=
while test -n "${1}"; do
case ${1} in
RHOME|--print-home)
echo "${R_HOME}"; exit 0 ;;
CMD)
shift;
export R_ARCH
. ${R_HOME}/etc${R_ARCH}/ldpaths
exec sh "${R_HOME}/bin/Rcmd" "${@}" ;;
-g|--gui)
if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
gui="${2}"
args="${args} ${1} ${2}"
shift
else
error "option '${1}' requires an argument"
fi
;;
--gui=*)
gui=`echo "${1}" | ${SED} -e 's/[^=]*=//'`
args="${args} ${1}"
;;
-d|--debugger)
if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
debugger="${2}"; shift
else
error "option '${1}' requires an argument"
fi
;;
--debugger=*)
debugger=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
--debugger-args=*)
debugger_args=`echo "${1}" | ${SED} -e 's/[^=]*=//'` ;;
-h|--help)
echo "${usage}"; exit 0 ;;
## use the version in compiled code to always be in sync
# --version)
# echo "${version}"; exit 0 ;;
--args)
break ;;
--arch)
if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
R_ARCH="/${2}"
shift
else
error "option '${1}' requires an argument"
fi
;;
--arch=*)
r_arch=`echo "${1}" | ${SED} -e 's/[^=]*=//'`
R_ARCH="/${r_arch}"
;;
-e)
if test -n "`echo ${2} | ${SED} 's/^-.*//'`"; then
a=`echo "${2}" | ${SED} -e 's/ /~+~/g'`; shift
else
error "option '${1}' requires an argument"
fi
args="${args} -e $a"
;;
*)
args="${args} ${1}" ;;
esac
shift
done

. ${R_HOME}/etc${R_ARCH}/ldpaths

R_binary="${R_HOME}/bin/exec${R_ARCH}/R"
export R_ARCH

case "${gui}" in
Tk|tk|X11|x11)
;;
"")
;;
*)
error "unknown GUI ${gui}"
esac

## R_HOME may have moved, so check
if test -x "${R_HOME}"; then
:
else
error "R_HOME ('${R_HOME}') not found"
fi

## Startup
if test -z "${debugger}"; then
exec "${R_binary}" ${args} "${@}"
else
## Ideally, we would like the debugger to start R with additional
## ('inferior') arguments, but not all debuggers can do this. We know
## about valgrind and some versions of GDB , and deal with these.
## Otherwise, to be on the safe side, we disregard non-debugger
## command line args.
args_ok=no
case "`${debugger} --version 2>/dev/null`" in
"GNU gdb"*)
if ${debugger} --help 2>/dev/null | \
grep ' *--args' >/dev/null; then
args_ok=yes
debugger_args="${debugger_args} --args"
fi
;;
valgrind*)
args_ok=yes
;;
esac
if test -n "${args}${*}" && test "${args_ok}" = no; then
args=`expr "${args} ${*}" : " *\(.*\)"`
echo "*** Further command line arguments ('${args}') disregarded"
echo "*** (maybe use 'run ${args}' from *inside* ${debugger})"
echo ""
exec ${debugger} ${debugger_args} "${R_binary}"
else
exec ${debugger} ${debugger_args} "${R_binary}" ${args} "${@}"
fi
fi

### Local Variables: ***
### mode: sh ***
### sh-indentation: 2 ***
### End: ***


I haven't been able to figure out how to get R to find files it needs when invoked from within Eclipse.

Any help will be greatly appreciated.

thanks,

Russ
Re: Using autotools & valgrind for compiling an R library [message #517481 is a reply to message #516677] Sun, 28 February 2010 10:49 Go to previous message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member

Hi Elliott,

I just figured it out. R also creates an executable Rscript, which does the same thing as the "R" script. I could start valgrind-R using this executable.

thanks again for all your help.

Russ
Re: Using autotools & valgrind for compiling an R library [message #517487 is a reply to message #517481] Sun, 28 February 2010 06:48 Go to previous message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
That's great! Glad to help.

--Elliott
Re: Using autotools & valgrind for compiling an R library [message #568434 is a reply to message #516693] Wed, 24 February 2010 18:05 Go to previous message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Hi Elliott,

Thanks for the quick response.

(1)

> R -d "valgrind --tool=memcheck --leak-check=full --log-file=logout" --vanilla --slave < simple.R

valgrind logfile is produced with full output.

(2)

> valgrind --tool=memcheck --leak-check=full --log-file=logout R --vanilla < simple.R


R runs the commands and produces correct results on console, but valgrind logfile includes only the banner:
==6863== Memcheck, a memory error detector
==6863== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==6863== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for copyright info
==6863== Command: R --vanilla
==6863== Parent PID: 6499
==6863==
No other output is produced.
including/excluding --slave has no effect. -d is the command to invoke debugger from R.

Does this have anything to do with the fact that R is an "interactive" program and the "main" really sets up a wait-loop?? As I understand it calling R allows interactive debugging.

How do I do this from within Eclipse, so that I can locate errors within source files etc.

thanks again for all your help,

Russ
Re: Using autotools & valgrind for compiling an R library [message #568458 is a reply to message #568434] Wed, 24 February 2010 23:56 Go to previous message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
Hi Russ,

On 02/24/2010 06:05 PM, Russ wrote:
>> valgrind --tool=memcheck --leak-check=full --log-file=logout R
>> --vanilla < simple.R
>
>
> R runs the commands and produces correct results on console, but
> valgrind logfile includes only the banner:
> ==6863== Memcheck, a memory error detector
> ==6863== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
> ==6863== Using Valgrind-3.5.0-Debian and LibVEX; rerun with -h for
> copyright info
> ==6863== Command: R --vanilla
> ==6863== Parent PID: 6499
> ==6863== No other output is produced.
A guess is that R is spawning an process, which Valgrind is not
instrumenting. Try adding --trace-children=yes to the valgrind command line.

>
> Does this have anything to do with the fact that R is an "interactive"
> program and the "main" really sets up a wait-loop?? As I understand it
> calling R allows interactive debugging.
> How do I do this from within Eclipse, so that I can locate errors within
> source files etc.
Even for interactive programs, Valgrind should wait until the program
terminates.

Thanks,
Elliott
Re: Using autotools & valgrind for compiling an R library [message #568478 is a reply to message #516770] Thu, 25 February 2010 10:31 Go to previous message
Russ  is currently offline Russ
Messages: 13
Registered: February 2010
Junior Member
Adding trace-children indeed produced complete output.


>valgrind --tool=memcheck --leak-check=full --trace-children=yes --log-file=logout R --vanilla < simple.R


I will now try to replicate it from within Eclipse. If I understand correctly. I would do the following:
Compile my-pkg as a dynamic library
Compile R
Call valgrind with appropriate parameters, and call R as an application, passing other arguments. I will report back the results.

Thanks again,

Russ
Re: Using autotools & valgrind for compiling an R library [message #568499 is a reply to message #516959] Thu, 25 February 2010 22:21 Go to previous message
Elliott Baron is currently offline Elliott Baron
Messages: 28
Registered: July 2009
Junior Member
Hi Russ,

On 02/25/2010 10:31 AM, Russ wrote:
> Adding trace-children indeed produced complete output.
>
>> valgrind --tool=memcheck --leak-check=full --trace-children=yes
>> --log-file=logout R --vanilla < simple.R
That's great news!

> I will now try to replicate it from within Eclipse. If I understand
> correctly. I would do the following:
> Compile my-pkg as a dynamic library
> Compile R
> Call valgrind with appropriate parameters, and call R as an application,
> passing other arguments. I will report back the results.
Yes, in this case you would create a new Valgrind Profile Configuration
for R, in the arguments tab you could add --vanilla. To use your R file,
from what I read there is a -f option for R to specify a script to run.
So under the arguments tab put: --vanilla -f simple.R
Under the Valgrind Options tab make sure to check "Trace children on
exec", and you should be ready to go. The log file option is implicitly
used to gather the output to display. Let me know how it goes.

Thanks,
Elliott
Previous Topic:C++ Unit Testing Framework
Next Topic:Using autotools & valgrind for compiling an R library
Goto Forum:
  


Current Time: Thu Aug 21 14:06:48 EDT 2014

Powered by FUDForum. Page generated in 0.05159 seconds