问题
I am trying to profile a R script with the last (third) approach in http://pj.freefaculty.org/blog/?p=140. I wonder if what I do (described in the following) is correct?
Firstly, in my.cpp
, the link says to add #include <gperftools/profiler.h>
, which
doesn't work for me. I found that the header is located in a different
dir, and what works for me is #include <google/profiler.h>
.
Then I put the following around some code to be profiled
ProfilerStart("./myprofile.log")
//the part of the code to be profiled
ProfilerStop()
Next, I created a script mytest.R, which contains the following
Sys.setenv("PKG_LIBS"="-lprofiler")
sourceCpp('my.cpp') # for compiling the cpp file
... (use some functions defined in my.cpp
Lastly, when I run in bash
$ R -f mytest.R
it runs a R session, run the content of mytest.R
inside R, and exit R after outputting
PROFILE: interrupts/evictions/bytes = 353/0/1988
Does it mean the profiling was run successfully, or not? "interrupts" and "evictions" look troublesome to me.
It does generate the profiling output to myprofile.log
, with
$ google-pprof --text /usr/bin/R myprofile.log
I can see
Total: 353 samples
37 10.5% 10.5% 37 10.5% b313b2cb
21 5.9% 16.4% 21 5.9% b313b2b8
18 5.1% 21.5% 18 5.1% b313b2ce
15 4.2% 25.8% 15 4.2% _IO_str_pbackfail
10 2.8% 28.6% 10 2.8% b69be532
9 2.5% 31.2% 9 2.5% b69be520
7 2.0% 33.1% 7 2.0% b69bd111
6 1.7% 34.8% 6 1.7% b313b2dc
6 1.7% 36.5% 6 1.7% b69bd132
5 1.4% 38.0% 5 1.4% b69bb50f
5 1.4% 39.4% 5 1.4% b69bb6d8
4 1.1% 40.5% 4 1.1% b3133bda
4 1.1% 41.6% 4 1.1% b3134c2b
4 1.1% 42.8% 4 1.1% b313b298
4 1.1% 43.9% 4 1.1% b69bd159
3 0.8% 44.8% 3 0.8% b3134c32
3 0.8% 45.6% 3 0.8% b313b29b
3 0.8% 46.5% 3 0.8% b313b2c8
3 0.8% 47.3% 3 0.8% b69bb6e0
3 0.8% 48.2% 3 0.8% b69bb6f1
3 0.8% 49.0% 3 0.8% b69bcef1
3 0.8% 49.9% 3 0.8% b69bd100
No entry in the last column is human-readable, so I wonder if some way to make them readable?
I wonder if I miss something? Thanks!
回答1:
Instead of
google-pprof --text /usr/bin/R myprofile.log
if you issue sourceCpp with verbose=T
you'll see the file path and generated object file...
Building shared library
--------------------------------------------------------
DIR: /tmp/RtmpyxYB19/sourcecpp_79831e029f
/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.so' --->8---
so try using (in this instance)
google-pprof --text /tmp/RtmpyxYB19/sourcecpp_79831e029f/sourceCpp_2.so myprofile.log
来源:https://stackoverflow.com/questions/23685206/is-my-using-gperftools-to-profile-a-r-script-with-rcpp-correct