diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2002-11-06 13:06:49 -0500 |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2002-11-06 13:06:49 -0500 |
commit | d7ee016535a12737b9abb41e4032a6a5ab85b095 (patch) | |
tree | 0bccce88590c6fb008b186526d67be38ab09beb1 | |
parent | 3d4a2fdc52fa01353653afc8835653559f14e10b (diff) | |
download | cmake-d7ee016535a12737b9abb41e4032a6a5ab85b095.tar.gz |
Move the hi-res time to system tools
-rw-r--r-- | Source/cmSystemTools.cxx | 55 | ||||
-rw-r--r-- | Source/cmSystemTools.h | 9 | ||||
-rw-r--r-- | Source/ctest.cxx | 59 |
3 files changed, 66 insertions, 57 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index 1a81a1874b..3a6c362946 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -70,6 +70,61 @@ inline int Chdir(const char* dir) } #endif + +/* Implement floattime() for various platforms */ +// Taken from Python 2.1.3 + +#if defined( _WIN32 ) && !defined( __CYGWIN__ ) +# include <sys/timeb.h> +# define HAVE_FTIME +# if defined( __BORLANDC__) +# define FTIME ftime +# define TIMEB timeb +# else // Visual studio? +# define FTIME _ftime +# define TIMEB _timeb +# endif +#elif defined( __CYGWIN__ ) || defined( __linux__ ) +# include <sys/time.h> +# define HAVE_GETTIMEOFDAY +#endif + +double +cmSystemTools::GetTime(void) +{ + /* There are three ways to get the time: + (1) gettimeofday() -- resolution in microseconds + (2) ftime() -- resolution in milliseconds + (3) time() -- resolution in seconds + In all cases the return value is a float in seconds. + Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may + fail, so we fall back on ftime() or time(). + Note: clock resolution does not imply clock accuracy! */ +#ifdef HAVE_GETTIMEOFDAY + { + struct timeval t; +#ifdef GETTIMEOFDAY_NO_TZ + if (gettimeofday(&t) == 0) + return (double)t.tv_sec + t.tv_usec*0.000001; +#else /* !GETTIMEOFDAY_NO_TZ */ + if (gettimeofday(&t, (struct timezone *)NULL) == 0) + return (double)t.tv_sec + t.tv_usec*0.000001; +#endif /* !GETTIMEOFDAY_NO_TZ */ + } +#endif /* !HAVE_GETTIMEOFDAY */ + { +#if defined(HAVE_FTIME) + struct TIMEB t; + FTIME(&t); + return (double)t.time + (double)t.millitm * (double)0.001; +#else /* !HAVE_FTIME */ + time_t secs; + time(&secs); + return (double)secs; +#endif /* !HAVE_FTIME */ + } +} + bool cmSystemTools::s_DisableRunCommandOutput = false; bool cmSystemTools::s_ErrorOccured = false; bool cmSystemTools::s_DisableMessages = false; diff --git a/Source/cmSystemTools.h b/Source/cmSystemTools.h index 67b93007ed..5218fa9e1d 100644 --- a/Source/cmSystemTools.h +++ b/Source/cmSystemTools.h @@ -38,6 +38,15 @@ public: static bool MakeDirectory(const char* path); /** + * Get current time as a double. On certain platforms this will + * return higher resolution than seconds: + * (1) gettimeofday() -- resolution in microseconds + * (2) ftime() -- resolution in milliseconds + * (3) time() -- resolution in seconds + */ + static double GetTime(); + + /** * Replace replace all occurances of the string in * the source string. */ diff --git a/Source/ctest.cxx b/Source/ctest.cxx index 45f1f478b4..d17ce2ce6d 100644 --- a/Source/ctest.cxx +++ b/Source/ctest.cxx @@ -21,61 +21,6 @@ #include <stdio.h> #include <time.h> - -/* Implement floattime() for various platforms */ -// Taken from Python 2.1.3 - -#if defined( _WIN32 ) && !defined( __CYGWIN__ ) -# include <sys/timeb.h> -# define HAVE_FTIME -# if defined( __BORLANDC__) -# define FTIME ftime -# define TIMEB timeb -# else // Visual studio? -# define FTIME _ftime -# define TIMEB _timeb -# endif -#elif defined( __CYGWIN__ ) || defined( __linux__ ) -# include <sys/time.h> -# define HAVE_GETTIMEOFDAY -#endif - -static double -floattime(void) -{ - /* There are three ways to get the time: - (1) gettimeofday() -- resolution in microseconds - (2) ftime() -- resolution in milliseconds - (3) time() -- resolution in seconds - In all cases the return value is a float in seconds. - Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may - fail, so we fall back on ftime() or time(). - Note: clock resolution does not imply clock accuracy! */ -#ifdef HAVE_GETTIMEOFDAY - { - struct timeval t; -#ifdef GETTIMEOFDAY_NO_TZ - if (gettimeofday(&t) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#else /* !GETTIMEOFDAY_NO_TZ */ - if (gettimeofday(&t, (struct timezone *)NULL) == 0) - return (double)t.tv_sec + t.tv_usec*0.000001; -#endif /* !GETTIMEOFDAY_NO_TZ */ - } -#endif /* !HAVE_GETTIMEOFDAY */ - { -#if defined(HAVE_FTIME) - struct TIMEB t; - FTIME(&t); - return (double)t.time + (double)t.millitm * (double)0.001; -#else /* !HAVE_FTIME */ - time_t secs; - time(&secs); - return (double)secs; -#endif /* !HAVE_FTIME */ - } -} - static std::string CleanString(std::string str) { std::string::size_type spos = str.find_first_not_of(" \n\t"); @@ -874,7 +819,7 @@ void ctest::ProcessDirectory(std::vector<std::string> &passed, int retVal; double clock_start, clock_finish; - clock_start = floattime(); + clock_start = cmSystemTools::GetTime(); if ( m_Verbose ) { @@ -882,7 +827,7 @@ void ctest::ProcessDirectory(std::vector<std::string> &passed, } bool res = cmSystemTools::RunCommand(testCommand.c_str(), output, retVal, 0, false); - clock_finish = floattime(); + clock_finish = cmSystemTools::GetTime(); cres.m_ExecutionTime = (double)(clock_finish - clock_start); cres.m_FullCommandLine = testCommand; |