diff options
author | jthorn <jthorn@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2003-08-05 13:46:08 +0000 |
---|---|---|
committer | jthorn <jthorn@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2003-08-05 13:46:08 +0000 |
commit | ed9c971476dd16b4545eb214e13c1ebd7c69dea2 (patch) | |
tree | c93f08dd8a3ef7c73fa70e37c4247a5fb4a88ad9 /src/main/WarnLevel.c | |
parent | 90be1f0432333a262c2418897e79fb724307e4f2 (diff) |
implement new flesh parameter cactus::info_format
to optionally provide timestamps for CCTK_INFO() / CCTK_VInfo() output
the current implementation uses gettimeofday(2) to provide
microsecond-precision timing info if this is available
(Cactus checks this at configure time), otherwise it falls back
to time(3) (which only gives 1 second precision) which is in
the ISO C standard, and so should be available everywhere...
git-svn-id: http://svn.cactuscode.org/flesh/trunk@3376 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'src/main/WarnLevel.c')
-rw-r--r-- | src/main/WarnLevel.c | 99 |
1 files changed, 97 insertions, 2 deletions
diff --git a/src/main/WarnLevel.c b/src/main/WarnLevel.c index 4a559db8..ded90d9d 100644 --- a/src/main/WarnLevel.c +++ b/src/main/WarnLevel.c @@ -15,6 +15,17 @@ #include <stdarg.h> #include <string.h> +#if TIME_WITH_SYS_TIME +# include <sys/time.h> +# include <time.h> +#else +# if HAVE_SYS_TIME_H +# include <sys/time.h> +# elif HAVE_TIME_H +# include <time.h> +# endif +#endif + #include "StoreKeyedData.h" #include "cctk_Comm.h" @@ -119,6 +130,12 @@ void CCTK_FCALL CCTK_FNAME (CCTK_Info) Info output routine with variable argument list @enddesc + @history + @date Mon Aug 4 17:56:06 CEST 2003 + @author Jonathan Thornburg + @hdesc add cactus::info_format parameter + @endhistory + @var thorn @vdesc Name of originating thorn @vtype const char * @@ -144,14 +161,92 @@ int CCTK_VInfo (const char *thorn, const char *format, ...) { va_list ap; + static int info_format_decoded = 0; /* are the following two flags valid? */ + /* Boolean flags decoded from cactus::info_format */ + static int info_format_numeric = 0; /* print a numeric timestamp? */ + static int info_format_human_readable = 0; /* print a human-readable timestamp? */ - va_start (ap, format); + /* + * if we haven't already decoded cactus::info_format into the + * Boolean flags, do so + */ + if (! info_format_decoded) + { + /* get cactus::info_format and decode it into Boolean flags */ + const char* const info_format = + * ( (const char*const *) + CCTK_ParameterGet("info_format", "Cactus", NULL) ); + if (CCTK_Equals(info_format, "basic")) + { + /* "basic" :: "INFO (ThornName): message" */ + info_format_numeric = 0; + info_format_human_readable = 0; + } + else if (CCTK_Equals(info_format, "numeric time stamp")) + { + /* "numeric time stamp" :: "numeric_timestamp\tINFO (ThornName): message" */ + info_format_numeric = 1; + info_format_human_readable = 0; + } + else if (CCTK_Equals(info_format, "human-readable time stamp")) + { + /* "human-readable time stamp" :: "human readable timestamp: INFO (ThornName): message" */ + info_format_numeric = 0; + info_format_human_readable = 1; + } + else if (CCTK_Equals(info_format, "full time stamp")) + { + /* "full time stamp" :: "numeric_timestamp\thuman readable timestamp: INFO (ThornName): message" */ + info_format_numeric = 1; + info_format_human_readable = 1; + } + info_format_decoded = 1; + } + + /* + * print any time stamps desired + */ + if (info_format_numeric || info_format_human_readable) + { + double numeric_time; + + /* get the timing info */ +#ifdef HAVE_TIME_GETTIMEOFDAY + /* use gettimeofday() to get (up to) microsecond-level timing info */ + #define NUMERIC_TIME_FORMAT "%.6f" + struct timeval timeval; + gettimeofday(&timeval, NULL); + numeric_time = timeval.tv_sec + 1.0e-6*timeval.tv_usec; +#else + /* fall back to time() ; this is ISO C, so everyone should have it */ + #define NUMERIC_TIME_FORMAT "%.0f" + numeric_time = (double) time(NULL); +#endif + + if (info_format_numeric) + { + fprintf(stdout, NUMERIC_TIME_FORMAT "\t", numeric_time); + } + + if (info_format_human_readable) + { + /* 123456789 123456789 1234 */ + /* time_buffer --> a string like "Thu Nov 24 18:22:48 1986\n" */ + const time_t time_t_numeric_time = (time_t) numeric_time; + const char* const time_buffer = ctime(& time_t_numeric_time); + fprintf(stdout, "%.24s: ", time_buffer); + } + } + + /* + * print the INFO message itself + */ + va_start (ap, format); fprintf (stdout, "INFO (%s): ", thorn); vfprintf (stdout, format, ap); fprintf (stdout, "\n"); fflush (stdout); - va_end (ap); return (0); |