diff options
author | Erik Schnetter <schnetter@cct.lsu.edu> | 2009-09-03 16:19:15 -0500 |
---|---|---|
committer | Barry Wardell <barry.wardell@gmail.com> | 2011-12-14 16:42:31 +0000 |
commit | 11c4d98017cbb86d08e15fd1b549180184b58a26 (patch) | |
tree | 2546a154c6f7bc0bec87de7316125ae7d1453569 /Carpet/CarpetLib/src/startup_time.cc | |
parent | f520477b1c14e02f1495cfa8d3e09f4e21ab34d0 (diff) |
Import Carpet
Ignore-this: 309b4dd613f4af2b84aa5d6743fdb6b3
Diffstat (limited to 'Carpet/CarpetLib/src/startup_time.cc')
-rw-r--r-- | Carpet/CarpetLib/src/startup_time.cc | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/Carpet/CarpetLib/src/startup_time.cc b/Carpet/CarpetLib/src/startup_time.cc new file mode 100644 index 000000000..f361345fa --- /dev/null +++ b/Carpet/CarpetLib/src/startup_time.cc @@ -0,0 +1,82 @@ +#include <cstdio> +#include <cstdlib> +#include <string> + +#include <cctk.h> + +// IRIX wants this before <time.h> +#if HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#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 + +#if HAVE_UNISTD_H +# include <unistd.h> +#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 |