正在显示
11 个修改的文件
包含
178 行增加
和
3 行删除
@@ -138,7 +138,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | @@ -138,7 +138,7 @@ if [ $SRS_MIPS_UBUNTU12 = YES ]; then SrsLinkOptions="${SrsLinkOptions} -lgcc_eh | ||
138 | MODULE_ID="CORE" | 138 | MODULE_ID="CORE" |
139 | MODULE_DEPENDS=() | 139 | MODULE_DEPENDS=() |
140 | ModuleLibIncs=(${SRS_OBJS_DIR}) | 140 | ModuleLibIncs=(${SRS_OBJS_DIR}) |
141 | -MODULE_FILES=("srs_core" "srs_core_autofree" "srs_core_performance") | 141 | +MODULE_FILES=("srs_core" "srs_core_autofree" "srs_core_performance" "srs_core_mem_watch") |
142 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh | 142 | CORE_INCS="src/core"; MODULE_DIR=${CORE_INCS} . auto/modules.sh |
143 | CORE_OBJS="${MODULE_OBJS[@]}" | 143 | CORE_OBJS="${MODULE_OBJS[@]}" |
144 | # | 144 | # |
@@ -16,6 +16,8 @@ file | @@ -16,6 +16,8 @@ file | ||
16 | ../../src/core/srs_core.cpp, | 16 | ../../src/core/srs_core.cpp, |
17 | ../../src/core/srs_core_autofree.hpp, | 17 | ../../src/core/srs_core_autofree.hpp, |
18 | ../../src/core/srs_core_autofree.cpp, | 18 | ../../src/core/srs_core_autofree.cpp, |
19 | + ../../src/core/srs_core_mem_watch.hpp, | ||
20 | + ../../src/core/srs_core_mem_watch.cpp, | ||
19 | ../../src/core/srs_core_performance.hpp, | 21 | ../../src/core/srs_core_performance.hpp, |
20 | ../../src/core/srs_core_performance.cpp, | 22 | ../../src/core/srs_core_performance.cpp, |
21 | kernel readonly separator, | 23 | kernel readonly separator, |
@@ -100,6 +100,7 @@ | @@ -100,6 +100,7 @@ | ||
100 | <ClInclude Include="..\..\src\app\srs_app_utility.hpp" /> | 100 | <ClInclude Include="..\..\src\app\srs_app_utility.hpp" /> |
101 | <ClInclude Include="..\..\src\core\srs_core.hpp" /> | 101 | <ClInclude Include="..\..\src\core\srs_core.hpp" /> |
102 | <ClInclude Include="..\..\src\core\srs_core_autofree.hpp" /> | 102 | <ClInclude Include="..\..\src\core\srs_core_autofree.hpp" /> |
103 | + <ClInclude Include="..\..\src\core\srs_core_mem_watch.hpp" /> | ||
103 | <ClInclude Include="..\..\src\core\srs_core_performance.hpp" /> | 104 | <ClInclude Include="..\..\src\core\srs_core_performance.hpp" /> |
104 | <ClInclude Include="..\..\src\kernel\srs_kernel_aac.hpp" /> | 105 | <ClInclude Include="..\..\src\kernel\srs_kernel_aac.hpp" /> |
105 | <ClInclude Include="..\..\src\kernel\srs_kernel_avc.hpp" /> | 106 | <ClInclude Include="..\..\src\kernel\srs_kernel_avc.hpp" /> |
@@ -181,6 +182,7 @@ | @@ -181,6 +182,7 @@ | ||
181 | <ClCompile Include="..\..\src\app\srs_app_utility.cpp" /> | 182 | <ClCompile Include="..\..\src\app\srs_app_utility.cpp" /> |
182 | <ClCompile Include="..\..\src\core\srs_core.cpp" /> | 183 | <ClCompile Include="..\..\src\core\srs_core.cpp" /> |
183 | <ClCompile Include="..\..\src\core\srs_core_autofree.cpp" /> | 184 | <ClCompile Include="..\..\src\core\srs_core_autofree.cpp" /> |
185 | + <ClCompile Include="..\..\src\core\srs_core_mem_watch.cpp" /> | ||
184 | <ClCompile Include="..\..\src\core\srs_core_performance.cpp" /> | 186 | <ClCompile Include="..\..\src\core\srs_core_performance.cpp" /> |
185 | <ClCompile Include="..\..\src\kernel\srs_kernel_aac.cpp" /> | 187 | <ClCompile Include="..\..\src\kernel\srs_kernel_aac.cpp" /> |
186 | <ClCompile Include="..\..\src\kernel\srs_kernel_avc.cpp" /> | 188 | <ClCompile Include="..\..\src\kernel\srs_kernel_avc.cpp" /> |
@@ -79,6 +79,7 @@ | @@ -79,6 +79,7 @@ | ||
79 | 3C36DB5B1ABD1CB90066CCAF /* srs_lib_bandwidth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB551ABD1CB90066CCAF /* srs_lib_bandwidth.cpp */; }; | 79 | 3C36DB5B1ABD1CB90066CCAF /* srs_lib_bandwidth.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB551ABD1CB90066CCAF /* srs_lib_bandwidth.cpp */; }; |
80 | 3C36DB5C1ABD1CB90066CCAF /* srs_lib_simple_socket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB571ABD1CB90066CCAF /* srs_lib_simple_socket.cpp */; }; | 80 | 3C36DB5C1ABD1CB90066CCAF /* srs_lib_simple_socket.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB571ABD1CB90066CCAF /* srs_lib_simple_socket.cpp */; }; |
81 | 3C36DB5D1ABD1CB90066CCAF /* srs_librtmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB591ABD1CB90066CCAF /* srs_librtmp.cpp */; }; | 81 | 3C36DB5D1ABD1CB90066CCAF /* srs_librtmp.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C36DB591ABD1CB90066CCAF /* srs_librtmp.cpp */; }; |
82 | + 3C5265B41B241BF0009CA186 /* srs_core_mem_watch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5265B21B241BF0009CA186 /* srs_core_mem_watch.cpp */; }; | ||
82 | 3C663F0F1AB0155100286D8B /* srs_aac_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */; }; | 83 | 3C663F0F1AB0155100286D8B /* srs_aac_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */; }; |
83 | 3C663F101AB0155100286D8B /* srs_audio_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */; }; | 84 | 3C663F101AB0155100286D8B /* srs_audio_raw_publish.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */; }; |
84 | 3C663F111AB0155100286D8B /* srs_bandwidth_check.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F041AB0155100286D8B /* srs_bandwidth_check.c */; }; | 85 | 3C663F111AB0155100286D8B /* srs_bandwidth_check.c in Sources */ = {isa = PBXBuildFile; fileRef = 3C663F041AB0155100286D8B /* srs_bandwidth_check.c */; }; |
@@ -327,6 +328,8 @@ | @@ -327,6 +328,8 @@ | ||
327 | 3C36DB581ABD1CB90066CCAF /* srs_lib_simple_socket.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_lib_simple_socket.hpp; path = ../../../src/libs/srs_lib_simple_socket.hpp; sourceTree = "<group>"; }; | 328 | 3C36DB581ABD1CB90066CCAF /* srs_lib_simple_socket.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_lib_simple_socket.hpp; path = ../../../src/libs/srs_lib_simple_socket.hpp; sourceTree = "<group>"; }; |
328 | 3C36DB591ABD1CB90066CCAF /* srs_librtmp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_librtmp.cpp; path = ../../../src/libs/srs_librtmp.cpp; sourceTree = "<group>"; }; | 329 | 3C36DB591ABD1CB90066CCAF /* srs_librtmp.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_librtmp.cpp; path = ../../../src/libs/srs_librtmp.cpp; sourceTree = "<group>"; }; |
329 | 3C36DB5A1ABD1CB90066CCAF /* srs_librtmp.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_librtmp.hpp; path = ../../../src/libs/srs_librtmp.hpp; sourceTree = "<group>"; }; | 330 | 3C36DB5A1ABD1CB90066CCAF /* srs_librtmp.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_librtmp.hpp; path = ../../../src/libs/srs_librtmp.hpp; sourceTree = "<group>"; }; |
331 | + 3C5265B21B241BF0009CA186 /* srs_core_mem_watch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = srs_core_mem_watch.cpp; path = ../../../src/core/srs_core_mem_watch.cpp; sourceTree = "<group>"; }; | ||
332 | + 3C5265B31B241BF0009CA186 /* srs_core_mem_watch.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = srs_core_mem_watch.hpp; path = ../../../src/core/srs_core_mem_watch.hpp; sourceTree = "<group>"; }; | ||
330 | 3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_aac_raw_publish.c; path = ../../../research/librtmp/srs_aac_raw_publish.c; sourceTree = "<group>"; }; | 333 | 3C663F021AB0155100286D8B /* srs_aac_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_aac_raw_publish.c; path = ../../../research/librtmp/srs_aac_raw_publish.c; sourceTree = "<group>"; }; |
331 | 3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_audio_raw_publish.c; path = ../../../research/librtmp/srs_audio_raw_publish.c; sourceTree = "<group>"; }; | 334 | 3C663F031AB0155100286D8B /* srs_audio_raw_publish.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_audio_raw_publish.c; path = ../../../research/librtmp/srs_audio_raw_publish.c; sourceTree = "<group>"; }; |
332 | 3C663F041AB0155100286D8B /* srs_bandwidth_check.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_bandwidth_check.c; path = ../../../research/librtmp/srs_bandwidth_check.c; sourceTree = "<group>"; }; | 335 | 3C663F041AB0155100286D8B /* srs_bandwidth_check.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = srs_bandwidth_check.c; path = ../../../research/librtmp/srs_bandwidth_check.c; sourceTree = "<group>"; }; |
@@ -428,6 +431,8 @@ | @@ -428,6 +431,8 @@ | ||
428 | children = ( | 431 | children = ( |
429 | 3C1231F01AAE652C00CE8F6C /* srs_core_autofree.cpp */, | 432 | 3C1231F01AAE652C00CE8F6C /* srs_core_autofree.cpp */, |
430 | 3C1231F11AAE652C00CE8F6C /* srs_core_autofree.hpp */, | 433 | 3C1231F11AAE652C00CE8F6C /* srs_core_autofree.hpp */, |
434 | + 3C5265B21B241BF0009CA186 /* srs_core_mem_watch.cpp */, | ||
435 | + 3C5265B31B241BF0009CA186 /* srs_core_mem_watch.hpp */, | ||
431 | 3C1231F21AAE652C00CE8F6C /* srs_core_performance.cpp */, | 436 | 3C1231F21AAE652C00CE8F6C /* srs_core_performance.cpp */, |
432 | 3C1231F31AAE652C00CE8F6C /* srs_core_performance.hpp */, | 437 | 3C1231F31AAE652C00CE8F6C /* srs_core_performance.hpp */, |
433 | 3C1231F41AAE652D00CE8F6C /* srs_core.cpp */, | 438 | 3C1231F41AAE652D00CE8F6C /* srs_core.cpp */, |
@@ -882,6 +887,7 @@ | @@ -882,6 +887,7 @@ | ||
882 | 3CC52DDC1ACE4023006FEB01 /* srs_utest_protocol.cpp in Sources */, | 887 | 3CC52DDC1ACE4023006FEB01 /* srs_utest_protocol.cpp in Sources */, |
883 | 3C663F151AB0155100286D8B /* srs_h264_raw_publish.c in Sources */, | 888 | 3C663F151AB0155100286D8B /* srs_h264_raw_publish.c in Sources */, |
884 | 3C1231F61AAE652D00CE8F6C /* srs_core_autofree.cpp in Sources */, | 889 | 3C1231F61AAE652D00CE8F6C /* srs_core_autofree.cpp in Sources */, |
890 | + 3C5265B41B241BF0009CA186 /* srs_core_mem_watch.cpp in Sources */, | ||
885 | 3C1EE6D71AB1367D00576EE9 /* README.md in Sources */, | 891 | 3C1EE6D71AB1367D00576EE9 /* README.md in Sources */, |
886 | 3C1232411AAE81A400CE8F6C /* srs_raw_avc.cpp in Sources */, | 892 | 3C1232411AAE81A400CE8F6C /* srs_raw_avc.cpp in Sources */, |
887 | 3C1232491AAE81A400CE8F6C /* srs_rtmp_utility.cpp in Sources */, | 893 | 3C1232491AAE81A400CE8F6C /* srs_rtmp_utility.cpp in Sources */, |
@@ -47,6 +47,7 @@ using namespace std; | @@ -47,6 +47,7 @@ using namespace std; | ||
47 | #include <srs_app_rtsp.hpp> | 47 | #include <srs_app_rtsp.hpp> |
48 | #include <srs_app_statistic.hpp> | 48 | #include <srs_app_statistic.hpp> |
49 | #include <srs_app_caster_flv.hpp> | 49 | #include <srs_app_caster_flv.hpp> |
50 | +#include <srs_core_mem_watch.hpp> | ||
50 | 51 | ||
51 | // signal defines. | 52 | // signal defines. |
52 | #define SIGNAL_RELOAD SIGHUP | 53 | #define SIGNAL_RELOAD SIGHUP |
@@ -556,6 +557,10 @@ void SrsServer::destroy() | @@ -556,6 +557,10 @@ void SrsServer::destroy() | ||
556 | // @remark never destroy the source, | 557 | // @remark never destroy the source, |
557 | // when we free all sources, the fmle publish may retry | 558 | // when we free all sources, the fmle publish may retry |
558 | // and segment fault. | 559 | // and segment fault. |
560 | + | ||
561 | +#ifdef SRS_MEM_WATCH | ||
562 | + srs_memory_report(); | ||
563 | +#endif | ||
559 | } | 564 | } |
560 | 565 | ||
561 | void SrsServer::dispose() | 566 | void SrsServer::dispose() |
@@ -571,6 +576,10 @@ void SrsServer::dispose() | @@ -571,6 +576,10 @@ void SrsServer::dispose() | ||
571 | srs_trace("gracefully dispose sources"); | 576 | srs_trace("gracefully dispose sources"); |
572 | 577 | ||
573 | srs_trace("terminate server"); | 578 | srs_trace("terminate server"); |
579 | + | ||
580 | +#ifdef SRS_MEM_WATCH | ||
581 | + srs_memory_report(); | ||
582 | +#endif | ||
574 | } | 583 | } |
575 | 584 | ||
576 | int SrsServer::initialize(ISrsServerCycle* cycle_handler) | 585 | int SrsServer::initialize(ISrsServerCycle* cycle_handler) |
@@ -891,6 +900,9 @@ void SrsServer::on_signal(int signo) | @@ -891,6 +900,9 @@ void SrsServer::on_signal(int signo) | ||
891 | signal_gmc_stop = true; | 900 | signal_gmc_stop = true; |
892 | #else | 901 | #else |
893 | srs_trace("user terminate program"); | 902 | srs_trace("user terminate program"); |
903 | +#ifdef SRS_MEM_WATCH | ||
904 | + srs_memory_report(); | ||
905 | +#endif | ||
894 | exit(0); | 906 | exit(0); |
895 | #endif | 907 | #endif |
896 | return; | 908 | return; |
trunk/src/core/srs_core_mem_watch.cpp
0 → 100644
1 | +/* | ||
2 | +The MIT License (MIT) | ||
3 | + | ||
4 | +Copyright (c) 2013-2015 SRS(simple-rtmp-server) | ||
5 | + | ||
6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
7 | +this software and associated documentation files (the "Software"), to deal in | ||
8 | +the Software without restriction, including without limitation the rights to | ||
9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
11 | +subject to the following conditions: | ||
12 | + | ||
13 | +The above copyright notice and this permission notice shall be included in all | ||
14 | +copies or substantial portions of the Software. | ||
15 | + | ||
16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
22 | +*/ | ||
23 | + | ||
24 | +#include <srs_core_mem_watch.hpp> | ||
25 | + | ||
26 | +#ifdef SRS_MEM_WATCH | ||
27 | + | ||
28 | +#include <map> | ||
29 | +#include <stdio.h> | ||
30 | +using namespace std; | ||
31 | + | ||
32 | +struct SrsMemoryObject | ||
33 | +{ | ||
34 | + void* ptr; | ||
35 | + std::string category; | ||
36 | + int size; | ||
37 | +}; | ||
38 | + | ||
39 | +std::map<void*, SrsMemoryObject*> _srs_ptrs; | ||
40 | + | ||
41 | +void srs_memory_watch(void* ptr, string category, int size) | ||
42 | +{ | ||
43 | + SrsMemoryObject* obj = NULL; | ||
44 | + | ||
45 | + std::map<void*, SrsMemoryObject*>::iterator it; | ||
46 | + if ((it = _srs_ptrs.find(ptr)) != _srs_ptrs.end()) { | ||
47 | + obj = it->second; | ||
48 | + } else { | ||
49 | + obj = new SrsMemoryObject(); | ||
50 | + _srs_ptrs[ptr] = obj; | ||
51 | + } | ||
52 | + | ||
53 | + obj->ptr = ptr; | ||
54 | + obj->category = category; | ||
55 | + obj->size = size; | ||
56 | +} | ||
57 | + | ||
58 | +void srs_memory_unwatch(void* ptr) | ||
59 | +{ | ||
60 | + std::map<void*, SrsMemoryObject*>::iterator it; | ||
61 | + if ((it = _srs_ptrs.find(ptr)) != _srs_ptrs.end()) { | ||
62 | + SrsMemoryObject* obj = it->second; | ||
63 | + srs_freep(obj); | ||
64 | + | ||
65 | + _srs_ptrs.erase(it); | ||
66 | + } | ||
67 | +} | ||
68 | + | ||
69 | +void srs_memory_report() | ||
70 | +{ | ||
71 | + printf("srs memory leak report:\n"); | ||
72 | + | ||
73 | + int total = 0; | ||
74 | + std::map<void*, SrsMemoryObject*>::iterator it; | ||
75 | + for (it = _srs_ptrs.begin(); it != _srs_ptrs.end(); ++it) { | ||
76 | + SrsMemoryObject* obj = it->second; | ||
77 | + printf(" %s: %#"PRIx64", %dKB\n", obj->category.c_str(), (int64_t)obj->ptr, obj->size / 1000); | ||
78 | + total += obj->size; | ||
79 | + } | ||
80 | + | ||
81 | + printf("%d objects leak %dKB.\n", (int)_srs_ptrs.size(), total / 1024); | ||
82 | +} | ||
83 | + | ||
84 | +#endif | ||
85 | + |
trunk/src/core/srs_core_mem_watch.hpp
0 → 100644
1 | +/* | ||
2 | +The MIT License (MIT) | ||
3 | + | ||
4 | +Copyright (c) 2013-2015 SRS(simple-rtmp-server) | ||
5 | + | ||
6 | +Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
7 | +this software and associated documentation files (the "Software"), to deal in | ||
8 | +the Software without restriction, including without limitation the rights to | ||
9 | +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
10 | +the Software, and to permit persons to whom the Software is furnished to do so, | ||
11 | +subject to the following conditions: | ||
12 | + | ||
13 | +The above copyright notice and this permission notice shall be included in all | ||
14 | +copies or substantial portions of the Software. | ||
15 | + | ||
16 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
18 | +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
19 | +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
20 | +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
21 | +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
22 | +*/ | ||
23 | + | ||
24 | +#ifndef SRS_CORE_MEM_WATCH_HPP | ||
25 | +#define SRS_CORE_MEM_WATCH_HPP | ||
26 | + | ||
27 | +/* | ||
28 | +#include <srs_core_mem_watch.hpp> | ||
29 | +*/ | ||
30 | + | ||
31 | +#include <srs_core.hpp> | ||
32 | + | ||
33 | +#ifdef SRS_MEM_WATCH | ||
34 | + | ||
35 | +#include <string> | ||
36 | + | ||
37 | +// watch the specified memory. | ||
38 | +extern void srs_memory_watch(void* ptr, std::string category, int size); | ||
39 | + | ||
40 | +// unwatch the specified memory. | ||
41 | +extern void srs_memory_unwatch(void* ptr); | ||
42 | + | ||
43 | +// report the memory watch. | ||
44 | +extern void srs_memory_report(); | ||
45 | + | ||
46 | +#endif | ||
47 | + | ||
48 | +#endif | ||
49 | + |
@@ -188,5 +188,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -188,5 +188,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
188 | #undef SRS_PERF_FAST_FLV_ENCODER | 188 | #undef SRS_PERF_FAST_FLV_ENCODER |
189 | #define SRS_PERF_FAST_FLV_ENCODER | 189 | #define SRS_PERF_FAST_FLV_ENCODER |
190 | 190 | ||
191 | +/** | ||
192 | + * whether enable the special memory watcher. | ||
193 | + * which used for memory leak debug and hurts performance. | ||
194 | + */ | ||
195 | +#undef SRS_MEM_WATCH | ||
196 | +#define SRS_MEM_WATCH | ||
197 | + | ||
191 | #endif | 198 | #endif |
192 | 199 |
@@ -38,6 +38,7 @@ using namespace std; | @@ -38,6 +38,7 @@ using namespace std; | ||
38 | #include <srs_kernel_file.hpp> | 38 | #include <srs_kernel_file.hpp> |
39 | #include <srs_kernel_codec.hpp> | 39 | #include <srs_kernel_codec.hpp> |
40 | #include <srs_kernel_utility.hpp> | 40 | #include <srs_kernel_utility.hpp> |
41 | +#include <srs_core_mem_watch.hpp> | ||
41 | 42 | ||
42 | SrsMessageHeader::SrsMessageHeader() | 43 | SrsMessageHeader::SrsMessageHeader() |
43 | { | 44 | { |
@@ -159,6 +160,9 @@ SrsCommonMessage::SrsCommonMessage() | @@ -159,6 +160,9 @@ SrsCommonMessage::SrsCommonMessage() | ||
159 | 160 | ||
160 | SrsCommonMessage::~SrsCommonMessage() | 161 | SrsCommonMessage::~SrsCommonMessage() |
161 | { | 162 | { |
163 | +#ifdef SRS_MEM_WATCH | ||
164 | + srs_memory_unwatch(payload); | ||
165 | +#endif | ||
162 | srs_freep(payload); | 166 | srs_freep(payload); |
163 | } | 167 | } |
164 | 168 | ||
@@ -171,6 +175,9 @@ SrsSharedPtrMessage::SrsSharedPtrPayload::SrsSharedPtrPayload() | @@ -171,6 +175,9 @@ SrsSharedPtrMessage::SrsSharedPtrPayload::SrsSharedPtrPayload() | ||
171 | 175 | ||
172 | SrsSharedPtrMessage::SrsSharedPtrPayload::~SrsSharedPtrPayload() | 176 | SrsSharedPtrMessage::SrsSharedPtrPayload::~SrsSharedPtrPayload() |
173 | { | 177 | { |
178 | +#ifdef SRS_MEM_WATCH | ||
179 | + srs_memory_unwatch(payload); | ||
180 | +#endif | ||
174 | srs_freep(payload); | 181 | srs_freep(payload); |
175 | } | 182 | } |
176 | 183 |
@@ -72,7 +72,7 @@ SrsFastBuffer::~SrsFastBuffer() | @@ -72,7 +72,7 @@ SrsFastBuffer::~SrsFastBuffer() | ||
72 | 72 | ||
73 | int SrsFastBuffer::size() | 73 | int SrsFastBuffer::size() |
74 | { | 74 | { |
75 | - return end - p; | 75 | + return (int)(end - p); |
76 | } | 76 | } |
77 | 77 | ||
78 | char* SrsFastBuffer::bytes() | 78 | char* SrsFastBuffer::bytes() |
@@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
30 | #include <srs_kernel_utility.hpp> | 30 | #include <srs_kernel_utility.hpp> |
31 | #include <srs_protocol_buffer.hpp> | 31 | #include <srs_protocol_buffer.hpp> |
32 | #include <srs_rtmp_utility.hpp> | 32 | #include <srs_rtmp_utility.hpp> |
33 | +#include <srs_core_mem_watch.hpp> | ||
33 | 34 | ||
34 | // for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213 | 35 | // for srs-librtmp, @see https://github.com/simple-rtmp-server/srs/issues/213 |
35 | #ifndef _WIN32 | 36 | #ifndef _WIN32 |
@@ -364,6 +365,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | @@ -364,6 +365,7 @@ int SrsProtocol::recv_message(SrsCommonMessage** pmsg) | ||
364 | srs_verbose("entire msg received"); | 365 | srs_verbose("entire msg received"); |
365 | 366 | ||
366 | if (!msg) { | 367 | if (!msg) { |
368 | + srs_info("got empty message without error."); | ||
367 | continue; | 369 | continue; |
368 | } | 370 | } |
369 | 371 | ||
@@ -467,7 +469,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | @@ -467,7 +469,7 @@ int SrsProtocol::do_send_messages(SrsSharedPtrMessage** msgs, int nb_msgs) | ||
467 | iovs[0].iov_len = nbh; | 469 | iovs[0].iov_len = nbh; |
468 | 470 | ||
469 | // payload iov | 471 | // payload iov |
470 | - int payload_size = srs_min(out_chunk_size, pend - p); | 472 | + int payload_size = srs_min(out_chunk_size, (int)(pend - p)); |
471 | iovs[1].iov_base = p; | 473 | iovs[1].iov_base = p; |
472 | iovs[1].iov_len = payload_size; | 474 | iovs[1].iov_len = payload_size; |
473 | 475 | ||
@@ -1411,6 +1413,9 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, SrsCommonMessage** | @@ -1411,6 +1413,9 @@ int SrsProtocol::read_message_payload(SrsChunkStream* chunk, SrsCommonMessage** | ||
1411 | if (!chunk->msg->payload) { | 1413 | if (!chunk->msg->payload) { |
1412 | chunk->msg->payload = new char[chunk->header.payload_length]; | 1414 | chunk->msg->payload = new char[chunk->header.payload_length]; |
1413 | srs_verbose("create payload for RTMP message. size=%d", chunk->header.payload_length); | 1415 | srs_verbose("create payload for RTMP message. size=%d", chunk->header.payload_length); |
1416 | +#ifdef SRS_MEM_WATCH | ||
1417 | + srs_memory_watch(chunk->msg->payload, "msg.payload", chunk->header.payload_length); | ||
1418 | +#endif | ||
1414 | } | 1419 | } |
1415 | 1420 | ||
1416 | // read payload to buffer | 1421 | // read payload to buffer |
-
请 注册 或 登录 后发表评论