00001 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2005 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage.inria.fr> 00019 */ 00020 00021 #include "system-wall-clock-ms.h" 00022 #include <sys/time.h> 00023 00024 namespace ns3 { 00025 00026 class SystemWallClockMsPrivate { 00027 public: 00028 void Start (void); 00029 unsigned long long End (void); 00030 private: 00031 struct timeval m_startTv; 00032 struct timeval m_endTv; 00033 }; 00034 00035 void 00036 SystemWallClockMsPrivate::Start (void) 00037 { 00038 struct timezone tz; 00039 gettimeofday (&m_startTv, &tz); 00040 } 00041 00042 unsigned long long 00043 SystemWallClockMsPrivate::End (void) 00044 { 00045 struct timezone tz; 00046 gettimeofday (&m_endTv, &tz); 00047 unsigned long long end = m_endTv.tv_sec *1000 + m_endTv.tv_usec / 1000; 00048 unsigned long long start = m_startTv.tv_sec *1000 + m_startTv.tv_usec / 1000; 00049 return end - start; 00050 } 00051 00052 SystemWallClockMs::SystemWallClockMs () 00053 : m_priv (new SystemWallClockMsPrivate ()) 00054 {} 00055 00056 SystemWallClockMs::~SystemWallClockMs () 00057 { 00058 delete m_priv; 00059 m_priv = 0; 00060 } 00061 00062 void 00063 SystemWallClockMs::Start (void) 00064 { 00065 m_priv->Start (); 00066 } 00067 unsigned long long 00068 SystemWallClockMs::End (void) 00069 { 00070 return m_priv->End (); 00071 } 00072 00073 }; // namespace ns3