#include #include #include #include // IRIX wants this before #if HAVE_SYS_TYPES_H # include #endif #if TIME_WITH_SYS_TIME # include # include #else # if HAVE_SYS_TIME_H # include # elif HAVE_TIME_H # include # endif #endif #if HAVE_UNISTD_H # include #endif #include "startup_time.hh" namespace CarpetLib { using namespace std; // Return the current wall time static double get_walltime () { #ifdef HAVE_TIME_GETTIMEOFDAY // get the current time struct timeval tv; gettimeofday (& tv, 0); return tv.tv_sec + tv.tv_usec / 1.0e6; #else return 0.0; #endif } void output_startup_time () { char * const cactus_starttime = getenv ("CACTUS_STARTTIME"); if (not cactus_starttime) { CCTK_VWarn (CCTK_WARN_PICKY, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not determine Cactus startup time (environment variable CACTUS_STARTTIME is not set; it should be set to the output of \"date +%%s\")"); return; } double starttime; int const iret = sscanf (cactus_starttime, "%lf", &starttime); if (iret != 1) { CCTK_VWarn (CCTK_WARN_COMPLAIN, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not determine Cactus startup time (environment variable CACTUS_STARTTIME has illegal value \"%s\"; it should instead be set to the output of \"date +%%s\", which is a single number)", cactus_starttime); return; } double const currenttime = get_walltime (); double const startuptime = currenttime - starttime; CCTK_VInfo (CCTK_THORNSTRING, "Process startup time was %.3g seconds", startuptime); } } // namespace CarpetLib