src/core/unix-system-wall-clock-ms.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Sat, 04 Jul 2009 08:15:48 +0200
changeset 4654 2eaebe77d66b
parent 150 663120712cd9
permissions -rw-r--r--
Added tag ns-3.5 for changeset c975274c9707
mathieu@150
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
mathieu@9
     2
/*
mathieu@9
     3
 * Copyright (c) 2005 INRIA
mathieu@9
     4
 *
mathieu@9
     5
 * This program is free software; you can redistribute it and/or modify
mathieu@9
     6
 * it under the terms of the GNU General Public License version 2 as
mathieu@9
     7
 * published by the Free Software Foundation;
mathieu@9
     8
 *
mathieu@9
     9
 * This program is distributed in the hope that it will be useful,
mathieu@9
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
mathieu@9
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
mathieu@9
    12
 * GNU General Public License for more details.
mathieu@9
    13
 *
mathieu@9
    14
 * You should have received a copy of the GNU General Public License
mathieu@9
    15
 * along with this program; if not, write to the Free Software
mathieu@9
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
mathieu@9
    17
 *
mathieu@9
    18
 * Author: Mathieu Lacage <mathieu.lacage.inria.fr>
mathieu@9
    19
 */
mathieu@9
    20
mathieu@34
    21
#include "system-wall-clock-ms.h"
mathieu@9
    22
#include <sys/time.h>
mathieu@9
    23
mathieu@16
    24
namespace ns3 {
mathieu@9
    25
mathieu@34
    26
class SystemWallClockMsPrivate {
mathieu@9
    27
public:
mathieu@150
    28
  void Start (void);
mathieu@150
    29
  unsigned long long End (void);
mathieu@9
    30
private:
mathieu@150
    31
  struct timeval m_startTv;
mathieu@150
    32
  struct timeval m_endTv;
mathieu@9
    33
};
mathieu@9
    34
mathieu@9
    35
void 
mathieu@122
    36
SystemWallClockMsPrivate::Start (void)
mathieu@9
    37
{
mathieu@150
    38
  struct timezone tz;
mathieu@150
    39
  gettimeofday (&m_startTv, &tz);
mathieu@9
    40
}
mathieu@9
    41
mathieu@9
    42
unsigned long long 
mathieu@122
    43
SystemWallClockMsPrivate::End (void)
mathieu@9
    44
{
mathieu@150
    45
  struct timezone tz;
mathieu@150
    46
  gettimeofday (&m_endTv, &tz);
mathieu@150
    47
  unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000;
mathieu@150
    48
  unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000;
mathieu@150
    49
  return end - start;
mathieu@9
    50
}
mathieu@9
    51
mathieu@34
    52
SystemWallClockMs::SystemWallClockMs ()
mathieu@150
    53
  : m_priv (new SystemWallClockMsPrivate ())
mathieu@9
    54
{}
mathieu@9
    55
mathieu@34
    56
SystemWallClockMs::~SystemWallClockMs ()
mathieu@9
    57
{
mathieu@150
    58
  delete m_priv;
mathieu@150
    59
  m_priv = 0;
mathieu@9
    60
}
mathieu@9
    61
mathieu@9
    62
void
mathieu@122
    63
SystemWallClockMs::Start (void)
mathieu@9
    64
{
mathieu@150
    65
  m_priv->Start ();
mathieu@9
    66
}
mathieu@9
    67
unsigned long long
mathieu@122
    68
SystemWallClockMs::End (void)
mathieu@9
    69
{
mathieu@150
    70
  return m_priv->End ();
mathieu@9
    71
}
mathieu@9
    72
mathieu@16
    73
}; // namespace ns3