Skip to content

CDRIVER-4697: More efficient trace toggle #1634

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libmongoc/src/mongoc/mongoc-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
static bson_once_t once = BSON_ONCE_INIT;
static bson_mutex_t gLogMutex;
static mongoc_log_func_t gLogFunc = mongoc_log_default_handler;
static bool gLogTrace = MONGOC_TRACE_ENABLED;
bool gLogTrace = MONGOC_TRACE_ENABLED;
static void *gLogData;

static BSON_ONCE_FUN (_mongoc_ensure_mutex_once)
Expand Down
19 changes: 11 additions & 8 deletions src/libmongoc/src/mongoc/mongoc-trace-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,43 +31,46 @@

BSON_BEGIN_DECLS

// `gLogTrace` determines if tracing is enabled at runtime.
extern bool gLogTrace;

#define TRACE(msg, ...) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log ( \
MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, "TRACE: %s():%d " msg, BSON_FUNC, __LINE__, __VA_ARGS__); \
} \
} while (0)
#define ENTRY \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, "ENTRY: %s():%d", BSON_FUNC, __LINE__); \
} \
} while (0)
#define EXIT \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, " EXIT: %s():%d", BSON_FUNC, __LINE__); \
} \
return; \
} while (0)
#define RETURN(ret) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, " EXIT: %s():%d", BSON_FUNC, __LINE__); \
} \
return ret; \
} while (0)
#define GOTO(label) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, MONGOC_LOG_DOMAIN, " GOTO: %s():%d %s", BSON_FUNC, __LINE__, #label); \
} \
goto label; \
} while (0)
#define DUMP_BYTES(_n, _b, _l) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, \
MONGOC_LOG_DOMAIN, \
"TRACE: %s():%d %s = %p [%d]", \
Expand All @@ -81,7 +84,7 @@ BSON_BEGIN_DECLS
} while (0)
#define DUMP_BSON(_bson) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
char *_bson_str; \
if (_bson) { \
_bson_str = bson_as_canonical_extended_json (_bson, NULL); \
Expand All @@ -100,7 +103,7 @@ BSON_BEGIN_DECLS
} while (0)
#define DUMP_IOVEC(_n, _iov, _iovcnt) \
do { \
if (MONGOC_TRACE_ENABLED) { \
if (MONGOC_TRACE_ENABLED && gLogTrace) { \
mongoc_log (MONGOC_LOG_LEVEL_TRACE, \
MONGOC_LOG_DOMAIN, \
"TRACE: %s():%d %s = %p [%d]", \
Expand Down