utils/bench-simulator.cc
author Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
Thu, 13 Mar 2008 12:56:49 -0700
changeset 2602 d9262bff6df2
parent 2559 ab98bf436a17
child 2834 1aab57845b07
permissions -rw-r--r--
add back support for introspected doxygen.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     2
/*
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     3
 * Copyright (c) 2006 INRIA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     4
 * All rights reserved.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     5
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License version 2 as
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     8
 * published by the Free Software Foundation;
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
     9
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    13
 * GNU General Public License for more details.
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    14
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    16
 * along with this program; if not, write to the Free Software
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    18
 *
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    19
 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    20
 */
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    21
14
6dd7d31c6fc3 replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 12
diff changeset
    22
#include "ns3/simulator.h"
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
    23
#include "ns3/scheduler-list.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
    24
#include "ns3/scheduler-map.h"
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
    25
#include "ns3/scheduler-heap.h"
34
f2aa05303e7c remove more unused files, rename system files
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 25
diff changeset
    26
#include "ns3/system-wall-clock-ms.h"
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    27
#include <iostream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    28
#include <fstream>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    29
#include <vector>
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    30
16
99e833adbb46 change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 14
diff changeset
    31
using namespace ns3;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    32
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    33
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    34
bool g_debug = false;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    35
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    36
class Bench 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    37
{
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    38
public:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    39
  void ReadDistribution (std::istream &istream);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    40
  void SetTotal (uint32_t total);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    41
  void RunBench (void);
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    42
private:
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    43
  void Cb (void);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    44
  std::vector<uint64_t> m_distribution;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    45
  std::vector<uint64_t>::const_iterator m_current;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    46
  uint32_t m_n;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    47
  uint32_t m_total;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    48
};
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    49
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    50
void 
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
    51
Bench::SetTotal (uint32_t total)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    52
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    53
  m_total = total;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    54
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    55
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    56
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
    57
Bench::ReadDistribution (std::istream &input)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    58
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    59
  double data;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    60
  while (!input.eof ()) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    61
    {
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    62
      if (input >> data) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    63
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    64
          uint64_t ns = (uint64_t) (data * 1000000000);
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    65
          m_distribution.push_back (ns);
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    66
        } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    67
      else 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    68
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    69
          input.clear ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    70
          std::string line;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    71
          input >> line;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    72
        }
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    73
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    74
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    75
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    76
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
    77
Bench::RunBench (void) 
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    78
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    79
  SystemWallClockMs time;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    80
  double init, simu;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    81
  time.Start ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    82
  for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    83
       i != m_distribution.end (); i++) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    84
    {
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
    85
      Simulator::Schedule (NanoSeconds (*i), &Bench::Cb, this);
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
    86
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    87
  init = time.End ();
204
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
    88
  init /= 1000;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    89
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    90
  m_current = m_distribution.begin ();
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    91
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    92
  time.Start ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    93
  Simulator::Run ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    94
  simu = time.End ();
204
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
    95
  simu /= 1000;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
    96
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    97
  std::cout <<
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    98
      "init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
    99
      "simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   100
      "init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   101
      init / ((double)m_distribution.size ())<< "s" << std::endl <<
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   102
      "simu " << ((double)m_n) / simu<< " hold/s, avg hold=" << 
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   103
      simu / ((double)m_n) << "s" << std::endl
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   104
      ;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   105
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   106
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   107
void
122
6b8f1eda5c57 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 110
diff changeset
   108
Bench::Cb (void)
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   109
{
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   110
  if (m_n > m_total) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   111
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   112
      return;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   113
    }
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   114
  if (m_current == m_distribution.end ()) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   115
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   116
      m_current = m_distribution.begin ();
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   117
    }
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   118
  if (g_debug) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   119
    {
163
2a7e05018eeb rename Time::ApproximateTo methods to Time::Get
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 162
diff changeset
   120
      std::cerr << "event at " << Simulator::Now ().GetSeconds () << "s" << std::endl;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   121
    }
162
5b398ac221c7 make Time relative instead of Absolute
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 150
diff changeset
   122
  Simulator::Schedule (NanoSeconds (*m_current), &Bench::Cb, this);
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   123
  m_current++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   124
  m_n++;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   125
}
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   126
189
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   127
void
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   128
PrintHelp (void)
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   129
{
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   130
  std::cout << "bench-simulator filename [options]"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   131
  std::cout << "  filename: a string which identifies the input distribution. \"-\" represents stdin." << std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   132
  std::cout << "  Options:"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   133
  std::cout << "      --list: use std::list scheduler"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   134
  std::cout << "      --map: use std::map cheduler"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   135
  std::cout << "      --heap: use Binary Heap scheduler"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   136
  std::cout << "      --log=filename: log scheduler events for the event replay utility."<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   137
  std::cout << "      --debug: enable some debugging"<<std::endl;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   138
}
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   139
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   140
int main (int argc, char *argv[])
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   141
{
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   142
  char const *filename = argv[1];
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   143
  std::istream *input;
204
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   144
  uint32_t n = 1;
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   145
  uint32_t total = 20000;
189
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   146
  if (argc == 1)
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   147
    {
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   148
      PrintHelp ();
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   149
      return 0;
fcfc2247da10 add help output to simulator bench/tester
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 163
diff changeset
   150
    }
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   151
  argc-=2;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   152
  argv+= 2;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   153
  if (strcmp (filename, "-") == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   154
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   155
      input = &std::cin;
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   156
    } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   157
  else 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   158
    {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   159
      input = new std::ifstream (filename);
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   160
    }
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   161
  while (argc > 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   162
    {
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   163
      if (strcmp ("--list", argv[0]) == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   164
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
   165
          Simulator::SetScheduler (CreateObject<SchedulerList> ());
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   166
        } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   167
      else if (strcmp ("--heap", argv[0]) == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   168
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
   169
          Simulator::SetScheduler (CreateObject<SchedulerHeap> ());
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   170
        } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   171
      else if (strcmp ("--map", argv[0]) == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   172
        {
2559
ab98bf436a17 do not use DefaultValues in simulator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 204
diff changeset
   173
          Simulator::SetScheduler (CreateObject<SchedulerMap> ());
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   174
        } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   175
      else if (strcmp ("--debug", argv[0]) == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   176
        {
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   177
          g_debug = true;
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   178
        } 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   179
      else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) 
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   180
        {
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   181
          char const *filename = argv[0] + strlen ("--log=");
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   182
          Simulator::EnableLogTo (filename);
190
916cd1bfed82 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 189
diff changeset
   183
        }
204
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   184
      else if (strncmp ("--total=", argv[0], strlen("--total=")) == 0) 
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   185
        {
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   186
          total = atoi (argv[0]+strlen ("--total="));
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   187
        } 
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   188
      else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) 
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   189
        {
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   190
          n = atoi (argv[0]+strlen ("--n="));
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   191
        } 
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   192
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   193
      argc--;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   194
      argv++;
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   195
  }
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   196
  Bench *bench = new Bench ();
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   197
  bench->ReadDistribution (*input);
204
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   198
  bench->SetTotal (total);
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   199
  for (uint32_t i = 0; i < n; i++)
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   200
    {
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   201
      bench->RunBench ();
d387497c6bfa add command-line options to simulator benchmark
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 190
diff changeset
   202
    }
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   203
150
663120712cd9 fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 143
diff changeset
   204
  return 0;
12
917ba023c576 utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff changeset
   205
}