logtrace: add log_session_lvl

log_session_lvl is suitable for performance critical places where in
most cases, the log is turned off by level. If the session is const and
the level is greater than session->lvl, the whole function will be
optimized out.
This commit is contained in:
Grissiom 2014-04-10 21:18:38 +08:00
parent 12728bcdff
commit 299cccfb26
2 changed files with 41 additions and 4 deletions

View File

@ -255,8 +255,9 @@ static rt_size_t _lg_parse_session(
return 0;
}
void _lg_fmtout(
const struct log_trace_session *session, const char *fmt, va_list argptr)
void __logtrace_vfmtout(const struct log_trace_session *session,
const char *fmt,
va_list argptr)
{
/* 1 for ']' */
static char _trace_buf[1+LOG_TRACE_BUFSZ];
@ -303,7 +304,7 @@ void log_trace(const char *fmt, ...)
return;
va_start(args, fmt);
_lg_fmtout(session, fmt, args);
__logtrace_vfmtout(session, fmt, args);
va_end(args);
}
FINSH_FUNCTION_EXPORT(log_trace, log trace);
@ -321,7 +322,7 @@ void log_session(const struct log_trace_session *session, const char *fmt, ...)
return;
va_start(args, fmt);
_lg_fmtout(session, fmt, args);
__logtrace_vfmtout(session, fmt, args);
va_end(args);
}

View File

@ -132,6 +132,42 @@ void log_trace(const char *fmt, ...);
*/
void log_session(const struct log_trace_session *session, const char *fmt, ...);
extern void __logtrace_vfmtout(const struct log_trace_session *session,
const char *fmt,
va_list argptr);
rt_inline void __logtrace_fmtout(const struct log_trace_session *session,
const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
__logtrace_vfmtout(session, fmt, args);
va_end(args);
}
/**
* log with numeric level
*
* The prototype of this function is:
*
* void log_session_lvl(struct log_trace_session *session,
* int lvl,
* const char *fmt, ...);
*
* If the @session is const and @level is greater than @session->lvl, the whole
* function will be optimized out. This is suitable for performance critical
* places where in most cases, the log is turned off by level.
*/
#define log_session_lvl(session, level, fmt, ...) \
do { \
if ((level) > (session)->lvl) \
{ \
break; \
} \
__logtrace_fmtout(session, fmt, ##__VA_ARGS__); \
} while (0)
/* here comes the global part. All sessions share the some output backend. */
/** get the backend device */