SRS提供了一系列工具来定位性能瓶颈和内存泄漏,这些在./configure && make后的summary中是有给出来用法的,不过不是很方便,所以特地把用法写到这个文章中。

文中所有的工具,对于其他的linux程序也是有用的。

备注:所有工具用起来都会导致SRS性能低下,所以除非是排查问题,否则不要开启这些选项。

GPERF

GPERF是google tcmalloc提供的cpu和内存工具,参考GPERF

GMD

GMD是GPERF提供的内存Defense工具,检测内存越界和野指针。一般在越界写入时,可能不会立刻导致破坏,而是在切换到其他线程使用被破坏的对象时才会发现破坏了,所以这种内存问题很难排查;GMD能在越界和野指针使用时直接core dump,定位在那个出问题的地方。参考GMD

Usage:

# Build SRS with GMD.
./configure --with-gperf --with-gmd && make

# Start SRS with GMD.
env TCMALLOC_PAGE_FENCE=1 ./objs/srs -c conf/console.conf
 
  • 1
  • 2
  • 3
  • 4
  • 5

GMC

GMC是内存泄漏检测工具,参考GMC

Usage:

# Build SRS with GMC
./configure --with-gperf --with-gmc && make

# Start SRS with GMC
env PPROF_PATH=./objs/pprof HEAPCHECK=normal ./objs/srs -c conf/console.conf 2>gmc.log 

# Or CTRL+C to stop gmc
killall -2 srs

# To analysis memory leak
cat gmc.log
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

GMP

GMP是内存性能分析工具,譬如检测是否有频繁的申请和释放堆内存导致的性能问题。参考GMP

Usage:

# Build SRS with GMP
./configure --with-gperf --with-gmp && make

# Start SRS with GMP
./objs/srs -c conf/console.conf

# Or CTRL+C to stop gmp
killall -2 srs 

# To analysis memory profile
./objs/pprof --text objs/srs gperf.srs.gmp*
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

GCP

GCP是CPU性能分析工具,就是一般讲的性能瓶颈,看哪个函数调用占用过多的CPU。参考GCP

Usage:

# Build SRS with GCP
./configure --with-gperf --with-gcp && make

# Start SRS with GCP
./objs/srs -c conf/console.conf

# Or CTRL+C to stop GCP
killall -2 srs

# To analysis cpu profile
./objs/pprof --text objs/srs gperf.srs.gcp*
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

GPROF

GPROF是个GNU的CPU性能分析工具。参考SRS GPROF,以及GNU GPROF

Usage:

# Build SRS with GPROF
./configure --with-gprof && make

# Start SRS with GPROF
./objs/srs -c conf/console.conf

# Or CTRL+C to stop GPROF
killall -2 srs

# To analysis result.
gprof -b ./objs/srs gmon.out
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

VALGRIND

VALGRIND是大名鼎鼎的C分析工具,SRS因为使用了ST所以最初不支持VALGRIND的分析,所以需要给ST打PATCH才能用,目前还没有合并到SRS。

给ST打PATCH支持VALGRIND,参考state-threads,详细的信息可以参考ST#2