安装:++++++++++++++
TCMalloc (google-perftools) 是用于优化C++写的多线程应用,比glibc 2.3的malloc快。这个模块可以用来让MySQL在高并发下内存占用更加稳定。
下载二个软件地址:
google-perftools:http://code.google.com/p/google-perftools/
libunwind:http://download.savannah.gnu.org/releases/libunwind/
安装步骤:
1.64 位操作系统请先安装 libunwind库,32位操作系统不要安装。libunwind库为基于64位CPU和操作系统的程序提供了基本的堆栈辗转开解功能,其中包括用于输出堆栈跟踪的API、用于以编程方式辗转开解堆栈的API以及支持C++异常处理机制的API。
#tar zxvf libunwind-0.9.tar.gz
#cd libunwind-0.99
#./configure
#make
#make install
2.安装google-perftools:
#tar zxvf google-perftools-1.6.tar.gz
#cd google-perftools-1.6
#./configure
#make
#make install
3.运行以下二行命令
echo "/usr/local/lib" > /etc/ld.so.conf.d/usr_local_lib.conf
/sbin/ldconfig
4.修改MySQL启动脚本(根据你的MySQL安装位置而定):
vi /usr/local/mysql/bin/mysqld_safe
在# executing mysqld_safe的下一行,加上:
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
保存后退出,然后重启MySQL服务器。
5.使用验证lsof命令查看tcmalloc是否起效:
如lsof没有装,可yum安装
/usr/sbin/lsof -n | grep tcmalloc
如果发现以下信息,说明tcmalloc已经起效:
mysqld 10847 mysql mem REG 8,5 1203756 20484960 /usr/local/lib/libtcmalloc.so.0.0.0
===========================
64位机器安装方法:
tar -zxvf libunwind-0.99-beta.tar.gz
cd libunwind-0.99-beta
CFLAGS=-fPIC ./configure --prefix=/usr
make CFLAGS=-fPIC
make CFLAGS=-fPIC install
tar -zxvf google-perftools-1.8.3.tar.gz
cd google-perftools-1.8.3
./configure --prefix=/usr
make
make install
echo "/usr/lib" > /etc/ld.so.conf.d/usr_lib.conf
/sbin/ldconfig
使用方法:
主函数:
#include <google/profiler.h>
main
{
ProfilerStart("outfile.prof");
int enable= ProfilingIsEnabledForAllThreads();
WriteLog("[CollectAS] Profiling Enabled: %d", enable);
………………………………
ProfilerStop();
}
每个线程添加注册函数:ProfilerRegisterThread();
此第三方软件在/usr 下,程序的makefile.am文件要包含库: -lprofiler
调用:
pprof --dot collect outfile.prof
利用graphviz将outfile.do生成图纸
=====================================
假设你已经安装好了这个开源工具
1) vim example.cpp
#include<iostream>
#include<stdlib.h>
//#include<google/profiler.h>
#include<stdio.h>
using namespace std;
void consumeSomeCPUTime1(int input){
int i = 0;
input++;
while(i++ < 10000){
i--; i++; i--; i++;
}
};
void consumeSomeCPUTime2(int input){
input++;
consumeSomeCPUTime1(input);
int i = 0;
while(i++ < 10000){
i--; i++; i--; i++;
}
};
int stupidComputing(int a, int b){
int i = 0;
while( i++ < 10000){
consumeSomeCPUTime1(i);
}
int j = 0;
while(j++ < 5000){
consumeSomeCPUTime2(j);
}
return a+b;
};
int smartComputing(int a, int b){
return a+b;
};
int main(){
int i = 0;
printf("reached the start point of performance bottle neck\n");
sleep(1);
// ProfilerStart("CPUProfile.prof");
while( i++ < 10){
printf("Stupid computing return : %d\n",stupidComputing(i, i+1));
printf("Smart computing return %d\n",smartComputing(i+1, i+2));
}
printf("should teminate profiling now.\n");
sleep(1);
// ProfilerStop();
return 0;
}
2)设置 LD_LIBRARY_PATH就是你的pprof的安装路径下的lib
3)设置CPUPROFILE的值如:CPUPROFILE=cpu;
这里还可以再源文件里面加入被注释掉的语句来设置cpuprofile输出的结果
如果是多线程的话就需要使用ProfilerRegisterThread();这样在每个线程执行的时候就注册了一次
4)编译g++ -g example.cpp -L/usr/local/lib/ -lprofiler -o example
5)执行example就会生成cpu文件
6)查看结果 pprof --text profile cpu>>t1.txt 这里是以text的格式查看函数调用关系 和耗时;也可以用--dot的格式查看;然后再将其转换成gif格式就可以看调用关系图:pprof --dot profile cpu>t1.dot
7)将dot文件下载到本地然后用Graphviz软件转换为gif格式就可以查看函数调用关系了
分享到:
相关推荐
google-perftools 是一款针对 C/C++ 程序的性能分析工具,它是一个遵守 BSD 协议的开源项目。使用该工具可以对 CPU 时间片、内存等系统资源的分配和使用进行分析,本文将重点介绍如何进行 CPU 时间片的剖析。 google...
google-perftools-1.6
google-perftools-1.8.3-1.el6.x86_64.rpm
google-perftools-1.8.2.tar.gz工具,帮助查看堆外内存
google_perftools是谷歌的内存池代码,可以支持嵌入程序。
支持nginx优化
使用Google tcmalloc进行内存申请释放,解决内存没有真正释放
下面为大家介绍google-perftools的安装,并配置Nginx和MySQL支持google-perftools。 首先,介绍如何优化Nginx: 1,首先下载并安装google-perftools: 注意,如果是64位系统: 那么你需要做:1)先安装libunwind或者2)在...
rack-perftools_profiler, 使用 perftools.rb 配置 rack 兼容应用程序的中间件 Rack::PerftoolsProfiler使用 perftools.rb 配置机架兼容应用的中间件快速启动假定应用程序使用 Rails 3 ( 你已经在下一节中安装了需求...
我们见过的最快的malloc; 与线程和STL配合使用特别好。 另外:线程友好的堆检查器,堆分析器和cpu分析器。
编译R18的时候,看lichee和android选择的是不一样的选项。 初步判断:在android中执行extract-bsp的时候,只是去上一级目录中查找lichee编译生成的内核。 先依葫芦画瓢,依照octopus-perf修改一个octopus-cb5801。...
使用全志的原生系统,lichee和android的编译选项都是perf3: android使用ENG模式编译,方便调试之用。 wenyuanbo@cm-System-Product-Name:/home/wwt/r58_bma250/lichee$ ./build.sh config Welcome to mkscript ...
编译R18的时候,看lichee和android选择的是不一样的选项。 初步判断:在android中执行extract-bsp的时候,只是去上一级目录中查找lichee编译生成的内核。 先依葫芦画瓢,依照octopus-perf修改一个octopus-cb5801。...
节点远程pprof 将为Express / Connect兼容路由器的库。 安装 npm install --save node-remote-pprof 用法 将/pprof端点添加到您的应用程序 ... 使用pprof工具来分析应用程序 pprof --web localhos
非常强大的Linux系统性能检测工具。非常强大的Linux系统性能检测工具。
PostgreSQL 性能监控工具 该软件包包括三个有用的脚本,旨在帮助查明以 PostgreSQL 作为数据库后端的系统上的性能问题。 所有脚本都是用 Python 编写的。 要求: Python 2.6+ psycopg2 模块 ( ) 所有脚本都需要...
离线安装包,亲测可用
深度Q学习改善自适应自组织网络案例 # Deep-Q-Learning-SON-Perf-Improvement The requirement for running this code is to obtain license and access of the Vienna LTE-A simulator, found at: ...
rabbitmq-perf-test-2.7.0-bin.tar.gz,这个是rabbitmq的压测工具,无需安装,直接下载解压。