1

我正在尝试使用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 会话,运行mytest.RR 内部的内容,并在输出后退出 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

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

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

4

1 回答 1

1

代替

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

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

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
于 2015-12-06T23:01:37.743 回答