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