Commit ab0d0f6b authored by Simon Morlat's avatar Simon Morlat

Optimize logs - don't format costly debug logs for nothing.

parent c153c0f5
......@@ -57,6 +57,13 @@
#define LOGV(thelevel, thefmt, theargs) bctbx_logv(FLEXISIP_LOG_DOMAIN, thelevel, (thefmt), (theargs))
#define LOGDV(thefmt, theargs) LOGV(BCTBX_LOG_DEBUG, thefmt, theargs)
/*
* These are test macros, useful to avoid doing anything when the log is not needed and the formating of the log arguments is costly,
* for example when logging a SIP message.
*/
#define LOGD_ENABLED() (bctbx_log_level_enabled(BCTBX_LOG_DOMAIN, BCTBX_LOG_DEBUG))
#define LOGI_ENABLED() (bctbx_log_level_enabled(BCTBX_LOG_DOMAIN, BCTBX_LOG_MESSAGE))
/*
* These are the C++ logging macros, that can be used with << operator.
* Though they are convenient, they are not performant, see comment above.
......
......@@ -990,9 +990,11 @@ void Agent::sendRequestEvent(shared_ptr<RequestSipEvent> ev) {
const sip_request_t *req = sip->sip_request;
const url_t *from_url = sip->sip_from ? sip->sip_from->a_url : NULL;
SLOGD << "Receiving new Request SIP message " << req->rq_method_name << " from "
<< (from_url ? url_as_string(ev->getHome(), from_url) : "<invalid from>") << " :"
<< "\n" << *ev->getMsgSip();
if (LOGD_ENABLED()){
SLOGD << "Receiving new Request SIP message " << req->rq_method_name << " from "
<< (from_url ? url_as_string(ev->getHome(), from_url) : "<invalid from>") << " :"
<< "\n" << *ev->getMsgSip();
}
switch (req->rq_method) {
case sip_method_register:
++*mCountIncomingRegister;
......@@ -1037,8 +1039,11 @@ void Agent::sendResponseEvent(shared_ptr<ResponseSipEvent> ev) {
return;
}
SipLogContext ctx(ev->getMsgSip());
SLOGD << "Receiving new Response SIP message: " << ev->getMsgSip()->getSip()->sip_status->st_status << "\n"
if (LOGD_ENABLED()){
SLOGD << "Receiving new Response SIP message: " << ev->getMsgSip()->getSip()->sip_status->st_status << "\n"
<< *ev->getMsgSip();
}
sip_t *sip = ev->getMsgSip()->getSip();
switch (sip->sip_status->st_status) {
......@@ -1091,9 +1096,10 @@ void Agent::sendResponseEvent(shared_ptr<ResponseSipEvent> ev) {
void Agent::injectRequestEvent(shared_ptr<RequestSipEvent> ev) {
SipLogContext ctx(ev->getMsgSip());
SLOGD << "Inject Request SIP message:\n" << *ev->getMsgSip();
if (LOGD_ENABLED()){
SLOGD << "Inject request SIP event after " << ev->mCurrModule->getModuleName() << ":\n" << *ev->getMsgSip();
}
ev->restartProcessing();
SLOGD << "Injecting request event after " << ev->mCurrModule->getModuleName();
list<Module *>::iterator it;
for (it = mModules.begin(); it != mModules.end(); ++it) {
if (ev->mCurrModule == *it) {
......@@ -1106,10 +1112,12 @@ void Agent::injectRequestEvent(shared_ptr<RequestSipEvent> ev) {
void Agent::injectResponseEvent(shared_ptr<ResponseSipEvent> ev) {
SipLogContext ctx(ev->getMsgSip());
SLOGD << "Inject Response SIP message:\n" << *ev->getMsgSip();
if (LOGD_ENABLED()){
SLOGD << "Injecting response SIP event after " << ev->mCurrModule->getModuleName() << ":\n" << *ev->getMsgSip();
}
list<Module *>::iterator it;
ev->restartProcessing();
SLOGD << "Injecting response event after " << ev->mCurrModule->getModuleName();
for (it = mModules.begin(); it != mModules.end(); ++it) {
if (ev->mCurrModule == *it) {
++it;
......
......@@ -180,8 +180,10 @@ RequestSipEvent::RequestSipEvent(const shared_ptr<RequestSipEvent> &sipEvent)
void RequestSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u, tag_type_t tag, tag_value_t value,
...) {
if (mOutgoingAgent != NULL) {
SLOGD << "Sending Request SIP message to " << (u ? url_as_string(msg->getHome(), (url_t const *)u) : "NULL")
if (LOGD_ENABLED()){
SLOGD << "Sending Request SIP message to " << (u ? url_as_string(msg->getHome(), (url_t const *)u) : "NULL")
<< "\n" << *msg;
}
ta_list ta;
ta_start(ta, tag, value);
mOutgoingAgent->send(msg, u, ta_tags(ta));
......@@ -328,7 +330,9 @@ void ResponseSipEvent::send(const shared_ptr<MsgSip> &msg, url_string_t const *u
}
if (msg->getSip()->sip_via)
checkContentLength(msg, msg->getSip()->sip_via);
SLOGD << "Sending response:" << (via_popped ? " (via popped) " : "") << endl << *msg;
if (LOGD_ENABLED()){
SLOGD << "Sending response:" << (via_popped ? " (via popped) " : "") << endl << *msg;
}
ta_list ta;
ta_start(ta, tag, value);
mIncomingAgent->send(msg, u, ta_tags(ta));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment