From b2dbe4454e8f9dedaccddb8b8185176b0a8ca3a6 Mon Sep 17 00:00:00 2001 From: Craig Dowell Date: Tue, 20 Oct 2009 12:04:20 -0700 Subject: [PATCH] Backed out changeset 04cc3ffe0202 --- src/core/system-wall-clock-ms.h | 27 ++-------- src/core/test.cc | 38 +++++++++----- src/core/test.h | 14 +++--- src/core/unix-system-wall-clock-ms.cc | 69 ++++---------------------- src/core/win32-system-wall-clock-ms.cc | 18 ------- 5 files changed, 46 insertions(+), 120 deletions(-) diff --git a/src/core/system-wall-clock-ms.h b/src/core/system-wall-clock-ms.h index 9cca3ca38..0c512d3ad 100644 --- a/src/core/system-wall-clock-ms.h +++ b/src/core/system-wall-clock-ms.h @@ -25,9 +25,6 @@ namespace ns3 { /** * \brief measure wall-clock time in milliseconds - - * \todo This class exists also in non-unix systems but is not - * implemented and always return zero as measurd time. */ class SystemWallClockMs { public: @@ -39,31 +36,13 @@ public: */ void Start (void); /** - * \brief Stop measuring the time since Start() was called. - * \returns the measured elapsed wall clock time (in milliseconds) since - * ns3::SystemWallClockMs::Start was invoked. + * \returns the measured elapsed wall clock time since + * ns3::SystemWallClockMs::start was invoked. * - * It is possible to start a new measurement with ns3::SystemWallClockMs::Start + * It is possible to start a new measurement with ns3::SystemWallClockMs::start * after this method returns. */ unsigned long long End (void); - - /** - * \returns the measured elapsed wall clock time (in milliseconds) since - * ns3::SystemWallClockMs::Start was invoked. - */ - double GetElapsedReal (void) const; - /** - * \returns the measured elapsed 'user' wall clock time (in milliseconds) since - * ns3::SystemWallClockMs::Start was invoked. - */ - double GetElapsedUser (void) const; - /** - * \returns the measured elapsed 'system' wall clock time (in milliseconds) since - * ns3::SystemWallClockMs::Start was invoked. - */ - double GetElapsedSystem (void) const; - private: class SystemWallClockMsPrivate *m_priv; }; diff --git a/src/core/test.cc b/src/core/test.cc index 3b3a2db24..57d285ad0 100644 --- a/src/core/test.cc +++ b/src/core/test.cc @@ -262,7 +262,7 @@ TestCase::ContinueOnFailure (void) void TestCase::DoReportStart (void) { - m_clock.Start (); + m_startTime = times (&m_startTimes); if (m_ofs == 0) { @@ -319,18 +319,26 @@ TestCase::DoReportTestFailure ( void TestCase::DoReportEnd (void) { - m_clock.End (); + static long ticksPerSecond = sysconf (_SC_CLK_TCK); + if (m_ofs == 0) { return; } + struct tms endTimes; + clock_t endTime = times (&endTimes); + + clock_t elapsed = endTime - m_startTime; + clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime; + clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime; + (*m_ofs).precision (2); *m_ofs << std::fixed; - *m_ofs << " " << "real " << m_clock.GetElapsedReal () * 1e-3 - << " user " << m_clock.GetElapsedUser () * 1e-3 - << " system " << m_clock.GetElapsedSystem () * 1e-3 + *m_ofs << " " << "real " << static_cast (elapsed) / ticksPerSecond + << " user " << static_cast (elapsedUsr) / ticksPerSecond + << " system " << static_cast (elapsedSys) / ticksPerSecond << "" << std::endl; *m_ofs << " " << std::endl; @@ -515,8 +523,8 @@ TestSuite::ContinueOnFailure (void) void TestSuite::DoReportStart (void) { - m_clock.Start (); - + m_startTime = times (&m_startTimes); + if (m_ofs == 0) { return; @@ -548,19 +556,25 @@ TestSuite::DoReportSuccess (void) void TestSuite::DoReportEnd (void) { - m_clock.End (); - + static long ticksPerSecond = sysconf (_SC_CLK_TCK); + if (m_ofs == 0) { return; } + struct tms endTimes; + clock_t endTime = times (&endTimes); + + clock_t elapsed = endTime - m_startTime; + clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime; + clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime; (*m_ofs).precision (2); *m_ofs << std::fixed; - *m_ofs << " " << "real " << m_clock.GetElapsedReal () * 1e-3 - << " user " << m_clock.GetElapsedUser () * 1e-3 - << " system " << m_clock.GetElapsedSystem () * 1e-3 + *m_ofs << " " << "real " << static_cast (elapsed) / ticksPerSecond + << " user " << static_cast (elapsedUsr) / ticksPerSecond + << " system " << static_cast (elapsedSys) / ticksPerSecond << "" << std::endl; *m_ofs << "" << std::endl; diff --git a/src/core/test.h b/src/core/test.h index 1a6e77950..58db025f9 100644 --- a/src/core/test.h +++ b/src/core/test.h @@ -27,10 +27,7 @@ #include #include #include - -#include "ns3/system-wall-clock-ms.h" - - +#include // // Note on below macros: // @@ -824,7 +821,6 @@ private: TestCase (TestCase& tc); TestCase& operator= (TestCase& tc); - SystemWallClockMs m_clock; std::string m_name; bool m_verbose; bool m_continueOnFailure; @@ -832,6 +828,8 @@ private: std::string m_basedir; std::ofstream *m_ofs; bool m_error; + clock_t m_startTime; + struct tms m_startTimes; }; /** @@ -1059,7 +1057,6 @@ private: TestSuite (TestSuite& ts); TestSuite& operator= (TestSuite& ts); - SystemWallClockMs m_clock; std::string m_name; bool m_verbose; bool m_continueOnFailure; @@ -1067,7 +1064,10 @@ private: std::ofstream *m_ofs; bool m_error; TestType m_type; - + + clock_t m_startTime; + struct tms m_startTimes; + typedef std::vector TestCaseVector_t; TestCaseVector_t m_tests; }; diff --git a/src/core/unix-system-wall-clock-ms.cc b/src/core/unix-system-wall-clock-ms.cc index cfe53932f..14f1fbb5b 100644 --- a/src/core/unix-system-wall-clock-ms.cc +++ b/src/core/unix-system-wall-clock-ms.cc @@ -19,9 +19,7 @@ */ #include "system-wall-clock-ms.h" -#include -#include -#include +#include namespace ns3 { @@ -29,57 +27,28 @@ class SystemWallClockMsPrivate { public: void Start (void); unsigned long long End (void); - double GetElapsedReal (void) const; - double GetElapsedUser (void) const; - double GetElapsedSystem (void) const; - private: - struct tms m_startTimes; - clock_t m_startTime; - double m_elapsedReal; - double m_elapsedUser; - double m_elapsedSystem; + struct timeval m_startTv; + struct timeval m_endTv; }; void SystemWallClockMsPrivate::Start (void) { - m_startTime = times (&m_startTimes); + struct timezone tz; + gettimeofday (&m_startTv, &tz); } unsigned long long SystemWallClockMsPrivate::End (void) { - static long ticksPerSecond = sysconf (_SC_CLK_TCK); - - struct tms endTimes; - clock_t endTime = times (&endTimes); - - m_elapsedReal = 1e3 * static_cast (endTime - m_startTime) / ticksPerSecond; - m_elapsedUser = 1e3 * static_cast (endTimes.tms_utime - m_startTimes.tms_utime) / ticksPerSecond; - m_elapsedSystem = 1e3 * static_cast (endTimes.tms_stime - m_startTimes.tms_stime) / ticksPerSecond; - - return m_elapsedReal; + struct timezone tz; + gettimeofday (&m_endTv, &tz); + unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000; + unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000; + return end - start; } -double -SystemWallClockMsPrivate::GetElapsedReal (void) const -{ - return m_elapsedReal; -} - -double -SystemWallClockMsPrivate::GetElapsedUser (void) const -{ - return m_elapsedUser; -} - -double -SystemWallClockMsPrivate::GetElapsedSystem (void) const -{ - return m_elapsedSystem; -} - SystemWallClockMs::SystemWallClockMs () : m_priv (new SystemWallClockMsPrivate ()) {} @@ -101,22 +70,4 @@ SystemWallClockMs::End (void) return m_priv->End (); } -double -SystemWallClockMs::GetElapsedReal (void) const -{ - return m_priv->GetElapsedReal (); -} - -double -SystemWallClockMs::GetElapsedUser (void) const -{ - return m_priv->GetElapsedUser (); -} - -double -SystemWallClockMs::GetElapsedSystem (void) const -{ - return m_priv->GetElapsedSystem (); -} - }; // namespace ns3 diff --git a/src/core/win32-system-wall-clock-ms.cc b/src/core/win32-system-wall-clock-ms.cc index c02f0f268..1cc9fc2c5 100644 --- a/src/core/win32-system-wall-clock-ms.cc +++ b/src/core/win32-system-wall-clock-ms.cc @@ -61,22 +61,4 @@ SystemWallClockMs::End (void) return m_priv->End (); } -double -SystemWallClockMs::GetElapsedReal (void) const -{ - return 0; -} - -double -SystemWallClockMs::GetElapsedUser (void) const -{ - return 0; -} - -double -SystemWallClockMs::GetElapsedSystem (void) const -{ - return 0; -} - }; // namespace ns3