【问题标题】:gperftools Error: substr outside of string at /usr/local/bin/pprof line 3618gperftools 错误:/usr/local/bin/pprof 第 3618 行的字符串之外的 substr
【发布时间】:2015-09-10 17:34:09
【问题描述】:

正如Dirk Eddelbuettel 在这个talk 和这个answer 中建议的那样,我尝试使用gperftools 分析编译的R 代码。这就是我所做的。

我使用 Dirks profilingSmall.R 作为我想要分析的脚本。我在这里重复一遍:

## R Extensions manual, section 3.2 'Profiling R for speed'
## 'N' reduced to 99 here
suppressMessages(library(MASS))
suppressMessages(library(boot))
storm.fm <- nls(Time ~ b*Viscosity/(Wt - c), stormer, start = c(b=29.401, c=2.2183))
st <- cbind(stormer, fit=fitted(storm.fm))
storm.bf <- function(rs, i) {
    st$Time <-  st$fit + rs[i]
    tmp <- nls(Time ~ (b * Viscosity)/(Wt - c), st, start = coef(storm.fm))
    tmp$m$getAllPars()
}
rs <- scale(resid(storm.fm), scale = FALSE) # remove the mean
Rprof("boot.out")
storm.boot <- boot(rs, storm.bf, R = 99) # pretty slow
Rprof(NULL)

为了分析它,我运行以下脚本

LD_PRELOAD="/usr/lib/libprofiler.so.0" 
\CPUPROFILE=sample.log \
Rscript profilingSmall.R

然后我尝试使用解析日志文件

pprof /usr/bin/R sample.log

这返回了以下错误

Using local file /usr/bin/R.
Using local file sample.log.
substr outside of string at /usr/local/bin/pprof line 3618.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3618.
substr outside of string at /usr/local/bin/pprof line 3620.
Use of uninitialized value in string eq at /usr/local/bin/pprof line 3620.
sample.log: header size >= 2**16

sample.log 为空。但是,创建了一堆包含看起来合理的信息的 sample.log_digit。

【问题讨论】:

    标签: r profiling


    【解决方案1】:

    我有同样的问题,但意识到我的问题。我已经完成了:

    export CPUPROFILE=test.prof
    export LD_PRELOAD="/usr/local/lib/libprofiler.so"
    testprog ...
    pprof --web `which testprog` test.prof
    

    如果我在运行 testprog 后停止,则 prof 文件不是空的,但在 pprof 之后它是空的。 pprof 因 substr 错误而崩溃。

    我后来意识到,通过设置和导出LD_PRELOADlibprofiler.so 也为pprof 加载,覆盖test.prof。 您只需要确保在运行pprof 时未设置LD_PRELOAD

    【讨论】:

      【解决方案2】:

      我用的是gperftools-2.5,也遇到了同样的问题:

      [root@localhost ivrserver]# pprof --text ./IvrServer ivr.prof
      Using local file ./IvrServer.
      Using local file ivr.prof.
      substr outside of string at /usr/local/bin/pprof line 3695.
      Use of uninitialized value in string eq at /usr/local/bin/pprof line 3695.
      substr outside of string at /usr/local/bin/pprof line 3697.
      Use of uninitialized value in string eq at /usr/local/bin/pprof line 3697.
      ivr.prof: header size >= 2**16
      

      我发现这是因为 prof 文件(在我的示例中为 ivr.prof)是空的。

      profiler 每次启动和结束都会创建一个新的 prof 文件,你应该使用 xxx.prof.0 xxx.prof.1 ... 以获得正确的结果

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-08-05
        • 2014-12-17
        • 2020-05-05
        • 2012-07-05
        • 1970-01-01
        • 2019-01-15
        相关资源
        最近更新 更多