在CentOS环境下进行C++性能测试,可从基准测试、性能分析、压力测试等方面入手,常用工具及方法如下:
sysbench cpu --threads=4 --events=10000 --time=0 run。sysbench memory --memory-block-size=1M --memory-total-size=10G run。fio工具(需安装)可测试随机读写IOPS及带宽。perf stat ./程序。perf record -g ./程序,生成火焰图直观展示瓶颈。-pg选项,生成函数调用图及耗时分析。valgrind --leak-check=full ./程序。valgrind --tool=callgrind ./程序,配合kcachegrind可视化。stress -c 2(2个CPU核心)。stress -vm 2 -vm-bytes 2000M(2个线程,分配2GB内存)。常用工具可通过yum安装:
sudo yum install sysbench fio perf gprof valgrind gcc-c++
Helgrind(Valgrind工具集)分析。Valgrind,CPU密集型优先用perf或gprof。参考资料:[1,2,3,4,5,6,7,8,9,10]