gpt4 book ai didi

c++ - 我使用 gperftools 来分析带有 RCpp 的 R 脚本是否正确?

转载 作者:太空宇宙 更新时间:2023-11-04 11:33:31 26 4
gpt4 key购买 nike

我正在尝试使用 http://pj.freefaculty.org/blog/?p=140 中的最后(第三种)方法分析 R 脚本.我想知道我所做的(如下所述)是否正确?

首先,在my.cpp ,链接说要添加 #include <gperftools/profiler.h> , 哪个对我不起作用。我发现标题位于不同的位置目录,对我有用的是 #include <google/profiler.h> .

然后我将以下代码放在要分析的代码周围

ProfilerStart("./myprofile.log") 
//the part of the code to be profiled
ProfilerStop()

接下来,我创建了一个脚本 mytest.R,其中包含以下内容

Sys.setenv("PKG_LIBS"="-lprofiler")
sourceCpp('my.cpp') # for compiling the cpp file
... (use some functions defined in my.cpp

最后,当我在 bash 中运行时

$ R -f mytest.R

它运行一个 R session ,运行 mytest.R 的内容R内部,输出后退出R

PROFILE: interrupts/evictions/bytes = 353/0/1988

这是否意味着分析已成功运行? “中断”和“驱逐”在我看来很麻烦。

它确实会生成分析输出到 myprofile.log , 与

$ 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

最后一列中没有条目是人类可读的,所以我想知道是否有什么方法可以使它们可读?

我想知道我是否错过了什么?谢谢!

最佳答案

代替

google-pprof --text /usr/bin/R myprofile.log

如果您使用 verbose=T 发出 sourceCpp,您将看到文件路径和生成的目标文件...

Building shared library
--------------------------------------------------------

DIR: /tmp/RtmpyxYB19/sourcecpp_79831e029f

/usr/lib/R/bin/R CMD SHLIB -o 'sourceCpp_2.so' --->8---

所以尝试使用(在这种情况下)

google-pprof --text /tmp/RtmpyxYB19/sourcecpp_79831e029f/sourceCpp_2.so myprofile.log

关于c++ - 我使用 gperftools 来分析带有 RCpp 的 R 脚本是否正确?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23685206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com