From b76bd91beef9a279cc730ce7167408b2c01953b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 30 Jul 2018 13:45:44 +0200 Subject: wrapper: improve performance of verbose_log This reduces the number of syscalls per call from 3 to 1, on one specific game when piping everything to /dev/null this reduces the runtime from 14.115s to 8.800s. Signed-off-by: Jari Vetoniemi --- src/wrapper/wrapper.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/wrapper') diff --git a/src/wrapper/wrapper.c b/src/wrapper/wrapper.c index d78f1a4..b3249b6 100644 --- a/src/wrapper/wrapper.c +++ b/src/wrapper/wrapper.c @@ -21,12 +21,12 @@ verbose_log(const char *fmt, ...) static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_lock(&mutex); - fprintf(stderr, "%lu: ", pthread_self()); va_list ap; va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + char buf[1024]; + vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); - fputc('\n', stderr); + fprintf(stderr, "%lu: %s\n", pthread_self(), buf); pthread_mutex_unlock(&mutex); } -- cgit v1.2.3-70-g09d2