View | Details | Raw Unified | Return to bug 691
Collapse All | Expand All

(-)a/src/core/system-wall-clock-ms.h (-3 / +24 lines)
 Lines 25-30    Link Here 
25
25
26
/**
26
/**
27
 * \brief measure wall-clock time in milliseconds
27
 * \brief measure wall-clock time in milliseconds
28
29
 * \todo This class exists also in non-unix systems but is not
30
 * implemented and always return zero as measurd time.
28
 */
31
 */
29
class SystemWallClockMs {
32
class SystemWallClockMs {
30
public:
33
public:
 Lines 36-48    Link Here 
36
   */
39
   */
37
  void Start (void);
40
  void Start (void);
38
  /**
41
  /**
39
   * \returns the measured elapsed wall clock time since 
42
   * \brief Stop measuring the time since Start() was called.
40
   *          ns3::SystemWallClockMs::start was invoked.
43
   * \returns the measured elapsed wall clock time (in milliseconds) since 
44
   *          ns3::SystemWallClockMs::Start was invoked.
41
   *
45
   *
42
   * It is possible to start a new measurement with ns3::SystemWallClockMs::start
46
   * It is possible to start a new measurement with ns3::SystemWallClockMs::Start
43
   * after this method returns.
47
   * after this method returns.
44
   */
48
   */
45
  unsigned long long End (void);
49
  unsigned long long End (void);
50
51
  /**
52
   * \returns the measured elapsed wall clock time (in milliseconds) since 
53
   *          ns3::SystemWallClockMs::Start was invoked.
54
   */
55
  double GetElapsedReal (void) const;
56
  /**
57
   * \returns the measured elapsed 'user' wall clock time (in milliseconds) since 
58
   *          ns3::SystemWallClockMs::Start was invoked.
59
   */
60
  double GetElapsedUser (void) const;
61
  /**
62
   * \returns the measured elapsed 'system' wall clock time (in milliseconds) since 
63
   *          ns3::SystemWallClockMs::Start was invoked.
64
   */
65
  double GetElapsedSystem (void) const;
66
46
private:
67
private:
47
  class SystemWallClockMsPrivate *m_priv;
68
  class SystemWallClockMsPrivate *m_priv;
48
};
69
};
(-)a/src/core/test.cc (-26 / +12 lines)
 Lines 262-268    Link Here 
262
void
262
void
263
TestCase::DoReportStart  (void)
263
TestCase::DoReportStart  (void)
264
{
264
{
265
  m_startTime = times (&m_startTimes);
265
  m_clock.Start ();
266
266
267
  if (m_ofs == 0)
267
  if (m_ofs == 0)
268
    {
268
    {
 Lines 319-344    Link Here 
319
void
319
void
320
TestCase::DoReportEnd  (void)
320
TestCase::DoReportEnd  (void)
321
{
321
{
322
  static long ticksPerSecond = sysconf (_SC_CLK_TCK);
322
  m_clock.End ();
323
324
  if (m_ofs == 0)
323
  if (m_ofs == 0)
325
    {
324
    {
326
      return;
325
      return;
327
    }
326
    }
328
327
329
  struct tms endTimes;
330
  clock_t endTime = times (&endTimes);
331
332
  clock_t elapsed = endTime - m_startTime;
333
  clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
334
  clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
335
336
  (*m_ofs).precision (2);
328
  (*m_ofs).precision (2);
337
  *m_ofs << std::fixed;
329
  *m_ofs << std::fixed;
338
330
339
  *m_ofs << "    <CaseTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
331
  *m_ofs << "    <CaseTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
340
                             << " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
332
                             << " user " << m_clock.GetElapsedUser () * 1e-3
341
                             << " system " << static_cast<double> (elapsedSys) / ticksPerSecond
333
                             << " system " << m_clock.GetElapsedSystem () * 1e-3
342
         << "</CaseTime>" << std::endl;
334
         << "</CaseTime>" << std::endl;
343
335
344
  *m_ofs << "  </TestCase>" << std::endl;
336
  *m_ofs << "  </TestCase>" << std::endl;
 Lines 523-530    Link Here 
523
void
515
void
524
TestSuite::DoReportStart (void)
516
TestSuite::DoReportStart (void)
525
{
517
{
526
  m_startTime = times (&m_startTimes);
518
  m_clock.Start ();
527
519
  
528
  if (m_ofs == 0)
520
  if (m_ofs == 0)
529
    {
521
    {
530
      return;
522
      return;
 Lines 556-580    Link Here 
556
void
548
void
557
TestSuite::DoReportEnd (void)
549
TestSuite::DoReportEnd (void)
558
{
550
{
559
  static long ticksPerSecond = sysconf (_SC_CLK_TCK);
551
  m_clock.End ();
560
552
  
561
  if (m_ofs == 0)
553
  if (m_ofs == 0)
562
    {
554
    {
563
      return;
555
      return;
564
    }
556
    }
565
  struct tms endTimes;
566
  clock_t endTime = times (&endTimes);
567
568
  clock_t elapsed = endTime - m_startTime;
569
  clock_t elapsedUsr = endTimes.tms_utime - m_startTimes.tms_utime;
570
  clock_t elapsedSys = endTimes.tms_stime - m_startTimes.tms_stime;
571
557
572
  (*m_ofs).precision (2);
558
  (*m_ofs).precision (2);
573
  *m_ofs << std::fixed;
559
  *m_ofs << std::fixed;
574
560
575
  *m_ofs << "  <SuiteTime>" << "real " << static_cast<double> (elapsed) / ticksPerSecond
561
  *m_ofs << "  <SuiteTime>" << "real " << m_clock.GetElapsedReal () * 1e-3
576
                            << " user " << static_cast<double> (elapsedUsr) / ticksPerSecond
562
                            << " user " << m_clock.GetElapsedUser () * 1e-3
577
                            << " system " << static_cast<double> (elapsedSys) / ticksPerSecond
563
                            << " system " << m_clock.GetElapsedSystem () * 1e-3
578
         << "</SuiteTime>" << std::endl;
564
         << "</SuiteTime>" << std::endl;
579
565
580
  *m_ofs << "</TestSuite>" << std::endl;
566
  *m_ofs << "</TestSuite>" << std::endl;
(-)a/src/core/test.h (-7 / +7 lines)
 Lines 27-33    Link Here 
27
#include <list>
27
#include <list>
28
#include <limits>
28
#include <limits>
29
#include <stdint.h>
29
#include <stdint.h>
30
#include <sys/times.h>
30
31
#include "ns3/system-wall-clock-ms.h"
32
33
31
// 
34
// 
32
// Note on below macros:
35
// Note on below macros:
33
//
36
//
 Lines 821-826    Link Here 
821
  TestCase (TestCase& tc);
824
  TestCase (TestCase& tc);
822
  TestCase& operator= (TestCase& tc);
825
  TestCase& operator= (TestCase& tc);
823
826
827
  SystemWallClockMs m_clock;
824
  std::string m_name;
828
  std::string m_name;
825
  bool m_verbose;
829
  bool m_verbose;
826
  bool m_continueOnFailure;
830
  bool m_continueOnFailure;
 Lines 828-835    Link Here 
828
  std::string m_basedir;
832
  std::string m_basedir;
829
  std::ofstream *m_ofs;
833
  std::ofstream *m_ofs;
830
  bool m_error;
834
  bool m_error;
831
  clock_t m_startTime;
832
  struct tms m_startTimes;
833
};
835
};
834
836
835
/**
837
/**
 Lines 1057-1062    Link Here 
1057
  TestSuite (TestSuite& ts);
1059
  TestSuite (TestSuite& ts);
1058
  TestSuite& operator= (TestSuite& ts);
1060
  TestSuite& operator= (TestSuite& ts);
1059
1061
1062
  SystemWallClockMs m_clock;
1060
  std::string m_name;
1063
  std::string m_name;
1061
  bool m_verbose;
1064
  bool m_verbose;
1062
  bool m_continueOnFailure;
1065
  bool m_continueOnFailure;
 Lines 1064-1073    Link Here 
1064
  std::ofstream *m_ofs;
1067
  std::ofstream *m_ofs;
1065
  bool m_error;
1068
  bool m_error;
1066
  TestType m_type;
1069
  TestType m_type;
1067
1070
  
1068
  clock_t m_startTime;
1069
  struct tms m_startTimes;
1070
1071
  typedef std::vector<TestCase *> TestCaseVector_t;
1071
  typedef std::vector<TestCase *> TestCaseVector_t;
1072
  TestCaseVector_t m_tests;
1072
  TestCaseVector_t m_tests;
1073
};
1073
};
(-)a/src/core/unix-system-wall-clock-ms.cc (-10 / +59 lines)
 Lines 19-25    Link Here 
19
 */
19
 */
20
20
21
#include "system-wall-clock-ms.h"
21
#include "system-wall-clock-ms.h"
22
#include <sys/time.h>
22
#include <sys/times.h>
23
#include <unistd.h>
24
#include <limits.h>
23
25
24
namespace ns3 {
26
namespace ns3 {
25
27
 Lines 27-54    Link Here 
27
public:
29
public:
28
  void Start (void);
30
  void Start (void);
29
  unsigned long long End (void);
31
  unsigned long long End (void);
32
  double GetElapsedReal (void) const;
33
  double GetElapsedUser (void) const;
34
  double GetElapsedSystem (void) const;
35
30
private:
36
private:
31
  struct timeval m_startTv;
37
  struct tms m_startTimes;
32
  struct timeval m_endTv;
38
  clock_t m_startTime;
39
  double m_elapsedReal;
40
  double m_elapsedUser;
41
  double m_elapsedSystem;
33
};
42
};
34
43
35
void 
44
void 
36
SystemWallClockMsPrivate::Start (void)
45
SystemWallClockMsPrivate::Start (void)
37
{
46
{
38
  struct timezone tz;
47
  m_startTime = times (&m_startTimes);
39
  gettimeofday (&m_startTv, &tz);
40
}
48
}
41
49
42
unsigned long long 
50
unsigned long long 
43
SystemWallClockMsPrivate::End (void)
51
SystemWallClockMsPrivate::End (void)
44
{
52
{
45
  struct timezone tz;
53
  static long ticksPerSecond = sysconf (_SC_CLK_TCK);
46
  gettimeofday (&m_endTv, &tz);
54
47
  unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
55
  struct tms endTimes;
48
  unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
56
  clock_t endTime = times (&endTimes);
49
  return end - start;
57
58
  m_elapsedReal = 1e3 * static_cast<double> (endTime - m_startTime) / ticksPerSecond;
59
  m_elapsedUser = 1e3 * static_cast<double> (endTimes.tms_utime - m_startTimes.tms_utime) / ticksPerSecond;
60
  m_elapsedSystem = 1e3 * static_cast<double> (endTimes.tms_stime - m_startTimes.tms_stime) / ticksPerSecond;
61
62
  return m_elapsedReal;
50
}
63
}
51
64
65
double
66
SystemWallClockMsPrivate::GetElapsedReal (void) const
67
{
68
  return m_elapsedReal;
69
}
70
71
double
72
SystemWallClockMsPrivate::GetElapsedUser (void) const
73
{
74
  return m_elapsedUser;
75
}
76
77
double
78
SystemWallClockMsPrivate::GetElapsedSystem (void) const
79
{
80
  return m_elapsedSystem;
81
}
82
  
52
SystemWallClockMs::SystemWallClockMs ()
83
SystemWallClockMs::SystemWallClockMs ()
53
  : m_priv (new SystemWallClockMsPrivate ())
84
  : m_priv (new SystemWallClockMsPrivate ())
54
{}
85
{}
 Lines 70-73    Link Here 
70
  return m_priv->End ();
101
  return m_priv->End ();
71
}
102
}
72
103
104
double
105
SystemWallClockMs::GetElapsedReal (void) const
106
{
107
  return m_priv->GetElapsedReal ();
108
}
109
110
double
111
SystemWallClockMs::GetElapsedUser (void) const
112
{
113
  return m_priv->GetElapsedUser ();
114
}
115
116
double
117
SystemWallClockMs::GetElapsedSystem (void) const
118
{
119
  return m_priv->GetElapsedSystem ();
120
}
121
73
}; // namespace ns3
122
}; // namespace ns3
(-)a/src/core/win32-system-wall-clock-ms.cc (+18 lines)
 Lines 61-64    Link Here 
61
  return m_priv->End ();
61
  return m_priv->End ();
62
}
62
}
63
63
64
double
65
SystemWallClockMs::GetElapsedReal (void) const
66
{
67
  return 0;
68
}
69
70
double
71
SystemWallClockMs::GetElapsedUser (void) const
72
{
73
  return 0;
74
}
75
76
double
77
SystemWallClockMs::GetElapsedSystem (void) const
78
{
79
  return 0;
80
}
81
64
}; // namespace ns3
82
}; // namespace ns3

Return to bug 691