Backed out changeset 04cc3ffe0202

This commit is contained in:
Craig Dowell
2009-10-20 12:04:20 -07:00
parent 48ee52fffb
commit b2dbe4454e
5 changed files with 46 additions and 120 deletions

View File

@@ -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;
};

View File

@@ -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 << " <CaseTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
<< " user " << m_clock.GetElapsedUser () * 1e-3
<< " system " << m_clock.GetElapsedSystem () * 1e-3
*m_ofs << " <CaseTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
<< " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
<< " system " << static_cast<double> (elapsedSys) / ticksPerSecond
<< "</CaseTime>" << std::endl;
*m_ofs << " </TestCase>" << 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 << " <SuiteTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
<< " user " << m_clock.GetElapsedUser () * 1e-3
<< " system " << m_clock.GetElapsedSystem () * 1e-3
*m_ofs << " <SuiteTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
<< " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
<< " system " << static_cast<double> (elapsedSys) / ticksPerSecond
<< "</SuiteTime>" << std::endl;
*m_ofs << "</TestSuite>" << std::endl;

View File

@@ -27,10 +27,7 @@
#include <list>
#include <limits>
#include <stdint.h>
#include "ns3/system-wall-clock-ms.h"
#include <sys/times.h>
//
// 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<TestCase *> TestCaseVector_t;
TestCaseVector_t m_tests;
};

View File

@@ -19,9 +19,7 @@
*/
#include "system-wall-clock-ms.h"
#include <sys/times.h>
#include <unistd.h>
#include <limits.h>
#include <sys/time.h>
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<double> (endTime - m_startTime) / ticksPerSecond;
m_elapsedUser = 1e3 * static_cast<double> (endTimes.tms_utime - m_startTimes.tms_utime) / ticksPerSecond;
m_elapsedSystem = 1e3 * static_cast<double> (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

View File

@@ -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