1.1 --- a/src/core/system-wall-clock-ms.h Mon Oct 26 10:15:22 2009 +0000
1.2 +++ b/src/core/system-wall-clock-ms.h Mon Oct 26 11:26:35 2009 -0700
1.3 @@ -25,6 +25,9 @@
1.4
1.5 /**
1.6 * \brief measure wall-clock time in milliseconds
1.7 +
1.8 + * \todo This class exists also in non-unix systems but is not
1.9 + * implemented and always return zero as measurd time.
1.10 */
1.11 class SystemWallClockMs {
1.12 public:
1.13 @@ -36,13 +39,31 @@
1.14 */
1.15 void Start (void);
1.16 /**
1.17 - * \returns the measured elapsed wall clock time since
1.18 - * ns3::SystemWallClockMs::start was invoked.
1.19 + * \brief Stop measuring the time since Start() was called.
1.20 + * \returns the measured elapsed wall clock time (in milliseconds) since
1.21 + * ns3::SystemWallClockMs::Start was invoked.
1.22 *
1.23 - * It is possible to start a new measurement with ns3::SystemWallClockMs::start
1.24 + * It is possible to start a new measurement with ns3::SystemWallClockMs::Start
1.25 * after this method returns.
1.26 */
1.27 unsigned long long End (void);
1.28 +
1.29 + /**
1.30 + * \returns the measured elapsed wall clock time (in milliseconds) since
1.31 + * ns3::SystemWallClockMs::Start was invoked.
1.32 + */
1.33 + double GetElapsedReal (void) const;
1.34 + /**
1.35 + * \returns the measured elapsed 'user' wall clock time (in milliseconds) since
1.36 + * ns3::SystemWallClockMs::Start was invoked.
1.37 + */
1.38 + double GetElapsedUser (void) const;
1.39 + /**
1.40 + * \returns the measured elapsed 'system' wall clock time (in milliseconds) since
1.41 + * ns3::SystemWallClockMs::Start was invoked.
1.42 + */
1.43 + double GetElapsedSystem (void) const;
1.44 +
1.45 private:
1.46 class SystemWallClockMsPrivate *m_priv;
1.47 };
2.1 --- a/src/core/test.cc Mon Oct 26 10:15:22 2009 +0000
2.2 +++ b/src/core/test.cc Mon Oct 26 11:26:35 2009 -0700
2.3 @@ -262,7 +262,7 @@
2.4 void
2.5 TestCase::DoReportStart (void)
2.6 {
2.7 - m_startTime = times (&m_startTimes);
2.8 + m_clock.Start ();
2.9
2.10 if (m_ofs == 0)
2.11 {
2.12 @@ -319,26 +319,18 @@
2.13 void
2.14 TestCase::DoReportEnd (void)
2.15 {
2.16 - static long ticksPerSecond = sysconf (_SC_CLK_TCK);
2.17 -
2.18 + m_clock.End ();
2.19 if (m_ofs == 0)
2.20 {
2.21 return;
2.22 }
2.23
2.24 - struct tms endTimes;
2.25 - clock_t endTime = times (&endTimes);
2.26 -
2.27 - clock_t elapsed = endTime - m_startTime;
2.28 - clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
2.29 - clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
2.30 -
2.31 (*m_ofs).precision (2);
2.32 *m_ofs << std::fixed;
2.33
2.34 - *m_ofs << " <CaseTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
2.35 - << " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
2.36 - << " system " << static_cast<double> (elapsedSys) / ticksPerSecond
2.37 + *m_ofs << " <CaseTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
2.38 + << " user " << m_clock.GetElapsedUser () * 1e-3
2.39 + << " system " << m_clock.GetElapsedSystem () * 1e-3
2.40 << "</CaseTime>" << std::endl;
2.41
2.42 *m_ofs << " </TestCase>" << std::endl;
2.43 @@ -523,8 +515,8 @@
2.44 void
2.45 TestSuite::DoReportStart (void)
2.46 {
2.47 - m_startTime = times (&m_startTimes);
2.48 -
2.49 + m_clock.Start ();
2.50 +
2.51 if (m_ofs == 0)
2.52 {
2.53 return;
2.54 @@ -556,25 +548,19 @@
2.55 void
2.56 TestSuite::DoReportEnd (void)
2.57 {
2.58 - static long ticksPerSecond = sysconf (_SC_CLK_TCK);
2.59 -
2.60 + m_clock.End ();
2.61 +
2.62 if (m_ofs == 0)
2.63 {
2.64 return;
2.65 }
2.66 - struct tms endTimes;
2.67 - clock_t endTime = times (&endTimes);
2.68 -
2.69 - clock_t elapsed = endTime - m_startTime;
2.70 - clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
2.71 - clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
2.72
2.73 (*m_ofs).precision (2);
2.74 *m_ofs << std::fixed;
2.75
2.76 - *m_ofs << " <SuiteTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
2.77 - << " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
2.78 - << " system " << static_cast<double> (elapsedSys) / ticksPerSecond
2.79 + *m_ofs << " <SuiteTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
2.80 + << " user " << m_clock.GetElapsedUser () * 1e-3
2.81 + << " system " << m_clock.GetElapsedSystem () * 1e-3
2.82 << "</SuiteTime>" << std::endl;
2.83
2.84 *m_ofs << "</TestSuite>" << std::endl;
3.1 --- a/src/core/test.h Mon Oct 26 10:15:22 2009 +0000
3.2 +++ b/src/core/test.h Mon Oct 26 11:26:35 2009 -0700
3.3 @@ -27,7 +27,10 @@
3.4 #include <list>
3.5 #include <limits>
3.6 #include <stdint.h>
3.7 -#include <sys/times.h>
3.8 +
3.9 +#include "ns3/system-wall-clock-ms.h"
3.10 +
3.11 +
3.12 //
3.13 // Note on below macros:
3.14 //
3.15 @@ -821,6 +824,7 @@
3.16 TestCase (TestCase& tc);
3.17 TestCase& operator= (TestCase& tc);
3.18
3.19 + SystemWallClockMs m_clock;
3.20 std::string m_name;
3.21 bool m_verbose;
3.22 bool m_continueOnFailure;
3.23 @@ -828,8 +832,6 @@
3.24 std::string m_basedir;
3.25 std::ofstream *m_ofs;
3.26 bool m_error;
3.27 - clock_t m_startTime;
3.28 - struct tms m_startTimes;
3.29 };
3.30
3.31 /**
3.32 @@ -1057,6 +1059,7 @@
3.33 TestSuite (TestSuite& ts);
3.34 TestSuite& operator= (TestSuite& ts);
3.35
3.36 + SystemWallClockMs m_clock;
3.37 std::string m_name;
3.38 bool m_verbose;
3.39 bool m_continueOnFailure;
3.40 @@ -1064,10 +1067,7 @@
3.41 std::ofstream *m_ofs;
3.42 bool m_error;
3.43 TestType m_type;
3.44 -
3.45 - clock_t m_startTime;
3.46 - struct tms m_startTimes;
3.47 -
3.48 +
3.49 typedef std::vector<TestCase *> TestCaseVector_t;
3.50 TestCaseVector_t m_tests;
3.51 };
4.1 --- a/src/core/unix-system-wall-clock-ms.cc Mon Oct 26 10:15:22 2009 +0000
4.2 +++ b/src/core/unix-system-wall-clock-ms.cc Mon Oct 26 11:26:35 2009 -0700
4.3 @@ -19,7 +19,9 @@
4.4 */
4.5
4.6 #include "system-wall-clock-ms.h"
4.7 -#include <sys/time.h>
4.8 +#include <sys/times.h>
4.9 +#include <unistd.h>
4.10 +#include <limits.h>
4.11
4.12 namespace ns3 {
4.13
4.14 @@ -27,28 +29,57 @@
4.15 public:
4.16 void Start (void);
4.17 unsigned long long End (void);
4.18 + double GetElapsedReal (void) const;
4.19 + double GetElapsedUser (void) const;
4.20 + double GetElapsedSystem (void) const;
4.21 +
4.22 private:
4.23 - struct timeval m_startTv;
4.24 - struct timeval m_endTv;
4.25 + struct tms m_startTimes;
4.26 + clock_t m_startTime;
4.27 + double m_elapsedReal;
4.28 + double m_elapsedUser;
4.29 + double m_elapsedSystem;
4.30 };
4.31
4.32 void
4.33 SystemWallClockMsPrivate::Start (void)
4.34 {
4.35 - struct timezone tz;
4.36 - gettimeofday (&m_startTv, &tz);
4.37 + m_startTime = times (&m_startTimes);
4.38 }
4.39
4.40 unsigned long long
4.41 SystemWallClockMsPrivate::End (void)
4.42 {
4.43 - struct timezone tz;
4.44 - gettimeofday (&m_endTv, &tz);
4.45 - unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
4.46 - unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
4.47 - return end - start;
4.48 + static long ticksPerSecond = sysconf (_SC_CLK_TCK);
4.49 +
4.50 + struct tms endTimes;
4.51 + clock_t endTime = times (&endTimes);
4.52 +
4.53 + m_elapsedReal = 1e3 * static_cast<double> (endTime - m_startTime) / ticksPerSecond;
4.54 + m_elapsedUser = 1e3 * static_cast<double> (endTimes.tms_utime - m_startTimes.tms_utime) / ticksPerSecond;
4.55 + m_elapsedSystem = 1e3 * static_cast<double> (endTimes.tms_stime - m_startTimes.tms_stime) / ticksPerSecond;
4.56 +
4.57 + return m_elapsedReal;
4.58 }
4.59
4.60 +double
4.61 +SystemWallClockMsPrivate::GetElapsedReal (void) const
4.62 +{
4.63 + return m_elapsedReal;
4.64 +}
4.65 +
4.66 +double
4.67 +SystemWallClockMsPrivate::GetElapsedUser (void) const
4.68 +{
4.69 + return m_elapsedUser;
4.70 +}
4.71 +
4.72 +double
4.73 +SystemWallClockMsPrivate::GetElapsedSystem (void) const
4.74 +{
4.75 + return m_elapsedSystem;
4.76 +}
4.77 +
4.78 SystemWallClockMs::SystemWallClockMs ()
4.79 : m_priv (new SystemWallClockMsPrivate ())
4.80 {}
4.81 @@ -70,4 +101,22 @@
4.82 return m_priv->End ();
4.83 }
4.84
4.85 +double
4.86 +SystemWallClockMs::GetElapsedReal (void) const
4.87 +{
4.88 + return m_priv->GetElapsedReal ();
4.89 +}
4.90 +
4.91 +double
4.92 +SystemWallClockMs::GetElapsedUser (void) const
4.93 +{
4.94 + return m_priv->GetElapsedUser ();
4.95 +}
4.96 +
4.97 +double
4.98 +SystemWallClockMs::GetElapsedSystem (void) const
4.99 +{
4.100 + return m_priv->GetElapsedSystem ();
4.101 +}
4.102 +
4.103 }; // namespace ns3
5.1 --- a/src/core/win32-system-wall-clock-ms.cc Mon Oct 26 10:15:22 2009 +0000
5.2 +++ b/src/core/win32-system-wall-clock-ms.cc Mon Oct 26 11:26:35 2009 -0700
5.3 @@ -61,4 +61,22 @@
5.4 return m_priv->End ();
5.5 }
5.6
5.7 +double
5.8 +SystemWallClockMs::GetElapsedReal (void) const
5.9 +{
5.10 + return 0;
5.11 +}
5.12 +
5.13 +double
5.14 +SystemWallClockMs::GetElapsedUser (void) const
5.15 +{
5.16 + return 0;
5.17 +}
5.18 +
5.19 +double
5.20 +SystemWallClockMs::GetElapsedSystem (void) const
5.21 +{
5.22 + return 0;
5.23 +}
5.24 +
5.25 }; // namespace ns3