fix coding style
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode:NS3; -*- */
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 INRIA
|
||||
* All rights reserved.
|
||||
@@ -30,106 +30,106 @@ using namespace ns3;
|
||||
static void
|
||||
benchPtrA (uint32_t n)
|
||||
{
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
Packet o = p;
|
||||
o.peek (&ipv4);
|
||||
o.remove (&ipv4);
|
||||
o.peek (&udp);
|
||||
o.remove (&udp);
|
||||
o.peek (&data);
|
||||
o.remove (&data);
|
||||
}
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
Packet o = p;
|
||||
o.peek (&ipv4);
|
||||
o.remove (&ipv4);
|
||||
o.peek (&udp);
|
||||
o.remove (&udp);
|
||||
o.peek (&data);
|
||||
o.remove (&data);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
benchPtrB (uint32_t n)
|
||||
{
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
}
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ptrC2 (Packet p)
|
||||
{
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
|
||||
p.peek (&udp);
|
||||
p.remove (&udp);
|
||||
p.peek (&data);
|
||||
p.remove (&data);
|
||||
p.peek (&udp);
|
||||
p.remove (&udp);
|
||||
p.peek (&data);
|
||||
p.remove (&data);
|
||||
}
|
||||
|
||||
static void
|
||||
ptrC1 (Packet p)
|
||||
{
|
||||
ChunkIpv4 ipv4;
|
||||
p.peek (&ipv4);
|
||||
p.remove (&ipv4);
|
||||
ptrC2 (p);
|
||||
ChunkIpv4 ipv4;
|
||||
p.peek (&ipv4);
|
||||
p.remove (&ipv4);
|
||||
ptrC2 (p);
|
||||
}
|
||||
|
||||
static void
|
||||
benchPtrC (uint32_t n)
|
||||
{
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
ChunkConstantData data = ChunkConstantData (2000, 1);
|
||||
ChunkUdp udp;
|
||||
ChunkIpv4 ipv4;
|
||||
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
ptrC1 (p);
|
||||
}
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
Packet p;
|
||||
p.add (&data);
|
||||
p.add (&udp);
|
||||
p.add (&ipv4);
|
||||
ptrC1 (p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
runBench (void (*bench) (uint32_t), uint32_t n, char const *name)
|
||||
{
|
||||
WallClockMs time;
|
||||
time.start ();
|
||||
(*bench) (n);
|
||||
unsigned long long deltaMs = time.end ();
|
||||
double ps = n;
|
||||
ps *= 1000;
|
||||
ps /= deltaMs;
|
||||
std::cout << name<<"=" << ps << " packets/s" << std::endl;
|
||||
WallClockMs time;
|
||||
time.start ();
|
||||
(*bench) (n);
|
||||
unsigned long long deltaMs = time.end ();
|
||||
double ps = n;
|
||||
ps *= 1000;
|
||||
ps /= deltaMs;
|
||||
std::cout << name<<"=" << ps << " packets/s" << std::endl;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
uint32_t n = 0;
|
||||
while (argc > 0) {
|
||||
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
|
||||
char const *nAscii = argv[0] + strlen ("--n=");
|
||||
n = atoi (nAscii);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
uint32_t n = 0;
|
||||
while (argc > 0) {
|
||||
if (strncmp ("--n=", argv[0],strlen ("--n=")) == 0) {
|
||||
char const *nAscii = argv[0] + strlen ("--n=");
|
||||
n = atoi (nAscii);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
runBench (&benchPtrA, n, "a");
|
||||
runBench (&benchPtrB, n, "b");
|
||||
runBench (&benchPtrC, n, "c");
|
||||
runBench (&benchPtrA, n, "a");
|
||||
runBench (&benchPtrB, n, "b");
|
||||
runBench (&benchPtrC, n, "c");
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode:NS3; -*- */
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 INRIA
|
||||
* All rights reserved.
|
||||
@@ -32,115 +32,115 @@ bool gDebug = false;
|
||||
|
||||
class Bench {
|
||||
public:
|
||||
void ReadDistribution (std::istream &istream);
|
||||
void SetTotal (uint32_t total);
|
||||
void RunBench (void);
|
||||
void ReadDistribution (std::istream &istream);
|
||||
void SetTotal (uint32_t total);
|
||||
void RunBench (void);
|
||||
private:
|
||||
void Cb (void);
|
||||
std::vector<uint64_t> m_distribution;
|
||||
std::vector<uint64_t>::const_iterator m_current;
|
||||
uint32_t m_n;
|
||||
uint32_t m_total;
|
||||
void Cb (void);
|
||||
std::vector<uint64_t> m_distribution;
|
||||
std::vector<uint64_t>::const_iterator m_current;
|
||||
uint32_t m_n;
|
||||
uint32_t m_total;
|
||||
};
|
||||
|
||||
void
|
||||
Bench::SetTotal (uint32_t total)
|
||||
{
|
||||
m_total = total;
|
||||
m_total = total;
|
||||
}
|
||||
|
||||
void
|
||||
Bench::ReadDistribution (std::istream &input)
|
||||
{
|
||||
double data;
|
||||
while (!input.eof ()) {
|
||||
if (input >> data) {
|
||||
uint64_t ns = (uint64_t) (data * 1000000000);
|
||||
m_distribution.push_back (ns);
|
||||
} else {
|
||||
input.clear ();
|
||||
std::string line;
|
||||
input >> line;
|
||||
}
|
||||
}
|
||||
double data;
|
||||
while (!input.eof ()) {
|
||||
if (input >> data) {
|
||||
uint64_t ns = (uint64_t) (data * 1000000000);
|
||||
m_distribution.push_back (ns);
|
||||
} else {
|
||||
input.clear ();
|
||||
std::string line;
|
||||
input >> line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Bench::RunBench (void)
|
||||
{
|
||||
SystemWallClockMs time;
|
||||
double init, simu;
|
||||
time.Start ();
|
||||
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
|
||||
i != m_distribution.end (); i++) {
|
||||
Simulator::Schedule (Now () + NanoSeconds (*i), &Bench::Cb, this);
|
||||
}
|
||||
init = time.End ();
|
||||
SystemWallClockMs time;
|
||||
double init, simu;
|
||||
time.Start ();
|
||||
for (std::vector<uint64_t>::const_iterator i = m_distribution.begin ();
|
||||
i != m_distribution.end (); i++) {
|
||||
Simulator::Schedule (Now () + NanoSeconds (*i), &Bench::Cb, this);
|
||||
}
|
||||
init = time.End ();
|
||||
|
||||
m_current = m_distribution.begin ();
|
||||
m_current = m_distribution.begin ();
|
||||
|
||||
time.Start ();
|
||||
Simulator::Run ();
|
||||
simu = time.End ();
|
||||
time.Start ();
|
||||
Simulator::Run ();
|
||||
simu = time.End ();
|
||||
|
||||
std::cout <<
|
||||
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
|
||||
"simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
|
||||
"init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
|
||||
init / ((double)m_distribution.size ())<< "s" << std::endl <<
|
||||
"simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
|
||||
simu / ((double)m_n) << "s" << std::endl
|
||||
;
|
||||
std::cout <<
|
||||
"init n=" << m_distribution.size () << ", time=" << init << "s" << std::endl <<
|
||||
"simu n=" << m_n << ", time=" <<simu << "s" << std::endl <<
|
||||
"init " << ((double)m_distribution.size ()) / init << " insert/s, avg insert=" <<
|
||||
init / ((double)m_distribution.size ())<< "s" << std::endl <<
|
||||
"simu " << ((double)m_n) / simu<< " hold/s, avg hold=" <<
|
||||
simu / ((double)m_n) << "s" << std::endl
|
||||
;
|
||||
}
|
||||
|
||||
void
|
||||
Bench::Cb (void)
|
||||
{
|
||||
if (m_n > m_total) {
|
||||
return;
|
||||
}
|
||||
if (m_current == m_distribution.end ()) {
|
||||
m_current = m_distribution.begin ();
|
||||
}
|
||||
if (gDebug) {
|
||||
std::cerr << "event at " << Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
|
||||
}
|
||||
Simulator::Schedule (Now () + NanoSeconds (*m_current), &Bench::Cb, this);
|
||||
m_current++;
|
||||
m_n++;
|
||||
if (m_n > m_total) {
|
||||
return;
|
||||
}
|
||||
if (m_current == m_distribution.end ()) {
|
||||
m_current = m_distribution.begin ();
|
||||
}
|
||||
if (gDebug) {
|
||||
std::cerr << "event at " << Simulator::Now ().ApproximateToSeconds () << "s" << std::endl;
|
||||
}
|
||||
Simulator::Schedule (Now () + NanoSeconds (*m_current), &Bench::Cb, this);
|
||||
m_current++;
|
||||
m_n++;
|
||||
}
|
||||
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
char const *filename = argv[1];
|
||||
std::istream *input;
|
||||
argc-=2;
|
||||
argv+= 2;
|
||||
if (strcmp (filename, "-") == 0) {
|
||||
input = &std::cin;
|
||||
} else {
|
||||
input = new std::ifstream (filename);
|
||||
}
|
||||
while (argc > 0) {
|
||||
if (strcmp ("--list", argv[0]) == 0) {
|
||||
Simulator::SetLinkedList ();
|
||||
} else if (strcmp ("--heap", argv[0]) == 0) {
|
||||
Simulator::SetBinaryHeap ();
|
||||
} else if (strcmp ("--map", argv[0]) == 0) {
|
||||
Simulator::SetStdMap ();
|
||||
} else if (strcmp ("--debug", argv[0]) == 0) {
|
||||
gDebug = true;
|
||||
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
|
||||
char const *filename = argv[0] + strlen ("--log=");
|
||||
Simulator::EnableLogTo (filename);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
Bench *bench = new Bench ();
|
||||
bench->ReadDistribution (*input);
|
||||
bench->SetTotal (20000);
|
||||
bench->RunBench ();
|
||||
char const *filename = argv[1];
|
||||
std::istream *input;
|
||||
argc-=2;
|
||||
argv+= 2;
|
||||
if (strcmp (filename, "-") == 0) {
|
||||
input = &std::cin;
|
||||
} else {
|
||||
input = new std::ifstream (filename);
|
||||
}
|
||||
while (argc > 0) {
|
||||
if (strcmp ("--list", argv[0]) == 0) {
|
||||
Simulator::SetLinkedList ();
|
||||
} else if (strcmp ("--heap", argv[0]) == 0) {
|
||||
Simulator::SetBinaryHeap ();
|
||||
} else if (strcmp ("--map", argv[0]) == 0) {
|
||||
Simulator::SetStdMap ();
|
||||
} else if (strcmp ("--debug", argv[0]) == 0) {
|
||||
gDebug = true;
|
||||
} else if (strncmp ("--log=", argv[0],strlen ("--log=")) == 0) {
|
||||
char const *filename = argv[0] + strlen ("--log=");
|
||||
Simulator::EnableLogTo (filename);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
Bench *bench = new Bench ();
|
||||
bench->ReadDistribution (*input);
|
||||
bench->SetTotal (20000);
|
||||
bench->RunBench ();
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode:NS3; -*- */
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2006 INRIA
|
||||
* All rights reserved.
|
||||
@@ -32,45 +32,45 @@ using namespace ns3;
|
||||
|
||||
class LogReader {
|
||||
public:
|
||||
void readFrom_filename (char const *filename);
|
||||
void run (void);
|
||||
void printStats (void);
|
||||
void readFrom_filename (char const *filename);
|
||||
void run (void);
|
||||
void printStats (void);
|
||||
private:
|
||||
struct Command {
|
||||
enum {
|
||||
REMOVE,
|
||||
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_evUs;
|
||||
} 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_evUs;
|
||||
} insertRemove;
|
||||
};
|
||||
};
|
||||
void executeLogCommands (uint32_t uid);
|
||||
struct Command {
|
||||
enum {
|
||||
REMOVE,
|
||||
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_evUs;
|
||||
} 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_evUs;
|
||||
} insertRemove;
|
||||
};
|
||||
};
|
||||
void executeLogCommands (uint32_t uid);
|
||||
|
||||
typedef std::deque<struct Command> Commands;
|
||||
typedef std::deque<struct Command>::iterator CommandsI;
|
||||
typedef std::deque<Event > RemoveEvents;
|
||||
|
||||
typedef std::deque<struct Command> Commands;
|
||||
typedef std::deque<struct Command>::iterator CommandsI;
|
||||
typedef std::deque<Event > RemoveEvents;
|
||||
|
||||
|
||||
Commands m_commands;
|
||||
CommandsI m_command;
|
||||
RemoveEvents m_removeEvents;
|
||||
uint32_t m_uid;
|
||||
Commands m_commands;
|
||||
CommandsI m_command;
|
||||
RemoveEvents m_removeEvents;
|
||||
uint32_t m_uid;
|
||||
};
|
||||
|
||||
typedef std::vector<std::pair<uint32_t, uint32_t> > Removes;
|
||||
@@ -79,187 +79,187 @@ typedef std::vector<std::pair<uint32_t, uint32_t> >::iterator RemovesI;
|
||||
void
|
||||
LogReader::ReadFrom_filename (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 nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
struct Command cmd;
|
||||
cmd.m_type = Command::INSERT;
|
||||
cmd.m_uid = nowUid;
|
||||
cmd.insert.m_evUs = evUs;
|
||||
m_commands.push_back (cmd);
|
||||
} else if (type == "r") {
|
||||
uint32_t nowUid, evUid;
|
||||
uint64_t nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
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 nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
struct Command cmd;
|
||||
cmd.m_type = Command::INSERT_LATER;
|
||||
cmd.m_uid = nowUid;
|
||||
m_commands.push_back (cmd);
|
||||
}
|
||||
}
|
||||
log.close ();
|
||||
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 nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
struct Command cmd;
|
||||
cmd.m_type = Command::INSERT;
|
||||
cmd.m_uid = nowUid;
|
||||
cmd.insert.m_evUs = evUs;
|
||||
m_commands.push_back (cmd);
|
||||
} else if (type == "r") {
|
||||
uint32_t nowUid, evUid;
|
||||
uint64_t nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
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 nowUs, evUs;
|
||||
log >> nowUid >> nowUs >> evUid >> evUs;
|
||||
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..." << 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->m_uid) {
|
||||
// this insert will be removed later.
|
||||
uint64_t us = i->insert.m_evUs;
|
||||
uint32_t uid = i->m_uid;
|
||||
i->m_type = Command::INSERT_REMOVE;
|
||||
i->m_uid = uid;
|
||||
i->insertRemove.m_evUs = us;
|
||||
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 &&
|
||||
tmp->m_uid == i->insertRemove.m_evLoc) {
|
||||
i->insertRemove.m_evLoc = loc;
|
||||
break;
|
||||
}
|
||||
loc++;
|
||||
}
|
||||
}
|
||||
}
|
||||
std::cout << "gather insert removes..." << 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->m_uid) {
|
||||
// this insert will be removed later.
|
||||
uint64_t us = i->insert.m_evUs;
|
||||
uint32_t uid = i->m_uid;
|
||||
i->m_type = Command::INSERT_REMOVE;
|
||||
i->m_uid = uid;
|
||||
i->insertRemove.m_evUs = us;
|
||||
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 &&
|
||||
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::nowUs ()
|
||||
//<< ", time=" << cmd.insert.m_evUs << std::endl;
|
||||
Simulator::ScheduleAbsUs (cmd.insert.m_evUs,
|
||||
makeEvent (&LogReader::executeLogCommands, this, m_uid));
|
||||
m_uid++;
|
||||
break;
|
||||
case Command::INSERT_LATER:
|
||||
//std::cout << "exec insert later" << std::endl;
|
||||
Simulator::ScheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
|
||||
m_uid++;
|
||||
break;
|
||||
case Command::REMOVE: {
|
||||
//std::cout << "exec remove" << std::endl;
|
||||
Event ev = m_removeEvents.front ();
|
||||
m_removeEvents.pop_front ();
|
||||
Simulator::Remove (ev);
|
||||
} break;
|
||||
case Command::INSERT_REMOVE: {
|
||||
//std::cout << "exec insert remove" << std::endl;
|
||||
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
|
||||
Simulator::ScheduleAbsUs (cmd.insertRemove.m_evUs, ev);
|
||||
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
|
||||
m_uid++;
|
||||
} break;
|
||||
}
|
||||
cmd = *m_command;
|
||||
}
|
||||
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::nowUs ()
|
||||
//<< ", time=" << cmd.insert.m_evUs << std::endl;
|
||||
Simulator::ScheduleAbsUs (cmd.insert.m_evUs,
|
||||
makeEvent (&LogReader::executeLogCommands, this, m_uid));
|
||||
m_uid++;
|
||||
break;
|
||||
case Command::INSERT_LATER:
|
||||
//std::cout << "exec insert later" << std::endl;
|
||||
Simulator::ScheduleNow (makeEvent (&LogReader::executeLogCommands, this, m_uid));
|
||||
m_uid++;
|
||||
break;
|
||||
case Command::REMOVE: {
|
||||
//std::cout << "exec remove" << std::endl;
|
||||
Event ev = m_removeEvents.front ();
|
||||
m_removeEvents.pop_front ();
|
||||
Simulator::Remove (ev);
|
||||
} break;
|
||||
case Command::INSERT_REMOVE: {
|
||||
//std::cout << "exec insert remove" << std::endl;
|
||||
Event ev = makeEvent (&LogReader::executeLogCommands, this, m_uid);
|
||||
Simulator::ScheduleAbsUs (cmd.insertRemove.m_evUs, ev);
|
||||
m_removeEvents[cmd.insertRemove.m_evLoc] = ev;
|
||||
m_uid++;
|
||||
} 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;
|
||||
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 = 0;
|
||||
WallClockMs time;
|
||||
time.start ();
|
||||
m_command = m_commands.begin ();
|
||||
executeLogCommands (m_uid);
|
||||
Simulator::Run ();
|
||||
unsigned long long delta = time.end ();
|
||||
double delay = ((double)delta)/1000;
|
||||
std::cout << "runtime="<<delay<<"s"<<std::endl;
|
||||
m_uid = 0;
|
||||
WallClockMs time;
|
||||
time.start ();
|
||||
m_command = m_commands.begin ();
|
||||
executeLogCommands (m_uid);
|
||||
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;
|
||||
while (argc > 0) {
|
||||
if (strcmp ("--list", argv[0]) == 0) {
|
||||
Simulator::SetLinkedList ();
|
||||
} else if (strcmp ("--heap", argv[0]) == 0) {
|
||||
Simulator::SetBinaryHeap ();
|
||||
} else if (strcmp ("--map", argv[0]) == 0) {
|
||||
Simulator::SetStdMap ();
|
||||
} 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.readFrom_filename (input);
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
log.run ();
|
||||
}
|
||||
char const *input = 0;
|
||||
uint32_t n = 1;
|
||||
while (argc > 0) {
|
||||
if (strcmp ("--list", argv[0]) == 0) {
|
||||
Simulator::SetLinkedList ();
|
||||
} else if (strcmp ("--heap", argv[0]) == 0) {
|
||||
Simulator::SetBinaryHeap ();
|
||||
} else if (strcmp ("--map", argv[0]) == 0) {
|
||||
Simulator::SetStdMap ();
|
||||
} 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.readFrom_filename (input);
|
||||
for (uint32_t i = 0; i < n; i++) {
|
||||
log.run ();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* -*- Mode:NS3; -*- */
|
||||
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
|
||||
/*
|
||||
* Copyright (c) 2005 INRIA
|
||||
* All rights reserved.
|
||||
@@ -24,9 +24,9 @@
|
||||
int main (int argc, char *argv[])
|
||||
{
|
||||
#ifdef RUN_SELF_TESTS
|
||||
ns3::TestManager::EnableVerbose ();
|
||||
ns3::TestManager::RunTests ();
|
||||
ns3::TestManager::EnableVerbose ();
|
||||
ns3::TestManager::RunTests ();
|
||||
#endif /* RUN_SELF_TESTS */
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user