diff --git a/trunk/auto/auto_headers.sh b/trunk/auto/auto_headers.sh index 635b9edb8..8723824a5 100755 --- a/trunk/auto/auto_headers.sh +++ b/trunk/auto/auto_headers.sh @@ -136,6 +136,12 @@ else echo "#undef SRS_AUTO_SSL" >> $SRS_AUTO_HEADERS_H fi +if [ $SRS_MEM_WATCH = YES ]; then + echo "#define SRS_AUTO_MEM_WATCH" >> $SRS_AUTO_HEADERS_H +else + echo "#undef SRS_AUTO_MEM_WATCH" >> $SRS_AUTO_HEADERS_H +fi + # whether compile ffmpeg tool if [ $SRS_FFMPEG_TOOL = YES ]; then echo "#define SRS_AUTO_FFMPEG_TOOL" >> $SRS_AUTO_HEADERS_H diff --git a/trunk/auto/options.sh b/trunk/auto/options.sh index 14c2602a8..c527cc2e6 100755 --- a/trunk/auto/options.sh +++ b/trunk/auto/options.sh @@ -60,6 +60,9 @@ SRS_LOG_TRACE=RESERVED # experts # donot compile ssl, use system ssl(-lssl) if required. SRS_USE_SYS_SSL=NO +# enable memory watch, detect memory leak, +# similar to gmc, should disable in release version for hurts performance. +SRS_MEM_WATCH=NO # export the srs-librtmp to specified project, NO to disable it. SRS_EXPORT_LIBRTMP_PROJECT=NO # export the srs-librtmp to a single .h and .c, NO to disable it. @@ -195,6 +198,7 @@ Conflicts: Experts: --use-sys-ssl donot compile ssl, use system ssl(-lssl) if required. + --memory-watch enable memory watch to detect memory leaking(hurts performance). --export-librtmp-project= export srs-librtmp to specified project in path. --export-librtmp-single= export srs-librtmp to a single file(.h+.cpp) in path. @@ -283,6 +287,7 @@ function parse_user_option() { --full) SRS_ENABLE_ALL=YES ;; --use-sys-ssl) SRS_USE_SYS_SSL=YES ;; + --memory-watch) SRS_MEM_WATCH=YES ;; --export-librtmp-project) SRS_EXPORT_LIBRTMP_PROJECT=${value} ;; --export-librtmp-single) SRS_EXPORT_LIBRTMP_SINGLE=${value} ;; diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index c3ac0a5fb..87c36b565 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -569,7 +569,7 @@ void SrsServer::dispose() st_usleep(100 * 1000); } -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH srs_memory_report(); #endif } @@ -893,7 +893,7 @@ void SrsServer::on_signal(int signo) signal_gmc_stop = true; #else srs_trace("user terminate program"); -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH srs_memory_report(); #endif exit(0); diff --git a/trunk/src/core/srs_core_mem_watch.cpp b/trunk/src/core/srs_core_mem_watch.cpp index bbdcbc7bb..4fd521763 100644 --- a/trunk/src/core/srs_core_mem_watch.cpp +++ b/trunk/src/core/srs_core_mem_watch.cpp @@ -23,7 +23,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH #include #include @@ -68,7 +68,7 @@ void srs_memory_unwatch(void* ptr) void srs_memory_report() { - printf("srs memory leak report:\n"); + printf("srs memory watch leak report:\n"); int total = 0; std::map::iterator it; @@ -79,6 +79,7 @@ void srs_memory_report() } printf("%d objects leak %dKB.\n", (int)_srs_ptrs.size(), total / 1024); + printf("@remark use script to cleanup for memory watch: ./etc/init.d/srs stop\n"); } #endif diff --git a/trunk/src/core/srs_core_mem_watch.hpp b/trunk/src/core/srs_core_mem_watch.hpp index bcaf96304..8dc5791e5 100644 --- a/trunk/src/core/srs_core_mem_watch.hpp +++ b/trunk/src/core/srs_core_mem_watch.hpp @@ -30,7 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH #include diff --git a/trunk/src/core/srs_core_performance.hpp b/trunk/src/core/srs_core_performance.hpp index c1b924756..f68efced2 100644 --- a/trunk/src/core/srs_core_performance.hpp +++ b/trunk/src/core/srs_core_performance.hpp @@ -174,7 +174,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * to force the server to send smaller tcp packet. * @see https://github.com/simple-rtmp-server/srs/issues/320 * @remark undef it to auto calc it by merged write sleep ms. -* @remark only apply it when SRS_PERF_MW_SO_RCVBUF is defined. +* @remark only apply it when SRS_PERF_MW_SO_SNDBUF is defined. */ #ifdef SRS_PERF_MW_SO_SNDBUF //#define SRS_PERF_SO_SNDBUF_SIZE 1024 @@ -188,12 +188,5 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #undef SRS_PERF_FAST_FLV_ENCODER #define SRS_PERF_FAST_FLV_ENCODER -/** - * whether enable the special memory watcher. - * which used for memory leak debug and hurts performance. - */ -#define SRS_MEM_WATCH -#undef SRS_MEM_WATCH - #endif diff --git a/trunk/src/kernel/srs_kernel_flv.cpp b/trunk/src/kernel/srs_kernel_flv.cpp index a9ce2d82e..ad446a938 100644 --- a/trunk/src/kernel/srs_kernel_flv.cpp +++ b/trunk/src/kernel/srs_kernel_flv.cpp @@ -160,7 +160,7 @@ SrsCommonMessage::SrsCommonMessage() SrsCommonMessage::~SrsCommonMessage() { -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH srs_memory_unwatch(payload); #endif srs_freep(payload); @@ -173,7 +173,7 @@ void SrsCommonMessage::create_payload(int size) payload = new char[size]; srs_verbose("create payload for RTMP message. size=%d", size); -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH srs_memory_watch(payload, "RTMP.msg.payload", size); #endif } @@ -187,7 +187,7 @@ SrsSharedPtrMessage::SrsSharedPtrPayload::SrsSharedPtrPayload() SrsSharedPtrMessage::SrsSharedPtrPayload::~SrsSharedPtrPayload() { -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH srs_memory_unwatch(payload); #endif srs_freep(payload); diff --git a/trunk/src/main/srs_main_server.cpp b/trunk/src/main/srs_main_server.cpp index b53504b7e..a91f637fb 100644 --- a/trunk/src/main/srs_main_server.cpp +++ b/trunk/src/main/srs_main_server.cpp @@ -212,7 +212,7 @@ void check_macro_features() srs_warn("SRS %s is not stable, please use stable branch %s instead", RTMP_SIG_SRS_VERSION, VERSION_STABLE_BRANCH); #endif -#ifdef SRS_MEM_WATCH +#ifdef SRS_AUTO_MEM_WATCH #warning "srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script." srs_warn("srs memory watcher will hurts performance. user should kill by SIGTERM or init.d script."); #endif