author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 29 Aug 2007 16:42:55 +0200 | |
changeset 1396 | 105d16b9bf04 |
parent 286 | 57e6a2006962 |
child 2559 | ab98bf436a17 |
permissions | -rw-r--r-- |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
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" |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
23 |
#include "ns3/nstime.h" |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
24 |
#include "ns3/system-wall-clock-ms.h" |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include <vector> |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
26 |
#include <deque> |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
27 |
#include <fstream> |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
#include <iostream> |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
29 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
30 |
using namespace ns3; |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
31 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
class LogReader { |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
public: |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
34 |
void ReadFromFilename (char const *filename); |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
35 |
void Run (void); |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
36 |
void PrintStats (void); |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
37 |
private: |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
38 |
struct Command { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
39 |
enum { |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
40 |
REMOVE = 100, |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
41 |
INSERT, |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
42 |
INSERT_LATER, |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
43 |
INSERT_REMOVE |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
44 |
} m_type; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
45 |
// uid at which this command is supposed to be executed. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
46 |
uint32_t m_uid; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
47 |
union { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
48 |
struct { |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
49 |
// time at which the event is supposed to expire |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
50 |
uint64_t m_evNs; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
51 |
uint32_t m_evUid; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
52 |
} insert; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
53 |
struct { |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
54 |
// location in the array of events to remove where |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
55 |
// to insert this event once it is inserted in |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
56 |
// the scheduler. |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
57 |
uint32_t m_evLoc; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
58 |
// time at which the event is supposed to expire |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
59 |
uint64_t m_evNs; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
60 |
} insertRemove; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
61 |
}; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
62 |
}; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
63 |
void ExecuteLogCommands (uint32_t uid); |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
64 |
|
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
65 |
typedef std::vector<struct Command> Commands; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
66 |
typedef std::vector<struct Command>::iterator CommandsI; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
67 |
typedef std::vector<EventId> RemoveEvents; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
68 |
typedef std::vector<EventId>::iterator RemoveEventsI; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
69 |
|
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
70 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
71 |
Commands m_commands; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
72 |
CommandsI m_command; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
73 |
RemoveEvents m_removeEvents; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
74 |
uint32_t m_uid; |
12
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 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes; |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
78 |
typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI; |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
void |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
81 |
LogReader::ReadFromFilename (char const *filename) |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
82 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
83 |
std::ifstream log; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
84 |
std::cout << "read log..." << std::endl; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
85 |
Removes removes; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
86 |
log.open (filename); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
87 |
while (!log.eof ()) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
88 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
89 |
std::string type; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
90 |
log >> type; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
91 |
if (type == "i") |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
92 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
93 |
uint32_t nowUid, evUid; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
94 |
uint64_t nowNs, evNs; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
95 |
log >> nowUid >> nowNs >> evUid >> evNs; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
96 |
struct Command cmd; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
97 |
cmd.m_type = Command::INSERT; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
98 |
cmd.m_uid = nowUid; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
99 |
cmd.insert.m_evNs = evNs; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
100 |
cmd.insert.m_evUid = evUid; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
101 |
m_commands.push_back (cmd); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
102 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
103 |
else if (type == "r") |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
104 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
105 |
uint32_t nowUid, evUid; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
106 |
uint64_t nowNs, evNs; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
107 |
log >> nowUid >> nowNs >> evUid >> evNs; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
108 |
struct Command cmd; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
109 |
cmd.m_type = Command::REMOVE; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
110 |
cmd.m_uid = nowUid; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
111 |
m_commands.push_back (cmd); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
112 |
removes.push_back (std::make_pair (nowUid, evUid)); |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
113 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
114 |
else if (type == "il") |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
115 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
116 |
uint32_t nowUid, evUid; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
117 |
uint64_t nowNs, evNs; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
118 |
log >> nowUid >> nowNs >> evUid >> evNs; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
119 |
struct Command cmd; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
120 |
cmd.m_type = Command::INSERT_LATER; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
121 |
cmd.m_uid = nowUid; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
122 |
m_commands.push_back (cmd); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
123 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
124 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
125 |
log.close (); |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
126 |
|
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
127 |
std::cout << "gather insert/removes, commands="<<m_commands.size () |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
128 |
<< ", removes=" << removes.size () << "..." << std::endl; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
129 |
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
130 |
{ |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
131 |
if (i->m_type == Command::INSERT) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
132 |
{ |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
133 |
for (RemovesI j = removes.begin (); j != removes.end (); j++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
134 |
{ |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
135 |
if (j->second == i->insert.m_evUid) |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
136 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
137 |
// this insert will be removed later. |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
138 |
uint64_t ns = i->insert.m_evNs; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
139 |
uint32_t uid = i->m_uid; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
140 |
i->m_type = Command::INSERT_REMOVE; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
141 |
i->m_uid = uid; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
142 |
i->insertRemove.m_evNs = ns; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
143 |
i->insertRemove.m_evLoc = j->first; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
144 |
break; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
145 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
146 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
147 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
148 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
149 |
std::cout << "calculate remove locations..." << std::endl; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
150 |
// calculate the final insert/remove location. |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
151 |
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
152 |
{ |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
153 |
if (i->m_type == Command::INSERT_REMOVE) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
154 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
155 |
uint32_t loc = 0; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
156 |
for (CommandsI tmp = i; tmp != m_commands.end (); tmp++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
157 |
{ |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
158 |
if (tmp->m_type == Command::REMOVE) |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
159 |
{ |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
160 |
if (tmp->m_uid == i->insertRemove.m_evLoc) |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
161 |
{ |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
162 |
i->insertRemove.m_evLoc = loc; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
163 |
break; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
164 |
} |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
165 |
loc++; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
166 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
167 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
168 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
169 |
} |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
170 |
} |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
171 |
void |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
110
diff
changeset
|
172 |
LogReader::ExecuteLogCommands (uint32_t uid) |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
173 |
{ |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
174 |
if (m_command == m_commands.end ()) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
175 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
176 |
return; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
177 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
178 |
//std::cout << "one event, uid=" <<m_uid<< std::endl; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
179 |
struct Command cmd = *m_command; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
180 |
//std::cout << "cmd uid=" <<cmd.m_uid<< std::endl; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
181 |
while (cmd.m_uid == uid) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
182 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
183 |
m_command++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
184 |
switch (cmd.m_type) { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
185 |
case Command::INSERT: |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
186 |
//std::Cout << "exec insert now=" << Simulator::Now ().GetNanoSeconds () |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
187 |
//<< ", time=" << cmd.insert.m_evNs << std::endl; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
188 |
Simulator::Schedule (NanoSeconds (cmd.insert.m_evNs) - Now (), |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
189 |
&LogReader::ExecuteLogCommands, this, m_uid); |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
190 |
m_uid++; |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
191 |
break; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
192 |
case Command::INSERT_LATER: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
193 |
//std::cout << "exec insert later" << std::endl; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
194 |
Simulator::ScheduleNow (&LogReader::ExecuteLogCommands, this, m_uid); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
195 |
m_uid++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
196 |
break; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
197 |
case Command::REMOVE: |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
198 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
199 |
//std::cout << "exec remove" << std::endl; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
200 |
EventId id = m_removeEvents.back (); |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
201 |
m_removeEvents.pop_back (); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
202 |
Simulator::Remove (id); |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
203 |
} break; |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
204 |
case Command::INSERT_REMOVE: |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
205 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
206 |
//std::cout << "exec insert remove" << std::endl; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
207 |
EventId id = Simulator::Schedule (NanoSeconds (cmd.insertRemove.m_evNs) - Now (), |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
208 |
&LogReader::ExecuteLogCommands, this, m_uid); |
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
205
diff
changeset
|
209 |
NS_ASSERT (id.GetUid () == m_uid); |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
210 |
if (cmd.insertRemove.m_evLoc + 1 > m_removeEvents.size ()) |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
211 |
{ |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
212 |
uint32_t missing = cmd.insertRemove.m_evLoc + 1 - m_removeEvents.size (); |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
213 |
m_removeEvents.insert (m_removeEvents.begin (), |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
214 |
missing, id); |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
215 |
} |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
216 |
uint32_t index = m_removeEvents.size () - cmd.insertRemove.m_evLoc - 1; |
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
217 |
m_removeEvents[index] = id; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
218 |
m_uid++; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
219 |
} break; |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
220 |
default: |
286
57e6a2006962
convert use of <cassert> to "ns3/assert.h"
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
205
diff
changeset
|
221 |
NS_ASSERT (false); |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
222 |
break; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
223 |
} |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
224 |
cmd = *m_command; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
225 |
} |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
226 |
} |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
227 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
228 |
void |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
110
diff
changeset
|
229 |
LogReader::PrintStats (void) |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
230 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
231 |
uint32_t nInserts = 0; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
232 |
uint32_t nRemoves = 0; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
233 |
for (CommandsI i = m_commands.begin (); i != m_commands.end (); i++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
234 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
235 |
switch (i->m_type) { |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
236 |
case Command::INSERT: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
237 |
nInserts++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
238 |
break; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
239 |
case Command::INSERT_LATER: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
240 |
nInserts++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
241 |
break; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
242 |
case Command::INSERT_REMOVE: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
243 |
nInserts++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
244 |
break; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
245 |
case Command::REMOVE: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
246 |
nRemoves++; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
247 |
break; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
248 |
} |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
249 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
250 |
std::cout << "inserts="<<nInserts<<", removes="<<nRemoves<<std::endl; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
251 |
std::cout << "run simulation..."<<std::endl; |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
252 |
} |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
253 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
254 |
void |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
110
diff
changeset
|
255 |
LogReader::Run (void) |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
256 |
{ |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
257 |
m_uid = 1; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
258 |
SystemWallClockMs time; |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
259 |
time.Start (); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
260 |
m_command = m_commands.begin (); |
201
b7635c5d5bdf
make the event replay code actually work. Stop using deques and use std::vector instead. plus a bunch of other fixes to deal correctly with removes
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
197
diff
changeset
|
261 |
ExecuteLogCommands (0); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
262 |
Simulator::Run (); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
263 |
unsigned long long delta = time.End (); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
264 |
double delay = ((double)delta)/1000; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
265 |
std::cout << "runtime="<<delay<<"s"<<std::endl; |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
266 |
} |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
267 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
268 |
|
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
269 |
int main (int argc, char *argv[]) |
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
270 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
271 |
char const *input = 0; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
272 |
uint32_t n = 1; |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
273 |
bool is_map = false; |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
274 |
bool is_list = false; |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
275 |
bool is_heap = false; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
276 |
while (argc > 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
277 |
{ |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
278 |
if (strcmp ("--list", argv[0]) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
279 |
{ |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
280 |
is_list = true; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
281 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
282 |
else if (strcmp ("--heap", argv[0]) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
283 |
{ |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
284 |
is_heap = true; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
285 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
286 |
else if (strcmp ("--map", argv[0]) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
287 |
{ |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
288 |
is_map = true; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
289 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
290 |
else if (strncmp ("--n=", argv[0], strlen("--n=")) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
291 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
292 |
n = atoi (argv[0]+strlen ("--n=")); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
293 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
294 |
else if (strncmp ("--input=", argv[0],strlen ("--input=")) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
295 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
296 |
input = argv[0] + strlen ("--input="); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
297 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
298 |
else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
299 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
300 |
char const *filename = argv[0] + strlen ("--log="); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
301 |
Simulator::EnableLogTo (filename); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
302 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
303 |
argc--; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
304 |
argv++; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
305 |
} |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
306 |
if (input == 0) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
307 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
308 |
std::cerr << "need --input=[filename] option" << std::endl; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
309 |
return 1; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
310 |
} |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
311 |
LogReader log; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
312 |
log.ReadFromFilename (input); |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
313 |
std::cout << "start runs..." << std::endl; |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
314 |
for (uint32_t i = 0; i < n; i++) |
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
315 |
{ |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
316 |
if (is_map) |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
317 |
{ |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
318 |
Simulator::SetStdMap (); |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
319 |
} |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
320 |
else if (is_list) |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
321 |
{ |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
322 |
Simulator::SetLinkedList (); |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
323 |
} |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
324 |
else if (is_heap) |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
325 |
{ |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
326 |
Simulator::SetBinaryHeap (); |
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
327 |
} |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
328 |
log.Run (); |
205
681e44f1cf58
make sure we reset the simulator configuration for each run
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
201
diff
changeset
|
329 |
Simulator::Destroy (); |
197
8346ab3528bf
fix the Simulation event replayer: make it build
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
330 |
} |
12
917ba023c576
utils and samples
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
331 |
} |