bug 252: get rid of dead code.
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 28 Jul 2008 08:54:20 -0700
changeset 3489 b5ef00370c70
parent 3488 517acaf61a69
child 3490 973e8f700e58
bug 252: get rid of dead code.
src/simulator/default-simulator-impl.cc
src/simulator/default-simulator-impl.h
src/simulator/simulator-impl.h
src/simulator/simulator.cc
src/simulator/simulator.h
utils/bench-simulator.cc
utils/replay-simulation.cc
utils/wscript
--- a/src/simulator/default-simulator-impl.cc	Mon Jul 28 08:30:32 2008 -0700
+++ b/src/simulator/default-simulator-impl.cc	Mon Jul 28 08:54:20 2008 -0700
@@ -57,7 +57,6 @@
   m_uid = 4; 
   // before ::Run is entered, the m_currentUid will be zero
   m_currentUid = 0;
-  m_logEnable = false;
   m_currentTs = 0;
   m_unscheduledEvents = 0;
 }
@@ -106,12 +105,6 @@
   return m_events;
 }
 
-void
-DefaultSimulatorImpl::EnableLogTo (char const *filename)
-{
-  m_log.open (filename);
-  m_logEnable = true;
-}
 
 void
 DefaultSimulatorImpl::ProcessOneEvent (void)
@@ -124,10 +117,6 @@
   NS_LOG_LOGIC ("handle " << next.GetTs ());
   m_currentTs = next.GetTs ();
   m_currentUid = next.GetUid ();
-  if (m_logEnable) 
-    {
-      m_log << "e "<<next.GetUid () << " " << next.GetTs () << std::endl;
-    }
   EventImpl *event = next.PeekEventImpl ();
   event->Invoke ();
 }
@@ -190,11 +179,6 @@
   NS_ASSERT (time >= TimeStep (m_currentTs));
   uint64_t ts = (uint64_t) time.GetTimeStep ();
   EventId id (event, ts, m_uid);
-  if (m_logEnable) 
-    {
-      m_log << "i "<<m_currentUid<<" "<<m_currentTs<<" "
-            <<m_uid<<" "<<time.GetTimeStep () << std::endl;
-    }
   m_uid++;
   ++m_unscheduledEvents;
   m_events->Insert (id);
@@ -205,11 +189,6 @@
 DefaultSimulatorImpl::ScheduleNow (const Ptr<EventImpl> &event)
 {
   EventId id (event, m_currentTs, m_uid);
-  if (m_logEnable) 
-    {
-      m_log << "i "<<m_currentUid<<" "<<m_currentTs<<" "
-            <<m_uid<<" "<<m_currentTs << std::endl;
-    }
   m_uid++;
   ++m_unscheduledEvents;
   m_events->Insert (id);
@@ -221,11 +200,6 @@
 {
   EventId id (event, m_currentTs, 2);
   m_destroyEvents.push_back (id);
-  if (m_logEnable) 
-  {
-    m_log << "id " << m_currentUid << " " << Now ().GetTimeStep () << " "
-          << m_uid << std::endl;
-  }
   m_uid++;
   return id;
 }
@@ -272,11 +246,6 @@
   m_events->Remove (ev);
   Cancel (ev);
 
-  if (m_logEnable) 
-    {
-      m_log << "r " << m_currentUid << " " << m_currentTs << " "
-            << ev.GetUid () << " " << ev.GetTs () << std::endl;
-    }
   --m_unscheduledEvents;
 }
 
--- a/src/simulator/default-simulator-impl.h	Mon Jul 28 08:30:32 2008 -0700
+++ b/src/simulator/default-simulator-impl.h	Mon Jul 28 08:54:20 2008 -0700
@@ -45,8 +45,6 @@
 
   void Destroy ();
 
-  void EnableLogTo (char const *filename);
-
   bool IsFinished (void) const;
   Time Next (void) const;
   void Stop (void);
--- a/src/simulator/simulator-impl.h	Mon Jul 28 08:30:32 2008 -0700
+++ b/src/simulator/simulator-impl.h	Mon Jul 28 08:54:20 2008 -0700
@@ -38,7 +38,6 @@
 {
 public:
   virtual void Destroy () = 0;
-  virtual void EnableLogTo (char const *filename) = 0;
   virtual bool IsFinished (void) const = 0;
   virtual Time Next (void) const = 0;
   virtual void Stop (void) = 0;
--- a/src/simulator/simulator.cc	Mon Jul 28 08:30:32 2008 -0700
+++ b/src/simulator/simulator.cc	Mon Jul 28 08:54:20 2008 -0700
@@ -122,10 +122,7 @@
 
 void 
 Simulator::EnableLogTo (char const *filename)
-{
-  NS_LOG_FUNCTION (filename);
-  GetImpl ()->EnableLogTo (filename);
-}
+{}
 
 bool 
 Simulator::IsFinished (void)
--- a/src/simulator/simulator.h	Mon Jul 28 08:30:32 2008 -0700
+++ b/src/simulator/simulator.h	Mon Jul 28 08:54:20 2008 -0700
@@ -27,6 +27,7 @@
 #include "scheduler.h"
 
 #include "ns3/type-traits.h"
+#include "ns3/deprecated.h"
 
 #include <stdint.h>
 #include <string>
@@ -79,20 +80,7 @@
    */
   static void SetScheduler (Ptr<Scheduler> scheduler);
 
-  /**
-   * Enable logging to the file identified by filename. If the file
-   * does not exist, it is created. If it exists, it is destroyed and
-   * re-created. Every scheduling event is logged to this file in a
-   * simple text format which can be read back by the event replay
-   * utility. This allows you to record the scheduling behavior of
-   * a simulation, and measure the exact overhead related to
-   * event scheduling with the event replay utility. It is also possible
-   * to compare the performance of every scheduling algorithms on this
-   * specific scheduling load.
-   * This method must be invoked before any call to Simulator::run
-   * @param filename the name of the file to log to 
-   */
-  static void EnableLogTo (char const *filename);
+  static void EnableLogTo (char const *filename) NS_DEPRECATED;
 
   /**
    * Every event scheduled by the Simulator::insertAtDestroy method is
--- a/utils/bench-simulator.cc	Mon Jul 28 08:30:32 2008 -0700
+++ b/utils/bench-simulator.cc	Mon Jul 28 08:54:20 2008 -0700
@@ -130,7 +130,6 @@
   std::cout << "      --list: use std::list scheduler"<<std::endl;
   std::cout << "      --map: use std::map cheduler"<<std::endl;
   std::cout << "      --heap: use Binary Heap scheduler"<<std::endl;
-  std::cout << "      --log=filename: log scheduler events for the event replay utility."<<std::endl;
   std::cout << "      --debug: enable some debugging"<<std::endl;
 }
 
@@ -173,11 +172,6 @@
         {
           g_debug = true;
         } 
-      else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) 
-        {
-          char const *filename = argv[0] + strlen ("--log=");
-          Simulator::EnableLogTo (filename);
-        }
       else if (strncmp ("--total=", argv[0], strlen("--total=")) == 0) 
         {
           total = atoi (argv[0]+strlen ("--total="));
--- a/utils/replay-simulation.cc	Mon Jul 28 08:30:32 2008 -0700
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,330 +0,0 @@
-/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
-/*
- * Copyright (c) 2006 INRIA
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation;
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
- */
-
-#include "ns3/simulator-module.h"
-#include "ns3/core-module.h"
-#include <vector>
-#include <deque>
-#include <fstream>
-#include <iostream>
-#include <string.h>
-
-using namespace ns3;
-
-class LogReader {
-public:
-  void ReadFromFilename (char const *filename);
-  void Run (void);
-  void PrintStats (void);
-private:
-  struct Command {
-      enum {
-          REMOVE = 100,
-          INSERT,
-          INSERT_LATER,
-          INSERT_REMOVE
-      } m_type;
-      // uid at which this command is supposed to be executed.
-      uint32_t m_uid;
-      union {
-          struct {
-            // time at which the event is supposed to expire
-            uint64_t m_evNs;
-            uint32_t m_evUid;
-          } insert;
-          struct {
-            // location in the array of events to remove where
-            // to insert this event once it is inserted in 
-            // the scheduler.
-            uint32_t m_evLoc; 
-            // time at which the event is supposed to expire
-            uint64_t m_evNs;
-          } insertRemove;
-      };
-  };
-  void ExecuteLogCommands (uint32_t uid);
-
-  typedef std::vector<struct Command> Commands;
-  typedef std::vector<struct Command>::iterator CommandsI;
-  typedef std::vector<EventId> RemoveEvents;
-  typedef std::vector<EventId>::iterator RemoveEventsI;
-  
-
-  Commands m_commands;
-  CommandsI m_command;
-  RemoveEvents m_removeEvents;
-  uint32_t m_uid;
-};
-
-typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
-typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI;
-
-void
-LogReader::ReadFromFilename (char const *filename)
-{
-  std::ifstream log;
-  std::cout << "read log..." << std::endl;
-  Removes removes;
-  log.open (filename);
-  while (!log.eof ()) 
-    {
-      std::string type;
-      log >> type;
-      if (type == "i") 
-        {
-          uint32_t nowUid, evUid;
-          uint64_t nowNs, evNs;
-          log >> nowUid >> nowNs >> evUid >> evNs;
-          struct Command cmd;
-          cmd.m_type = Command::INSERT;
-          cmd.m_uid = nowUid;
-          cmd.insert.m_evNs = evNs;
-          cmd.insert.m_evUid = evUid;
-          m_commands.push_back (cmd);
-        } 
-      else if (type == "r") 
-        {
-          uint32_t nowUid, evUid;
-          uint64_t nowNs, evNs;
-          log >> nowUid >> nowNs >> evUid >> evNs;
-          struct Command cmd;
-          cmd.m_type = Command::REMOVE;
-          cmd.m_uid = nowUid;
-          m_commands.push_back (cmd);
-          removes.push_back (std::make_pair (nowUid, evUid));
-        } 
-      else if (type == "il") 
-        {
-          uint32_t nowUid, evUid;
-          uint64_t nowNs, evNs;
-          log >> nowUid >> nowNs >> evUid >> evNs;
-          struct Command cmd;
-          cmd.m_type = Command::INSERT_LATER;
-          cmd.m_uid = nowUid;
-          m_commands.push_back (cmd);
-        }
-    }
-  log.close ();
-
-  std::cout << "gather insert/removes, commands="<<m_commands.size () 
-            << ", removes=" << removes.size () << "..." << std::endl;
-  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
-    {
-      if (i->m_type == Command::INSERT) 
-        {
-          for (RemovesI j = removes.begin (); j != removes.end (); j++) 
-            {
-              if (j->second == i->insert.m_evUid) 
-                {
-                  // this insert will be removed later.
-                  uint64_t ns = i->insert.m_evNs;
-                  uint32_t uid = i->m_uid;
-                  i->m_type = Command::INSERT_REMOVE;
-                  i->m_uid = uid;
-                  i->insertRemove.m_evNs = ns;
-                  i->insertRemove.m_evLoc = j->first;
-                  break;
-                }
-            }
-        }
-    }
-  std::cout << "calculate remove locations..." << std::endl;
-  // calculate the final insert/remove location.
-  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
-    {
-      if (i->m_type == Command::INSERT_REMOVE) 
-        {
-          uint32_t loc = 0;
-          for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) 
-            {
-              if (tmp->m_type == Command::REMOVE) 
-                {
-                  if (tmp->m_uid == i->insertRemove.m_evLoc) 
-                    {
-                      i->insertRemove.m_evLoc = loc;
-                      break;
-                    }
-                  loc++;
-                }
-            }
-        }
-    }
-}
-void
-LogReader::ExecuteLogCommands (uint32_t uid)
-{
-  if (m_command == m_commands.end ()) 
-    {
-      return;
-    }
-  //std::cout << "one event, uid=" <<m_uid<< std::endl;
-  struct Command cmd = *m_command;
-  //std::cout << "cmd uid=" <<cmd.m_uid<< std::endl;
-  while (cmd.m_uid == uid) 
-    {
-      m_command++;
-      switch (cmd.m_type) {
-      case Command::INSERT:
-        //std::Cout << "exec insert now=" << Simulator::Now ().GetNanoSeconds ()
-        //<< ", time=" << cmd.insert.m_evNs << std::endl;
-        Simulator::Schedule (NanoSeconds (cmd.insert.m_evNs) - Now (), 
-                             &LogReader::ExecuteLogCommands, this, m_uid);
-        m_uid++;
-        break;
-      case Command::INSERT_LATER:
-          //std::cout << "exec insert later" << std::endl;
-          Simulator::ScheduleNow (&LogReader::ExecuteLogCommands, this, m_uid);
-          m_uid++;
-          break;
-      case Command::REMOVE: 
-        {
-          //std::cout << "exec remove" << std::endl;
-          EventId id = m_removeEvents.back ();
-          m_removeEvents.pop_back ();
-          Simulator::Remove (id);
-        } break;
-      case Command::INSERT_REMOVE: 
-        {
-          //std::cout << "exec insert remove" << std::endl;
-          EventId id = Simulator::Schedule (NanoSeconds (cmd.insertRemove.m_evNs) - Now (),
-                                            &LogReader::ExecuteLogCommands, this, m_uid);
-          NS_ASSERT (id.GetUid () == m_uid);
-          if (cmd.insertRemove.m_evLoc + 1 > m_removeEvents.size ())
-            {
-              uint32_t missing = cmd.insertRemove.m_evLoc + 1 - m_removeEvents.size ();
-              m_removeEvents.insert (m_removeEvents.begin (),
-                                     missing, id);
-            }
-          uint32_t index = m_removeEvents.size () - cmd.insertRemove.m_evLoc - 1;
-          m_removeEvents[index] = id;
-          m_uid++;
-        } break;
-      default:
-        NS_ASSERT (false);
-        break;
-      }
-      cmd = *m_command;
-  }
-}
-
-void
-LogReader::PrintStats (void)
-{
-  uint32_t nInserts = 0;
-  uint32_t nRemoves = 0;
-  for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) 
-    {
-      switch (i->m_type) {
-      case Command::INSERT:
-          nInserts++;
-          break;
-      case Command::INSERT_LATER:
-          nInserts++;
-          break;
-      case Command::INSERT_REMOVE:
-          nInserts++;
-          break;
-      case Command::REMOVE:
-          nRemoves++;
-          break;
-      }
-    }
-  std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl;
-  std::cout << "run simulation..."<<std::endl;
-}
-
-void
-LogReader::Run (void)
-{
-  m_uid = 1;
-  SystemWallClockMs time;
-  time.Start ();
-  m_command = m_commands.begin ();
-  ExecuteLogCommands (0);
-  Simulator::Run ();
-  unsigned long long delta = time.End ();
-  double delay = ((double)delta)/1000;
-  std::cout << "runtime="<<delay<<"s"<<std::endl;
-}
-
-
-int main (int argc, char *argv[])
-{
-  char const *input = 0;
-  uint32_t n = 1;
-  bool is_map = false;
-  bool is_list = false;
-  bool is_heap = false;
-  while (argc > 0) 
-    {
-      if (strcmp ("--list", argv[0]) == 0) 
-        {
-          is_list = true;
-        } 
-      else if (strcmp ("--heap", argv[0]) == 0) 
-        {
-          is_heap = true;
-        } 
-      else if (strcmp ("--map", argv[0]) == 0) 
-        {
-          is_map = true;
-        } 
-      else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) 
-        {
-          n = atoi (argv[0]+strlen ("--n="));
-        } 
-      else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) 
-        {
-          input = argv[0] + strlen ("--input=");
-        } 
-      else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) 
-        {
-          char const *filename = argv[0] + strlen ("--log=");
-          Simulator::EnableLogTo (filename);
-        }
-      argc--;
-      argv++;
-    }
-  if (input == 0) 
-    {
-      std::cerr << "need --input=[filename] option" << std::endl;
-      return 1;
-    }
-  LogReader log;
-  log.ReadFromFilename (input);
-  std::cout << "start runs..." << std::endl;
-  for (uint32_t i = 0; i < n; i++) 
-    {
-      if (is_map)
-        {
-          Simulator::SetScheduler (CreateObject<MapScheduler> ());
-        }
-      else if (is_list)
-        {
-          Simulator::SetScheduler (CreateObject<ListScheduler> ());
-        }
-      else if (is_heap)
-        {
-          Simulator::SetScheduler (CreateObject<HeapScheduler> ());
-        }
-      log.Run ();
-      Simulator::Destroy ();
-    }
-}
--- a/utils/wscript	Mon Jul 28 08:30:32 2008 -0700
+++ b/utils/wscript	Mon Jul 28 08:54:20 2008 -0700
@@ -24,9 +24,6 @@
     obj = bld.create_ns3_program('bench-packets', ['common'])
     obj.source = 'bench-packets.cc'
 
-    obj = bld.create_ns3_program('replay-simulation', ['simulator'])
-    obj.source = 'replay-simulation.cc'
-
     obj = bld.create_ns3_program('print-introspected-doxygen',
                                  ['internet-stack', 'csma-cd', 'point-to-point'])
     obj.source = 'print-introspected-doxygen.cc'