Commit c5a90fd1 authored by Vladimír Čunát's avatar Vladimír Čunát

QRVERBOSE: move more code into a function, add docs

There's only very little that makes sense to "inline".
My understanding that it makes sense to have such heavier
optimization only for the case when no verbose logging is done.
This might actually help due to decreasing code size.
parent 934b5f59
......@@ -19,25 +19,22 @@
#include "lib/defines.h"
#include "lib/utils.h"
#ifndef NOVERBOSELOG
/** @internal Print a debug message related to resolution. */
#define QRVERBOSE(query, cls, ...) { \
const struct kr_query *q = (query); \
if (kr_log_trace_enabled(q)) { \
kr_log_trace(q, cls, __VA_ARGS__); \
#ifdef NOVERBOSELOG
#define QRVERBOSE(query, cls, ...)
#else
/** Print a debug message related to resolution.
* \param _query associated kr_query, may be NULL
* \param _cls identifying string, typically of length exactly four (padded)
* \param ... printf-compatible list of parameters
*/
#define QRVERBOSE(_query, _cls, ...) do { \
const struct kr_query *_qry = (_query); \
if (kr_log_trace_enabled(_qry)) { \
kr_log_trace(_qry, (_cls), __VA_ARGS__); \
} else if (VERBOSE_STATUS) { \
unsigned _ind = 0; \
uint32_t _q_uid = q ? q->uid : 0; \
uint32_t _req_uid = q && q->request ? q->request->uid : 0; \
for (; q; q = q->parent, _ind += 2); \
/* simplified kr_log_verbose() calls */ \
printf("[%05u.%02u][%s] %*s", _req_uid, _q_uid, cls, _ind, ""); \
printf(__VA_ARGS__); \
fflush(stdout); \
kr_log_qverbose_impl(_qry, (_cls), __VA_ARGS__); \
} \
}
#else
#define QRVERBOSE(query, cls, ...)
} while (false)
#endif
/** Layer processing states. Only one value at a time (but see TODO).
......
......@@ -690,7 +690,7 @@ static int process_answer(knot_pkt_t *pkt, struct kr_request *req)
const knot_pktsection_t *ans = knot_pkt_section(pkt, KNOT_ANSWER);
if ((pkt_class & (PKT_NOERROR)) && ans->count > 0 &&
knot_dname_is_equal(pkt_qname, query->zone_cut.name)) {
VERBOSE_MSG("<= continuing with qname minimization\n")
VERBOSE_MSG("<= continuing with qname minimization\n");
} else {
/* fall back to disabling minimization */
VERBOSE_MSG("<= retrying with non-minimized name\n");
......
......@@ -133,6 +133,23 @@ void kr_log_verbose(const char *fmt, ...)
}
}
void kr_log_qverbose_impl(const struct kr_query *qry, const char *cls, const char *fmt, ...)
{
unsigned ind = 0;
for (const struct kr_query *q = qry; q; q = q->parent)
ind += 2;
uint32_t qry_uid = qry ? qry->uid : 0;
uint32_t req_uid = qry && qry->request ? qry->request->uid : 0;
/* Simplified kr_log_verbose() calls, first prefix then passed fmt...
* Calling it would take about the same amount of code. */
printf("[%05u.%02u][%s] %*s", req_uid, qry_uid, cls, ind, "");
va_list args;
va_start(args, fmt);
vprintf(fmt, args);
va_end(args);
fflush(stdout);
}
bool kr_log_trace(const struct kr_query *query, const char *source, const char *fmt, ...)
{
if (!kr_log_trace_enabled(query)) {
......
......@@ -56,6 +56,10 @@ KR_EXPORT bool kr_verbose_set(bool status);
KR_EXPORT KR_PRINTF(1)
void kr_log_verbose(const char *fmt, ...);
/** Utility for QRVERBOSE - use that instead. */
KR_EXPORT KR_PRINTF(3)
void kr_log_qverbose_impl(const struct kr_query *qry, const char *cls, const char *fmt, ...);
/**
* @brief Return true if the query has request log handler installed.
*/
......
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