From: Joel Rosdahl Date: Fri, 29 Jul 2011 19:45:26 +0000 (+0200) Subject: Don't fetch current time for each logged configuration item X-Git-Tag: v3.2~181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1c723288bcaa0bd402cc5ed517a10cdac703575;p=thirdparty%2Fccache.git Don't fetch current time for each logged configuration item --- diff --git a/ccache.c b/ccache.c index d726a5661..ddec7d135 100644 --- a/ccache.c +++ b/ccache.c @@ -1936,7 +1936,7 @@ static void configuration_logger(const char *descr, const char *origin, void *context) { (void)context; - cc_log_without_flush("Config: (%s) %s", origin, descr); + cc_bulklog("Config: (%s) %s", origin, descr); } /* the main ccache driver function */ diff --git a/ccache.h b/ccache.h index 29f04dbd4..3608c408d 100644 --- a/ccache.h +++ b/ccache.h @@ -101,7 +101,7 @@ bool hash_file(struct mdfour *md, const char *fname); void cc_vlog(const char *format, va_list ap); void cc_log(const char *format, ...) ATTR_FORMAT(printf, 1, 2); -void cc_log_without_flush(const char *format, ...) ATTR_FORMAT(printf, 1, 2); +void cc_bulklog(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void cc_log_argv(const char *prefix, char **argv); void fatal(const char *format, ...) ATTR_FORMAT(printf, 1, 2); void copy_fd(int fd_in, int fd_out); diff --git a/util.c b/util.c index d6be41e87..9f266348d 100644 --- a/util.c +++ b/util.c @@ -56,22 +56,26 @@ init_log(void) } static void -log_prefix(void) +log_prefix(bool log_updated_time) { #ifdef HAVE_GETTIMEOFDAY char timestamp[100]; struct timeval tv; struct tm *tm; + static char prefix[200]; - gettimeofday(&tv, NULL); + if (log_updated_time) { + gettimeofday(&tv, NULL); #ifdef __MINGW64_VERSION_MAJOR - tm = _localtime32(&tv.tv_sec); + tm = _localtime32(&tv.tv_sec); #else - tm = localtime(&tv.tv_sec); + tm = localtime(&tv.tv_sec); #endif - strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm); - fprintf(logfile, "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, - (int)getpid()); + strftime(timestamp, sizeof(timestamp), "%Y-%m-%dT%H:%M:%S", tm); + snprintf(prefix, sizeof(prefix), + "[%s.%06d %-5d] ", timestamp, (int)tv.tv_usec, (int)getpid()); + } + fputs(prefix, logfile); #else fprintf(logfile, "[%-5d] ", (int)getpid()); #endif @@ -97,21 +101,27 @@ path_max(const char *path) #endif } -/* - * Write a message to the log file (adding a newline) and flush. - */ -void -cc_vlog(const char *format, va_list ap) +static void +vlog(const char *format, va_list ap, bool log_updated_time) { if (!init_log()) { return; } - log_prefix(); + log_prefix(log_updated_time); vfprintf(logfile, format, ap); fprintf(logfile, "\n"); } +/* + * Write a message to the log file (adding a newline) and flush. + */ +void +cc_vlog(const char *format, va_list ap) +{ + vlog(format, ap, true); +} + /* * Write a message to the log file (adding a newline) and flush. */ @@ -120,7 +130,7 @@ cc_log(const char *format, ...) { va_list ap; va_start(ap, format); - cc_vlog(format, ap); + vlog(format, ap, true); va_end(ap); if (logfile) { fflush(logfile); @@ -128,14 +138,15 @@ cc_log(const char *format, ...) } /* - * Write a message to the log file (adding a newline). + * Write a message to the log file (adding a newline) without flushing and with + * a reused timestamp. */ void -cc_log_without_flush(const char *format, ...) +cc_bulklog(const char *format, ...) { va_list ap; va_start(ap, format); - cc_vlog(format, ap); + vlog(format, ap, false); va_end(ap); } @@ -149,7 +160,7 @@ cc_log_argv(const char *prefix, char **argv) return; } - log_prefix(); + log_prefix(true); fputs(prefix, logfile); print_command(logfile, argv); fflush(logfile);