正在显示
1 个修改的文件
包含
66 行增加
和
32 行删除
| @@ -52,6 +52,7 @@ using namespace std; | @@ -52,6 +52,7 @@ using namespace std; | ||
| 52 | int run(SrsServer* svr); | 52 | int run(SrsServer* svr); |
| 53 | int run_master(SrsServer* svr); | 53 | int run_master(SrsServer* svr); |
| 54 | void show_macro_features(); | 54 | void show_macro_features(); |
| 55 | +string srs_getenv(const char* name); | ||
| 55 | 56 | ||
| 56 | // @global log and context. | 57 | // @global log and context. |
| 57 | ISrsLog* _srs_log = new SrsFastLog(); | 58 | ISrsLog* _srs_log = new SrsFastLog(); |
| @@ -64,15 +65,15 @@ extern const char* _srs_version; | @@ -64,15 +65,15 @@ extern const char* _srs_version; | ||
| 64 | 65 | ||
| 65 | /** | 66 | /** |
| 66 | * main entrance. | 67 | * main entrance. |
| 67 | -*/ | ||
| 68 | -int main(int argc, char** argv) | 68 | + */ |
| 69 | +int main(int argc, char** argv) | ||
| 69 | { | 70 | { |
| 70 | int ret = ERROR_SUCCESS; | 71 | int ret = ERROR_SUCCESS; |
| 71 | - | 72 | + |
| 72 | // TODO: support both little and big endian. | 73 | // TODO: support both little and big endian. |
| 73 | srs_assert(srs_is_little_endian()); | 74 | srs_assert(srs_is_little_endian()); |
| 74 | - | ||
| 75 | - // for gperf gmp or gcp, | 75 | + |
| 76 | + // for gperf gmp or gcp, | ||
| 76 | // should never enable it when not enabled for performance issue. | 77 | // should never enable it when not enabled for performance issue. |
| 77 | #ifdef SRS_AUTO_GPERF_MP | 78 | #ifdef SRS_AUTO_GPERF_MP |
| 78 | HeapProfilerStart("gperf.srs.gmp"); | 79 | HeapProfilerStart("gperf.srs.gmp"); |
| @@ -80,26 +81,26 @@ int main(int argc, char** argv) | @@ -80,26 +81,26 @@ int main(int argc, char** argv) | ||
| 80 | #ifdef SRS_AUTO_GPERF_CP | 81 | #ifdef SRS_AUTO_GPERF_CP |
| 81 | ProfilerStart("gperf.srs.gcp"); | 82 | ProfilerStart("gperf.srs.gcp"); |
| 82 | #endif | 83 | #endif |
| 83 | - | 84 | + |
| 84 | // directly compile error when these two macro defines. | 85 | // directly compile error when these two macro defines. |
| 85 | #if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP) | 86 | #if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP) |
| 86 | - #error ("option --with-gmc confict with --with-gmp, " | ||
| 87 | - "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" | ||
| 88 | - "Note that since the heap-checker uses the heap-profiling framework internally, " | ||
| 89 | - "it is not possible to run both the heap-checker and heap profiler at the same time"); | 87 | +#error ("option --with-gmc confict with --with-gmp, " |
| 88 | + "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" | ||
| 89 | + "Note that since the heap-checker uses the heap-profiling framework internally, " | ||
| 90 | + "it is not possible to run both the heap-checker and heap profiler at the same time"); | ||
| 90 | #endif | 91 | #endif |
| 91 | 92 | ||
| 92 | // never use gmp to check memory leak. | 93 | // never use gmp to check memory leak. |
| 93 | #ifdef SRS_AUTO_GPERF_MP | 94 | #ifdef SRS_AUTO_GPERF_MP |
| 94 | - #warning "gmp is not used for memory leak, please use gmc instead." | 95 | +#warning "gmp is not used for memory leak, please use gmc instead." |
| 95 | #endif | 96 | #endif |
| 96 | - | 97 | + |
| 97 | // never use srs log(srs_trace, srs_error, etc) before config parse the option, | 98 | // never use srs log(srs_trace, srs_error, etc) before config parse the option, |
| 98 | // which will load the log config and apply it. | 99 | // which will load the log config and apply it. |
| 99 | if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { | 100 | if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { |
| 100 | return ret; | 101 | return ret; |
| 101 | } | 102 | } |
| 102 | - | 103 | + |
| 103 | // change the work dir and set cwd. | 104 | // change the work dir and set cwd. |
| 104 | string cwd = _srs_config->get_work_dir(); | 105 | string cwd = _srs_config->get_work_dir(); |
| 105 | if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { | 106 | if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { |
| @@ -109,7 +110,7 @@ int main(int argc, char** argv) | @@ -109,7 +110,7 @@ int main(int argc, char** argv) | ||
| 109 | if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) { | 110 | if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) { |
| 110 | return ret; | 111 | return ret; |
| 111 | } | 112 | } |
| 112 | - | 113 | + |
| 113 | // config parsed, initialize log. | 114 | // config parsed, initialize log. |
| 114 | if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { | 115 | if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { |
| 115 | return ret; | 116 | return ret; |
| @@ -127,28 +128,50 @@ int main(int argc, char** argv) | @@ -127,28 +128,50 @@ int main(int argc, char** argv) | ||
| 127 | #endif | 128 | #endif |
| 128 | srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str()); | 129 | srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str()); |
| 129 | 130 | ||
| 131 | + // for memory check or detect. | ||
| 132 | + if (true) { | ||
| 133 | + stringstream ss; | ||
| 134 | + | ||
| 130 | #ifdef SRS_PERF_GLIBC_MEMORY_CHECK | 135 | #ifdef SRS_PERF_GLIBC_MEMORY_CHECK |
| 131 | - // ensure glibc write error to stderr. | ||
| 132 | - setenv("LIBC_FATAL_STDERR_", "1", 1); | ||
| 133 | - // ensure glibc to do alloc check. | ||
| 134 | - setenv("MALLOC_CHECK_", "1", 1); | ||
| 135 | - srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1"); | 136 | + // ensure glibc write error to stderr. |
| 137 | + string lfsov = srs_getenv("LIBC_FATAL_STDERR_"); | ||
| 138 | + setenv("LIBC_FATAL_STDERR_", "1", 1); | ||
| 139 | + string lfsnv = srs_getenv("LIBC_FATAL_STDERR_"); | ||
| 140 | + // | ||
| 141 | + // ensure glibc to do alloc check. | ||
| 142 | + string mcov = srs_getenv("MALLOC_CHECK_"); | ||
| 143 | + setenv("MALLOC_CHECK_", "1", 1); | ||
| 144 | + string mcnv = srs_getenv("MALLOC_CHECK_"); | ||
| 145 | + ss << "glic mem-check env MALLOC_CHECK_ " << mcov << "=>" << mcnv << ", LIBC_FATAL_STDERR_ " << lfsov << "=>" << lfsnv << "."; | ||
| 136 | #endif | 146 | #endif |
| 137 | - | 147 | + |
| 148 | +#ifdef SRS_AUTO_GPERF_MC | ||
| 149 | + string hcov = srs_getenv("HEAPCHECK"); | ||
| 150 | + if (hcov.empty()) { | ||
| 151 | + string cpath = _srs_config->config(); | ||
| 152 | + srs_warn("gmc HEAPCHECK is required, for example: env HEAPCHECK=normal ./objs/srs -c %s", cpath.c_str()); | ||
| 153 | + } else { | ||
| 154 | + ss << "gmc env HEAPCHECK=" << hcov << "."; | ||
| 155 | + } | ||
| 156 | +#endif | ||
| 157 | + | ||
| 138 | #ifdef SRS_AUTO_GPERF_MD | 158 | #ifdef SRS_AUTO_GPERF_MD |
| 139 | - char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); | ||
| 140 | - if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { | ||
| 141 | - srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); | ||
| 142 | - } else { | ||
| 143 | - srs_trace("env TCMALLOC_PAGE_FENCE=1"); | ||
| 144 | - } | 159 | + char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); |
| 160 | + if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { | ||
| 161 | + srs_warn("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); | ||
| 162 | + } else { | ||
| 163 | + ss << "gmd env TCMALLOC_PAGE_FENCE=" << TCMALLOC_PAGE_FENCE << "."; | ||
| 164 | + } | ||
| 145 | #endif | 165 | #endif |
| 146 | - | 166 | + |
| 167 | + srs_trace(ss.str().c_str()); | ||
| 168 | + } | ||
| 169 | + | ||
| 147 | // we check the config when the log initialized. | 170 | // we check the config when the log initialized. |
| 148 | if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { | 171 | if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { |
| 149 | return ret; | 172 | return ret; |
| 150 | } | 173 | } |
| 151 | - | 174 | + |
| 152 | // features | 175 | // features |
| 153 | show_macro_features(); | 176 | show_macro_features(); |
| 154 | 177 | ||
| @@ -156,10 +179,10 @@ int main(int argc, char** argv) | @@ -156,10 +179,10 @@ int main(int argc, char** argv) | ||
| 156 | SrsAutoFree(SrsServer, svr); | 179 | SrsAutoFree(SrsServer, svr); |
| 157 | 180 | ||
| 158 | /** | 181 | /** |
| 159 | - * we do nothing in the constructor of server, | ||
| 160 | - * and use initialize to create members, set hooks for instance the reload handler, | ||
| 161 | - * all initialize will done in this stage. | ||
| 162 | - */ | 182 | + * we do nothing in the constructor of server, |
| 183 | + * and use initialize to create members, set hooks for instance the reload handler, | ||
| 184 | + * all initialize will done in this stage. | ||
| 185 | + */ | ||
| 163 | if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { | 186 | if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { |
| 164 | return ret; | 187 | return ret; |
| 165 | } | 188 | } |
| @@ -330,6 +353,17 @@ void show_macro_features() | @@ -330,6 +353,17 @@ void show_macro_features() | ||
| 330 | #endif | 353 | #endif |
| 331 | } | 354 | } |
| 332 | 355 | ||
| 356 | +string srs_getenv(const char* name) | ||
| 357 | +{ | ||
| 358 | + char* cv = ::getenv(name); | ||
| 359 | + | ||
| 360 | + if (cv) { | ||
| 361 | + return cv; | ||
| 362 | + } | ||
| 363 | + | ||
| 364 | + return ""; | ||
| 365 | +} | ||
| 366 | + | ||
| 333 | int run(SrsServer* svr) | 367 | int run(SrsServer* svr) |
| 334 | { | 368 | { |
| 335 | // if not deamon, directly run master. | 369 | // if not deamon, directly run master. |
-
请 注册 或 登录 后发表评论