I'm debugging a problem which will be the topic of the next mail. To do this, I needed the cwd of the compile, and hostname printed in the logfile, otherwise it's impossible to sort out parallel builds; a patch for this is below.
I also found the timestamp useful, but have this as a separate patch as it may be less worth adding and it probably needs work for portability. I won't loose sleep if you want to reject it. These are against trunk. >From 489d53e4a6b0c4497f389b2e6dcc1b3e4bcef1d1 Mon Sep 17 00:00:00 2001 From: Wilson Snyder <wsny...@wsnyder.org> Date: Thu, 6 May 2010 10:13:03 -0400 Subject: [PATCH 1/2] Show hostname and CWD in logfile --- ccache.c | 4 ++++ ccache.h | 1 + util.c | 25 +++++++++++++++++++------ 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/ccache.c b/ccache.c index cbbfdc8..ba3b6ad 100644 --- a/ccache.c +++ b/ccache.c @@ -1673,6 +1673,10 @@ static void ccache(int argc, char *argv[]) process_args(orig_args->argc, orig_args->argv, &preprocessor_args, &compiler_args); + cc_log("Hostname: %s", get_hostname()); + + cc_log("Cwd: %s", current_working_dir); + cc_log("Source file: %s", input_file); if (generating_dependencies) { cc_log("Dependency file: %s", output_dep); diff --git a/ccache.h b/ccache.h index f514057..2277344 100644 --- a/ccache.h +++ b/ccache.h @@ -73,6 +73,7 @@ int move_file(const char *src, const char *dest, int compress_dest); int test_if_compressed(const char *filename); int create_dir(const char *dir); +const char *get_hostname(void); const char *tmp_string(void); char *format_hash_as_string(const unsigned char *hash, unsigned size); int create_hash_dir(char **dir, const char *hash, const char *cache_dir); diff --git a/util.c b/util.c index 34f1b5e..c50a7d5 100644 --- a/util.c +++ b/util.c @@ -272,6 +272,24 @@ int create_dir(const char *dir) } /* + * Return a string with the current hostname. + */ +const char *get_hostname(void) +{ + static char hostname[200] = ""; + + if (!hostname[0]) { + strcpy(hostname, "unknown"); +#if HAVE_GETHOSTNAME + gethostname(hostname, sizeof(hostname)-1); +#endif + hostname[sizeof(hostname)-1] = 0; + } + + return hostname; +} + +/* * Return a string to be used to distinguish temporary files. Also tries to * cope with NFS by adding the local hostname. */ @@ -280,12 +298,7 @@ const char *tmp_string(void) static char *ret; if (!ret) { - char hostname[200]; - strcpy(hostname, "unknown"); -#if HAVE_GETHOSTNAME - gethostname(hostname, sizeof(hostname)-1); -#endif - hostname[sizeof(hostname)-1] = 0; + const char *hostname = get_hostname(); x_asprintf(&ret, "%s.%u", hostname, (unsigned)getpid()); } -- 1.6.4.2 >From d3413e81ab28bc87741dcb2240acd9977c46b69a Mon Sep 17 00:00:00 2001 From: Wilson Snyder <wsny...@wsnyder.org> Date: Thu, 6 May 2010 12:43:13 -0400 Subject: [PATCH 2/2] Show times in logfiles --- util.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/util.c b/util.c index c50a7d5..ae48cf0 100644 --- a/util.c +++ b/util.c @@ -21,6 +21,7 @@ #include <sys/types.h> #include <sys/stat.h> +#include <sys/time.h> // For timestamps - may not be portable #include <fcntl.h> #include <ctype.h> #include <unistd.h> @@ -53,7 +54,10 @@ void cc_log(const char *format, ...) if (!logfile) logfile = fopen(cache_logfile, "a"); if (!logfile) return; - fprintf(logfile, "[%-5d] ", getpid()); + struct timeval tv; + gettimeofday(&tv, NULL); + + fprintf(logfile, "[%10d.%06d,%-5d] ", (int)tv.tv_sec, (int)tv.tv_usec, getpid()); va_start(ap, format); vfprintf(logfile, format, ap); va_end(ap); -- 1.6.4.2 _______________________________________________ ccache mailing list ccache@lists.samba.org https://lists.samba.org/mailman/listinfo/ccache