天天看点

堆外内存分析

堆外内存分析

需要安装google-perftools工具进行分析

安装g++

不然编译会报错:g++: command not found,已经安装可忽略

yum -y install gcc gcc-c++
           

安装libunwind

不建议版本>0.99据说有问题,这个需要FQ

# wgethttp://download.savannah.gnu.org/releases/libunwind/libunwind-0.99.tar.gz
# tar -xzvf libunwind-0.99.tar.gz
# cd libunwind-0.99
# ./configure  --prefix=/data0/java/deploy/google-perftools/local/libunwind
# make && make install
           

安装gperftools

# cd /data/software
# wget https://github.com/gperftools/gperftools/releases/download/gperftools-2.6.1/gperftools-2.6.1.tar.gz
# tar -xzvf gperftools-2.6.1.tar.gz
# cd gperftools-2.6.1
# ./configure --prefix=/data/gperftools/
# make && make install
           

使配置生效

# vim /etc/ld.so.conf.d/usr_local_lib.conf
           

新增以下内容按i

/data/gperftools/lib
           

按esc再:wq! #保存退出

执行

/sbin/ldconfig

执行此命令,使libunwind生效。 需要sudo权限

加入环境变量

export LD_PRELOAD=/data/gperftools/lib/libtcmalloc.so
export HEAPPROFILE=/data/gperftools/local/tmp/gzip
           

启动程序

就会在

/data/gperftools/local/tmp

目录下生成heap文件

total 13164
-rw-r----- 1 root root  895942 Apr 12 17:45 gzip_33981.0001.heap
-rw-r----- 1 root root 1048567 Apr 12 17:45 gzip_33981.0002.heap
-rw-r----- 1 root root 1048574 Apr 12 17:45 gzip_33981.0003.heap
-rw-r----- 1 root root 1048570 Apr 12 17:46 gzip_33981.0004.heap
-rw-r----- 1 root root 1048561 Apr 12 17:47 gzip_33981.0005.heap
-rw-r----- 1 root root 1048574 Apr 12 17:52 gzip_33981.0006.heap
-rw-r----- 1 root root 1048562 Apr 12 17:54 gzip_33981.0007.heap
-rw-r----- 1 root root 1048561 Apr 12 17:54 gzip_33981.0008.heap
-rw-r----- 1 root root 1048565 Apr 12 17:54 gzip_33981.0009.heap
-rw-r----- 1 root root 1048562 Apr 12 17:54 gzip_33981.0010.heap
-rw-r----- 1 root root 1048569 Apr 12 17:54 gzip_33981.0011.heap
-rw-r----- 1 root root 1048574 Apr 12 17:54 gzip_33981.0012.heap
-rw-r----- 1 root root 1048564 Apr 12 17:54 gzip_33981.0013.heap
           

如果是持续运行的程序需要ctrl+c会生成dump文件。

分析函数调用

/data/gperftools/bin/pprof --text /home/app/predictor-serving/jdk/bin/java  /data/gperftools/local/tmp/gzip_33981.0013.heap
           

下面就是分析的函数:

Total: 121557.3 MB
121493.2  99.9%  99.9% 121493.2  99.9% os::[email protected]
    45.7   0.0% 100.0%     45.7   0.0% init
    13.3   0.0% 100.0%     13.3   0.0% updatewindow
     2.9   0.0% 100.0%      2.9   0.0% inflateInit2_
     1.6   0.0% 100.0%      1.6   0.0% readCEN
     0.3   0.0% 100.0%      0.3   0.0% __GI__dl_allocate_tls
     0.0   0.0% 100.0%      1.7   0.0% ZIP_Put_In_Cache0
     0.0   0.0% 100.0%      3.0   0.0% Java_java_util_zip_Inflater_init
     0.0   0.0% 100.0%      0.0   0.0% newEntry
     0.0   0.0% 100.0%      0.0   0.0% __GI___strdup
     0.0   0.0% 100.0%      0.0   0.0% _dl_new_object
     0.0   0.0% 100.0%      0.0   0.0% _dlerror_run
     0.0   0.0% 100.0%      0.0   0.0% read_alias_file
     0.0   0.0% 100.0%      0.0   0.0% _nl_intern_locale_data
     0.0   0.0% 100.0%      0.0   0.0% _dl_check_map_versions
     0.0   0.0% 100.0%      0.0   0.0% _dl_map_object_deps
     0.0   0.0% 100.0%      0.0   0.0% nss_parse_service_list
     0.0   0.0% 100.0%      0.0   0.0% __new_exitfn
     0.0   0.0% 100.0%      0.0   0.0% getpwuid
     0.0   0.0% 100.0%      0.0   0.0% _nl_make_l10nflist
     0.0   0.0% 100.0%     16.7   0.0% Java_java_lang_ClassLoader_defineClass1
     0.0   0.0% 100.0%      0.0   0.0% __fopen_internal
     0.0   0.0% 100.0%      0.0   0.0% _dl_scope_free
     0.0   0.0% 100.0%      0.0   0.0% __GI___nss_database_lookup
     0.0   0.0% 100.0%      0.0   0.0% JLI_MemAlloc
     0.0   0.0% 100.0%      0.0   0.0% _dl_signal_error
     0.0   0.0% 100.0%      0.0   0.0% expand_dynamic_string_token
     0.0   0.0% 100.0%      0.0   0.0% __res_context_send
     0.0   0.0% 100.0%      0.0   0.0% initLoopbackRoutes
     0.0   0.0% 100.0%      0.0   0.0% __add_to_environ
     0.0   0.0% 100.0%      0.0   0.0% Java_java_lang_UNIXProcess_init
     0.0   0.0% 100.0%      0.0   0.0% dl_open_worker
     0.0   0.0% 100.0%      0.0   0.0% __tzfile_read
     0.0   0.0% 100.0%      0.0   0.0% os::realloc
     0.0   0.0% 100.0%      0.0   0.0% __GI___libc_alloc_buffer_allocate
     0.0   0.0% 100.0%      0.0   0.0% add_to_global
     0.0   0.0% 100.0%      0.0   0.0% _nl_load_locale_from_archive
     0.0   0.0% 100.0%      0.0   0.0% get_locked_global
     0.0   0.0% 100.0%      1.5   0.0% 0x00007f27f11811b8
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f1181399
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118dd48
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118f0a0
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118f0ae
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118f517
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118f6bb
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f118f6c9
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f1190000
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f119000e
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f1193951
     0.0   0.0% 100.0% 107445.5  88.4% 0x00007f27f1193ab3
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f1194008
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f1194016
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f11954ba
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f11954c8
     0.0   0.0% 100.0%      0.0   0.0% 0x00007f27f119561f