Fix redbean latency and resource usage logging (#257)

This commit is contained in:
Paul Kulchenko 2021-08-22 20:16:10 -07:00 committed by GitHub
parent 7d25fb0090
commit 818926dbae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -72,6 +72,14 @@ extern unsigned __log_level; /* log level for runtime check */
((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \ ((!__builtin_constant_p(LEVEL) || (LEVEL) <= LOGGABLELEVEL) && \
(LEVEL) <= __log_level) (LEVEL) <= __log_level)
// log a message with the specified log level (not checking if LOGGABLE)
#define ANYF(LEVEL, FMT, ...) \
do { \
++ftrace; \
flogf(LEVEL, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
--ftrace; \
} while (0)
// die with an error message without backtrace and debugger invocation // die with an error message without backtrace and debugger invocation
#define DIEF(FMT, ...) \ #define DIEF(FMT, ...) \
do { \ do { \

View file

@ -1118,7 +1118,7 @@ static void ReportWorkerResources(int pid, struct rusage *ru) {
AppendResourceReport(&b, ru, "\n"); AppendResourceReport(&b, ru, "\n");
if (b) { if (b) {
if ((s = IndentLines(b, appendz(b).i - 1, 0, 1))) { if ((s = IndentLines(b, appendz(b).i - 1, 0, 1))) {
DEBUGF("(stat) resource report for pid %d\n%s", pid, s); ANYF(kLogDebug, "(stat) resource report for pid %d\n%s", pid, s);
free(s); free(s);
} }
free(b); free(b);
@ -6122,8 +6122,8 @@ static bool HandleMessageAcutal(void) {
LockInc(&shared->c.messageshandled); LockInc(&shared->c.messageshandled);
++messageshandled; ++messageshandled;
if (loglatency || LOGGABLE(kLogDebug)) { if (loglatency || LOGGABLE(kLogDebug)) {
DEBUGF("(stat) %`'.*s latency %,ldµs", msg.uri.b - msg.uri.a, inbuf.p + msg.uri.a, ANYF(kLogDebug, "(stat) %`'.*s latency %,ldµs", msg.uri.b - msg.uri.a, inbuf.p + msg.uri.a,
(long)((nowl() - startrequest) * 1e6L)); (long)((nowl() - startrequest) * 1e6L));
} }
if (!generator) { if (!generator) {
return TransmitResponse(p); return TransmitResponse(p);