]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't fetch current time for each logged configuration item
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 29 Jul 2011 19:45:26 +0000 (21:45 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 29 Jul 2011 19:45:26 +0000 (21:45 +0200)
ccache.c
ccache.h
util.c

index d726a5661a4f4cd1894b66e0b8f3be1ccd67a4aa..ddec7d1356c95ead8c91221c5f5aa0134637dd4c 100644 (file)
--- 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 */
index 29f04dbd4fb94add991f3405854906231ced1a2e..3608c408d15d51b0086a8ec0c2fcf593749915bb 100644 (file)
--- 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 d6be41e87c2ebd691b9db65b3d87e17832a35c93..9f266348dc67eb581d5caae778359c46dfcfe8f1 100644 (file)
--- 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);