refine messages

pull/609/merge
winlin 8 years ago
parent dd1c769f65
commit 9e9cad1826

@ -52,6 +52,7 @@ using namespace std;
int run(SrsServer* svr); int run(SrsServer* svr);
int run_master(SrsServer* svr); int run_master(SrsServer* svr);
void show_macro_features(); void show_macro_features();
string srs_getenv(const char* name);
// @global log and context. // @global log and context.
ISrsLog* _srs_log = new SrsFastLog(); ISrsLog* _srs_log = new SrsFastLog();
@ -64,15 +65,15 @@ extern const char* _srs_version;
/** /**
* main entrance. * main entrance.
*/ */
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
// TODO: support both little and big endian. // TODO: support both little and big endian.
srs_assert(srs_is_little_endian()); srs_assert(srs_is_little_endian());
// for gperf gmp or gcp, // for gperf gmp or gcp,
// should never enable it when not enabled for performance issue. // should never enable it when not enabled for performance issue.
#ifdef SRS_AUTO_GPERF_MP #ifdef SRS_AUTO_GPERF_MP
HeapProfilerStart("gperf.srs.gmp"); HeapProfilerStart("gperf.srs.gmp");
@ -80,26 +81,26 @@ int main(int argc, char** argv)
#ifdef SRS_AUTO_GPERF_CP #ifdef SRS_AUTO_GPERF_CP
ProfilerStart("gperf.srs.gcp"); ProfilerStart("gperf.srs.gcp");
#endif #endif
// directly compile error when these two macro defines. // directly compile error when these two macro defines.
#if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP) #if defined(SRS_AUTO_GPERF_MC) && defined(SRS_AUTO_GPERF_MP)
#error ("option --with-gmc confict with --with-gmp, " #error ("option --with-gmc confict with --with-gmp, "
"@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n" "@see: http://google-perftools.googlecode.com/svn/trunk/doc/heap_checker.html\n"
"Note that since the heap-checker uses the heap-profiling framework internally, " "Note that since the heap-checker uses the heap-profiling framework internally, "
"it is not possible to run both the heap-checker and heap profiler at the same time"); "it is not possible to run both the heap-checker and heap profiler at the same time");
#endif #endif
// never use gmp to check memory leak. // never use gmp to check memory leak.
#ifdef SRS_AUTO_GPERF_MP #ifdef SRS_AUTO_GPERF_MP
#warning "gmp is not used for memory leak, please use gmc instead." #warning "gmp is not used for memory leak, please use gmc instead."
#endif #endif
// never use srs log(srs_trace, srs_error, etc) before config parse the option, // never use srs log(srs_trace, srs_error, etc) before config parse the option,
// which will load the log config and apply it. // which will load the log config and apply it.
if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) { if ((ret = _srs_config->parse_options(argc, argv)) != ERROR_SUCCESS) {
return ret; return ret;
} }
// change the work dir and set cwd. // change the work dir and set cwd.
string cwd = _srs_config->get_work_dir(); string cwd = _srs_config->get_work_dir();
if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) { if (!cwd.empty() && cwd != "./" && (ret = chdir(cwd.c_str())) != ERROR_SUCCESS) {
@ -109,7 +110,7 @@ int main(int argc, char** argv)
if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) { if ((ret = _srs_config->initialize_cwd()) != ERROR_SUCCESS) {
return ret; return ret;
} }
// config parsed, initialize log. // config parsed, initialize log.
if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) { if ((ret = _srs_log->initialize()) != ERROR_SUCCESS) {
return ret; return ret;
@ -127,28 +128,50 @@ int main(int argc, char** argv)
#endif #endif
srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str()); srs_trace("cwd=%s, work_dir=%s", _srs_config->cwd().c_str(), cwd.c_str());
// for memory check or detect.
if (true) {
stringstream ss;
#ifdef SRS_PERF_GLIBC_MEMORY_CHECK #ifdef SRS_PERF_GLIBC_MEMORY_CHECK
// ensure glibc write error to stderr. // ensure glibc write error to stderr.
setenv("LIBC_FATAL_STDERR_", "1", 1); string lfsov = srs_getenv("LIBC_FATAL_STDERR_");
// ensure glibc to do alloc check. setenv("LIBC_FATAL_STDERR_", "1", 1);
setenv("MALLOC_CHECK_", "1", 1); string lfsnv = srs_getenv("LIBC_FATAL_STDERR_");
srs_trace("env MALLOC_CHECK_=1 LIBC_FATAL_STDERR_=1"); //
// ensure glibc to do alloc check.
string mcov = srs_getenv("MALLOC_CHECK_");
setenv("MALLOC_CHECK_", "1", 1);
string mcnv = srs_getenv("MALLOC_CHECK_");
ss << "glic mem-check env MALLOC_CHECK_ " << mcov << "=>" << mcnv << ", LIBC_FATAL_STDERR_ " << lfsov << "=>" << lfsnv << ".";
#endif #endif
#ifdef SRS_AUTO_GPERF_MC
string hcov = srs_getenv("HEAPCHECK");
if (hcov.empty()) {
string cpath = _srs_config->config();
srs_warn("gmc HEAPCHECK is required, for example: env HEAPCHECK=normal ./objs/srs -c %s", cpath.c_str());
} else {
ss << "gmc env HEAPCHECK=" << hcov << ".";
}
#endif
#ifdef SRS_AUTO_GPERF_MD #ifdef SRS_AUTO_GPERF_MD
char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE"); char* TCMALLOC_PAGE_FENCE = getenv("TCMALLOC_PAGE_FENCE");
if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) { if (!TCMALLOC_PAGE_FENCE || strcmp(TCMALLOC_PAGE_FENCE, "1")) {
srs_trace("gmd enabled without env TCMALLOC_PAGE_FENCE=1"); srs_warn("gmd enabled without env TCMALLOC_PAGE_FENCE=1");
} else { } else {
srs_trace("env TCMALLOC_PAGE_FENCE=1"); ss << "gmd env TCMALLOC_PAGE_FENCE=" << TCMALLOC_PAGE_FENCE << ".";
} }
#endif #endif
srs_trace(ss.str().c_str());
}
// we check the config when the log initialized. // we check the config when the log initialized.
if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) { if ((ret = _srs_config->check_config()) != ERROR_SUCCESS) {
return ret; return ret;
} }
// features // features
show_macro_features(); show_macro_features();
@ -156,10 +179,10 @@ int main(int argc, char** argv)
SrsAutoFree(SrsServer, svr); SrsAutoFree(SrsServer, svr);
/** /**
* we do nothing in the constructor of server, * we do nothing in the constructor of server,
* and use initialize to create members, set hooks for instance the reload handler, * and use initialize to create members, set hooks for instance the reload handler,
* all initialize will done in this stage. * all initialize will done in this stage.
*/ */
if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) { if ((ret = svr->initialize(NULL)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -330,6 +353,17 @@ void show_macro_features()
#endif #endif
} }
string srs_getenv(const char* name)
{
char* cv = ::getenv(name);
if (cv) {
return cv;
}
return "";
}
int run(SrsServer* svr) int run(SrsServer* svr)
{ {
// if not deamon, directly run master. // if not deamon, directly run master.

Loading…
Cancel
Save