mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add gperf to heap check, use reload signal to terminate program normally
This commit is contained in:
parent
03a14e2e1a
commit
dcd568a0d7
6 changed files with 55 additions and 11 deletions
|
@ -448,3 +448,15 @@ if [ $SRS_GPERF = YES ]; then
|
||||||
ret=$?; if [[ $ret -ne 0 ]]; then echo "build gperftools-2.1 failed, ret=$ret"; exit $ret; fi
|
ret=$?; if [[ $ret -ne 0 ]]; then echo "build gperftools-2.1 failed, ret=$ret"; exit $ret; fi
|
||||||
if [ ! -f ${SRS_OBJS}/gperf/bin/pprof ]; then echo "build gperftools-2.1 failed."; exit -1; fi
|
if [ ! -f ${SRS_OBJS}/gperf/bin/pprof ]; then echo "build gperftools-2.1 failed."; exit -1; fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $SRS_GPERF = YES ]; then
|
||||||
|
echo "#define SRS_GPERF" >> $SRS_AUTO_HEADERS_H
|
||||||
|
#echo "#define SRS_GPERF_CPU_PROFILE" >> $SRS_AUTO_HEADERS_H
|
||||||
|
#echo "#define SRS_GPERF_HEAP_PROFILE" >> $SRS_AUTO_HEADERS_H
|
||||||
|
echo "#define SRS_GPERF_HEAP_CHECK" >> $SRS_AUTO_HEADERS_H
|
||||||
|
else
|
||||||
|
echo "#undef SRS_GPERF" >> $SRS_AUTO_HEADERS_H
|
||||||
|
echo "#undef SRS_GPERF_CPU_PROFILE" >> $SRS_AUTO_HEADERS_H
|
||||||
|
echo "#undef SRS_GPERF_HEAP_PROFILE" >> $SRS_AUTO_HEADERS_H
|
||||||
|
echo "#undef SRS_GPERF_HEAP_CHECK" >> $SRS_AUTO_HEADERS_H
|
||||||
|
fi
|
||||||
|
|
18
trunk/configure
vendored
18
trunk/configure
vendored
|
@ -138,8 +138,6 @@ END
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# build tools or compiler args.
|
# build tools or compiler args.
|
||||||
# the performance analysis, uncomments the following when use gperf to analysis the performance. see third-party/readme.txt
|
|
||||||
Performance="-pg"
|
|
||||||
# enable gdb debug
|
# enable gdb debug
|
||||||
GDBDebug="-g -O0"
|
GDBDebug="-g -O0"
|
||||||
# the warning level.
|
# the warning level.
|
||||||
|
@ -150,7 +148,7 @@ CppStd="-ansi"
|
||||||
LibraryCompile="-fPIC"
|
LibraryCompile="-fPIC"
|
||||||
# the cxx flag generated.
|
# the cxx flag generated.
|
||||||
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${LibraryCompile}"
|
CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${LibraryCompile}"
|
||||||
#CXXFLAGS="${CppStd} ${WarnLevel} ${GDBDebug} ${Performance}"
|
if [ $SRS_GPERF = YES ]; then CXXFLAGS="${CXXFLAGS} -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free"; fi
|
||||||
cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
|
cat << END > ${SRS_OBJS}/${SRS_MAKEFILE}
|
||||||
CC ?= gcc
|
CC ?= gcc
|
||||||
GCC ?= gcc
|
GCC ?= gcc
|
||||||
|
@ -178,6 +176,9 @@ if [ $SRS_HTTP = YES ]; then LibHttpParserRoot="${SRS_OBJS}/hp"; LibHttpParserfi
|
||||||
# openssl-1.0.1f, for the RTMP complex handshake.
|
# openssl-1.0.1f, for the RTMP complex handshake.
|
||||||
LibSSLRoot="";LibSSLfile=""
|
LibSSLRoot="";LibSSLfile=""
|
||||||
if [ $SRS_SSL = YES ]; then LibSSLRoot="${SRS_OBJS}/openssl/include"; LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"; fi
|
if [ $SRS_SSL = YES ]; then LibSSLRoot="${SRS_OBJS}/openssl/include"; LibSSLfile="${SRS_OBJS}/openssl/lib/libssl.a ${SRS_OBJS}/openssl/lib/libcrypto.a"; fi
|
||||||
|
# gperftools-2.1, for mem check and mem/cpu profile
|
||||||
|
LibGperfRoot=""; LibGperfFile=""
|
||||||
|
if [ $SRS_GPERF = YES ]; then LibGperfRoot="${SRS_OBJS}/gperf/include"; LibGperfFile="${SRS_OBJS}/gperf/lib/libtcmalloc_and_profiler.a"; fi
|
||||||
|
|
||||||
#####################################################################################
|
#####################################################################################
|
||||||
# Modules, compile each module, then link to binary
|
# Modules, compile each module, then link to binary
|
||||||
|
@ -229,7 +230,7 @@ LIBS_OBJS="${MODULE_OBJS[@]}"
|
||||||
#Main Module
|
#Main Module
|
||||||
MODULE_ID="MAIN"
|
MODULE_ID="MAIN"
|
||||||
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
|
MODULE_DEPENDS=("CORE" "KERNEL" "RTMP" "APP")
|
||||||
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS})
|
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS} ${LibGperfRoot})
|
||||||
MODULE_FILES=("srs_main_server" "srs_main_bandcheck")
|
MODULE_FILES=("srs_main_server" "srs_main_bandcheck")
|
||||||
MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
|
MAIN_INCS="src/main"; MODULE_DIR=${MAIN_INCS} . auto/modules.sh
|
||||||
MAIN_OBJS="${MODULE_OBJS[@]}"
|
MAIN_OBJS="${MODULE_OBJS[@]}"
|
||||||
|
@ -242,10 +243,11 @@ MAIN_OBJS="${MODULE_OBJS[@]}"
|
||||||
MAIN_ENTRANCES=("srs_main_server" "srs_main_bandcheck")
|
MAIN_ENTRANCES=("srs_main_server" "srs_main_bandcheck")
|
||||||
#
|
#
|
||||||
# all depends libraries
|
# all depends libraries
|
||||||
ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile})
|
ModuleLibFiles=(${LibSTfile} ${LibHttpParserfile} ${LibSSLfile} ${LibGperfFile})
|
||||||
# all depends objects
|
# all depends objects
|
||||||
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
|
MODULE_OBJS="${CORE_OBJS[@]} ${KERNEL_OBJS[@]} ${RTMP_OBJS[@]} ${APP_OBJS[@]} ${MAIN_OBJS[@]}"
|
||||||
LINK_OPTIONS="-ldl"
|
LINK_OPTIONS="-ldl"
|
||||||
|
if [ $SRS_GPERF = YES ]; then LINK_OPTIONS="${LINK_OPTIONS} -lpthread"; fi
|
||||||
#
|
#
|
||||||
# srs:
|
# srs:
|
||||||
# srs(simple rtmp server) over st(state-threads)
|
# srs(simple rtmp server) over st(state-threads)
|
||||||
|
@ -335,4 +337,8 @@ fi
|
||||||
if [ $SRS_HTTP = YES ]; then
|
if [ $SRS_HTTP = YES ]; then
|
||||||
echo -e "\" python ./research/api-server/server.py 8085 \" to start the api-server"
|
echo -e "\" python ./research/api-server/server.py 8085 \" to start the api-server"
|
||||||
fi
|
fi
|
||||||
echo "\" ./objs/srs -c conf/srs.conf \" to start the srs live server"
|
if [ $SRS_GPERF = YES ]; then
|
||||||
|
echo "\" env HEAPCHECK=normal ./objs/srs -c conf/srs.conf \" to start the srs live server"
|
||||||
|
else
|
||||||
|
echo "\" ./objs/srs -c conf/srs.conf \" to start the srs live server"
|
||||||
|
fi
|
||||||
|
|
2
trunk/research/gperftools/cpu-profiler/Makefile
Executable file → Normal file
2
trunk/research/gperftools/cpu-profiler/Makefile
Executable file → Normal file
|
@ -7,4 +7,4 @@ cpu_profiler: cpu_profiler.cc Makefile
|
||||||
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
|
-fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-free \
|
||||||
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_and_profiler.a -lpthread
|
-I../../../objs/gperf/include ../../../objs/gperf/lib/libtcmalloc_and_profiler.a -lpthread
|
||||||
clean:
|
clean:
|
||||||
rm -f cpu_profiler ./srs.conf*
|
rm -f cpu_profiler ./srs.prof*
|
||||||
|
|
|
@ -26,11 +26,11 @@ config srs with gperf(to make gperftools):
|
||||||
set the pprof path if not set:
|
set the pprof path if not set:
|
||||||
export PPROF_PATH=`pwd`/../../../objs/pprof
|
export PPROF_PATH=`pwd`/../../../objs/pprof
|
||||||
to do cpu profile:
|
to do cpu profile:
|
||||||
make && rm -f ./srs.conf* && env CPUPROFILE=./srs.conf ./cpu_profiler
|
make && rm -f ./srs.prof* && env CPUPROFILE=./srs.prof ./cpu_profiler
|
||||||
$PPROF_PATH --text cpu_profiler ./srs.conf*
|
$PPROF_PATH --text cpu_profiler ./srs.prof*
|
||||||
to do cpu profile by signal:
|
to do cpu profile by signal:
|
||||||
make && rm -f ./srs.conf* && env CPUPROFILE=./srs.conf CPUPROFILESIGNAL=12 ./cpu_profiler
|
make && rm -f ./srs.prof* && env CPUPROFILE=./srs.prof CPUPROFILESIGNAL=12 ./cpu_profiler
|
||||||
$PPROF_PATH --text cpu_profiler ./srs.conf*
|
$PPROF_PATH --text cpu_profiler ./srs.prof*
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
|
@ -233,6 +233,14 @@ int SrsServer::cycle()
|
||||||
srs_update_system_time_ms();
|
srs_update_system_time_ms();
|
||||||
|
|
||||||
if (signal_reload) {
|
if (signal_reload) {
|
||||||
|
// for gperf heap checker,
|
||||||
|
// @see: research/gperftools/heap-checker/heap_checker.cc
|
||||||
|
// if user interrupt the program, exit to check mem leak.
|
||||||
|
// but, if gperf, use reload to terminate the server,
|
||||||
|
// for the SIGINT will cause core-dump.
|
||||||
|
#ifdef SRS_GPERF
|
||||||
|
break;
|
||||||
|
#endif
|
||||||
signal_reload = false;
|
signal_reload = false;
|
||||||
srs_info("get signal reload, to reload the config.");
|
srs_info("get signal reload, to reload the config.");
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,13 @@ SrsServer* _srs_server = new SrsServer();
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#ifdef SRS_GPERF_HEAP_PROFILE
|
||||||
|
#include <gperftools/heap-profiler.h>
|
||||||
|
#endif
|
||||||
|
#ifdef SRS_GPERF_CPU_PROFILE
|
||||||
|
#include <gperftools/profiler.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
void handler(int signo)
|
void handler(int signo)
|
||||||
{
|
{
|
||||||
srs_trace("get a signal, signo=%d", signo);
|
srs_trace("get a signal, signo=%d", signo);
|
||||||
|
@ -47,6 +54,17 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
#ifdef SRS_GPERF_HEAP_CHECK
|
||||||
|
// env HEAPCHECK=normal ./objs/srs -c srs.conf
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef SRS_GPERF_HEAP_PROFILE
|
||||||
|
HeapProfilerStart("gperf.srs");
|
||||||
|
#endif
|
||||||
|
#ifdef SRS_GPERF_CPU_PROFILE
|
||||||
|
ProfilerStart("gperf.srs.prof");
|
||||||
|
#endif
|
||||||
|
|
||||||
signal(SIGNAL_RELOAD, handler);
|
signal(SIGNAL_RELOAD, handler);
|
||||||
|
|
||||||
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue