From ccd658a2d5f917db963e179557fc50a7c4a20a8d Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 20 Aug 2018 17:57:15 +0200 Subject: [PATCH] log: improve performance of log_print() --- lib/log.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/log.c b/lib/log.c index 6e149cf41..9578449ca 100644 --- a/lib/log.c +++ b/lib/log.c @@ -28,7 +28,6 @@ #include #include #include -#include #include #include @@ -275,17 +274,20 @@ void log_print(struct log *l, const char *lvl, const char *fmt, ...) void log_vprint(struct log *l, const char *lvl, const char *fmt, va_list ap) { struct timespec ts = time_now(); - thread_local char buf[1024]; + static __thread char buf[1024]; + + int off = 0; + int len = sizeof(buf); /* Optional prefix */ if (l->prefix) - strcatf(&buf, "%s", l->prefix); + off += snprintf(buf + off, len - off, "%s", l->prefix); /* Timestamp & Severity */ - strcatf(&buf, "%10.3f %-5s ", time_delta(&l->epoch, &ts), lvl); + off += snprintf(buf + off, len - off, "%10.3f %-5s ", time_delta(&l->epoch, &ts), lvl); /* Format String */ - vstrcatf(&buf, fmt, ap); + off += vsnprintf(buf + off, len - off, fmt, ap); /* Output */ #ifdef ENABLE_OPAL_ASYNC