2015-09-10 34 views
1

在本talk建議通過Dirk Eddelbuettel串之外,這answer我試着用gperftools剖析編譯R代碼裏面。這是我做的。gperftools錯誤:SUBSTR位於/ usr/local/bin目錄/ pprof線3618

我使用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。

回答

2

我有同樣的問題,但意識到我的問題。我做:

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

如果我跑testprog後停止了教授的文件是不是空的,但pprof後,這是。 pprof與substr錯誤墜毀。

我後來意識到的是,通過設置和導出LD_PRELOADlibprofiler.so也加載了pprof,覆蓋test.prof。 您只需確保在運行pprof時未設置LD_PRELOAD

0

我使用gperftools-2.5,我也遇到了同樣的問題:

[[email protected] 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 

,我發現這是因爲(在我的例子ivr.prof)的教授文件是空的。

每次探查開始和結束,它會創建一個新的文件教授,你應該使用xxx.prof.0 xxx.prof.1 ...得到正確的結果