Skip to content
Snippets Groups Projects
Commit 7ed1d30a authored by Peter W. Draper's avatar Peter W. Draper
Browse files

Don't include date in message time stamps, increase accuracy to 1/10th second,...

Don't include date in message time stamps, increase accuracy to 1/10th second, if no HAVE_GETTIME etc. report ticks since the program started.
parent 59a8c1a9
No related branches found
No related tags found
2 merge requests!136Master,!107Code timing and verbosity
...@@ -126,6 +126,9 @@ int main(int argc, char *argv[]) { ...@@ -126,6 +126,9 @@ int main(int argc, char *argv[]) {
&initial_partition.grid[1], &initial_partition.grid[0]); &initial_partition.grid[1], &initial_partition.grid[0]);
#endif #endif
/* Initialize CPU frequency, this also starts time. */
clocks_set_cpufreq(cpufreq);
/* Greeting message */ /* Greeting message */
if (myrank == 0) greetings(); if (myrank == 0) greetings();
...@@ -332,11 +335,11 @@ int main(int argc, char *argv[]) { ...@@ -332,11 +335,11 @@ int main(int argc, char *argv[]) {
aFactor(&us, UNIT_CONV_ENTROPY), hFactor(&us, UNIT_CONV_ENTROPY)); aFactor(&us, UNIT_CONV_ENTROPY), hFactor(&us, UNIT_CONV_ENTROPY));
} }
/* Initialize CPU frequency. */ /* Report CPU frequency. */
clocks_set_cpufreq(cpufreq); if (myrank == 0) {
cpufreq = clocks_get_cpufreq(); cpufreq = clocks_get_cpufreq();
if (myrank == 0)
message("CPU frequency used for tick conversion: %llu Hz", cpufreq); message("CPU frequency used for tick conversion: %llu Hz", cpufreq);
}
/* Check we have sensible time step bounds */ /* Check we have sensible time step bounds */
if (dt_min > dt_max) if (dt_min > dt_max)
......
...@@ -41,6 +41,9 @@ ...@@ -41,6 +41,9 @@
/* The CPU frequency used to convert ticks to seconds. */ /* The CPU frequency used to convert ticks to seconds. */
static unsigned long long clocks_cpufreq = 0; static unsigned long long clocks_cpufreq = 0;
/* Ticks when the CPU frequency was initialised. Used in elapsed. */
static ticks clocks_start = 0;
/* The units of any returned times. */ /* The units of any returned times. */
static char *clocks_units[] = {"ms", "ticks"}; static char *clocks_units[] = {"ms", "ticks"};
static int clocks_units_index = 0; static int clocks_units_index = 0;
...@@ -102,6 +105,7 @@ void clocks_set_cpufreq(unsigned long long freq) { ...@@ -102,6 +105,7 @@ void clocks_set_cpufreq(unsigned long long freq) {
} else { } else {
clocks_estimate_cpufreq(); clocks_estimate_cpufreq();
} }
clocks_start = getticks();
} }
/** /**
...@@ -223,29 +227,34 @@ double clocks_from_ticks(ticks tics) { ...@@ -223,29 +227,34 @@ double clocks_from_ticks(ticks tics) {
const char *clocks_getunit() { return clocks_units[clocks_units_index]; } const char *clocks_getunit() { return clocks_units[clocks_units_index]; }
/** /**
* @brief returns a string containing the local date and time * @brief returns the time of day to 1/10th second accuracy.
* *
* The date is return in the format [YYYY-MM-DD hh:mm:ss] * The date is return in the format [hh:mm:ss.s]
* *
* @result the current time. * @result the current time of day.
*/ */
const char *clocks_get_timeofday() { const char *clocks_get_timeofday() {
#if defined(HAVE_GETTIMEOFDAY) && defined(HAVE_LOCALTIME) && \ static char buffer[40];
#if defined(HAVE_CLOCK_GETTIME) && defined(HAVE_LOCALTIME) && \
defined(HAVE_STRFTIME) defined(HAVE_STRFTIME)
struct timeval time; struct timespec time;
struct tm *local_time; struct tm *local_time;
static char buffer[40]; char fmttime[40];
/* Get the local time of day */ clock_gettime(CLOCK_REALTIME, &time);
gettimeofday(&time, NULL);
local_time = localtime(&time.tv_sec); local_time = localtime(&time.tv_sec);
/* Make it a string */ /* Make it a string */
strftime(buffer, 40, "[%F %T]", local_time); strftime(fmttime, 40, "%T", local_time);
/* 1/10 seconds. */
int tseconds = time.tv_nsec / 100000000;
sprintf(buffer, "[%s.%01d]", fmttime, tseconds);
#else #else
static char buffer[40] = "[Unknown time]"; sprintf(buffer, "[%08.1f]", clocks_diff_ticks(getticks(),clocks_start)/100.0);
#endif #endif
return buffer; return buffer;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment