我使用gperftools使用RCpp解析R脚本正确吗? [英] Is my using gperftools to profile a R script with RCpp correct?
问题描述
我正在尝试使用 http://pj.freefaculty.org/blog/?p=140 .我想知道我做的事(如下所述)是正确的吗?
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?
首先,在 my.cpp
中,该链接说要添加 #include< gperftools/profiler.h>
,对我不起作用.我发现标题位于不同的位置dir,对我有用的是 #include< google/profiler.h>
.
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()
接下来,我创建了一个脚本mytest.R,其中包含以下内容
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
最后,当我在bash中运行
Lastly, when I run in bash
$ R -f mytest.R
它运行R会话,在R中运行 mytest.R
的内容,并在输出后退出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.
它确实使用
$ google-pprof --text /usr/bin/R myprofile.log
我可以看到
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!
推荐答案
代替
google-pprof --text /usr/bin/R myprofile.log
如果使用 verbose = T
发出sourceCpp,您将看到文件路径和生成的目标文件...
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
这篇关于我使用gperftools使用RCpp解析R脚本正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!