winlin

refine messages

@@ -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,7 +65,7 @@ extern const char* _srs_version; @@ -64,7 +65,7 @@ extern const char* _srs_version;
64 65
65 /** 66 /**
66 * main entrance. 67 * main entrance.
67 -*/ 68 + */
68 int main(int argc, char** argv) 69 int main(int argc, char** argv)
69 { 70 {
70 int ret = ERROR_SUCCESS; 71 int ret = ERROR_SUCCESS;
@@ -83,7 +84,7 @@ int main(int argc, char** argv) @@ -83,7 +84,7 @@ int main(int argc, char** argv)
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 +#error ("option --with-gmc confict with --with-gmp, "
87 "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" 88 "@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 "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"); 90 "it is not possible to run both the heap-checker and heap profiler at the same time");
@@ -91,7 +92,7 @@ int main(int argc, char** argv) @@ -91,7 +92,7 @@ int main(int argc, char** argv)
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,
@@ -127,23 +128,45 @@ int main(int argc, char** argv) @@ -127,23 +128,45 @@ 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. 136 // ensure glibc write error to stderr.
  137 + string lfsov = srs_getenv("LIBC_FATAL_STDERR_");
132 setenv("LIBC_FATAL_STDERR_", "1", 1); 138 setenv("LIBC_FATAL_STDERR_", "1", 1);
  139 + string lfsnv = srs_getenv("LIBC_FATAL_STDERR_");
  140 + //
133 // ensure glibc to do alloc check. 141 // ensure glibc to do alloc check.
  142 + string mcov = srs_getenv("MALLOC_CHECK_");
134 setenv("MALLOC_CHECK_", "1", 1); 143 setenv("MALLOC_CHECK_", "1", 1);
135 - srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1"); 144 + string mcnv = srs_getenv("MALLOC_CHECK_");
  145 + ss << "glic mem-check env MALLOC_CHECK_ " << mcov << "=>" << mcnv << ", LIBC_FATAL_STDERR_ " << lfsov << "=>" << lfsnv << ".";
  146 +#endif
  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 + }
136 #endif 156 #endif
137 157
138 #ifdef SRS_AUTO_GPERF_MD 158 #ifdef SRS_AUTO_GPERF_MD
139 char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); 159 char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE");
140 if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { 160 if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) {
141 - srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); 161 + srs_warn("gmd enabled without env TCMALLOC_PAGE_FENCE=1");
142 } else { 162 } else {
143 - srs_trace("env TCMALLOC_PAGE_FENCE=1"); 163 + ss << "gmd env TCMALLOC_PAGE_FENCE=" << TCMALLOC_PAGE_FENCE << ".";
144 } 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;
@@ -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.