Skip to content

Commit 93de145

Browse files
committed
Simulation summary and incast logging
1 parent 59099d6 commit 93de145

File tree

9 files changed

+135
-26
lines changed

9 files changed

+135
-26
lines changed

simulation/simulation.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "simulation/simulation.hpp"
77
#include "utils/logger.hpp"
88
#include "utils/utils.hpp"
9+
#include "utils/pktdumper.hpp"
910
#include "topology/fattree_topology.hpp"
1011

1112

@@ -433,6 +434,41 @@ void Simulation::printSimulationStats(){
433434
ndebug_print("Generated: {} | Delivered: {}", this->nextPktId, this->totalPktsDelivered);
434435
}
435436

437+
438+
void Simulation::printSimulationSetup(){
439+
440+
ndebug_print_yellow("######## Simulation Setup ########");
441+
ndebug_print("TrafficPattern type is {}", trafficPatternTypeToString(syndbConfig.trafficPatternType));
442+
ndebug_print("TrafficDistribution type is {}", trafficGenTypeToString(syndbConfig.trafficGenType));
443+
ndebug_print("Trigger initial delay is {}ns", syndbConfig.triggerInitialDelay);
444+
#if LOGGING
445+
ndebug_print("Logging is enabled!");
446+
#else
447+
ndebug_print("Logging is disabled!");
448+
#endif
449+
450+
#if HOP_DELAY_NOISE
451+
ndebug_print("HopDelayNoise is enabled!");
452+
#else
453+
ndebug_print("HopDelayNoise is disabled!");
454+
#endif
455+
456+
#if TRIGGERS_ENABLED
457+
ndebug_print("Triggers are enabled!");
458+
#else
459+
ndebug_print("Triggers are disabled!");
460+
#endif
461+
462+
#if INCASTS_ENABLED
463+
ndebug_print("Incasts are enabled!");
464+
#else
465+
ndebug_print("Incasts are disabled!");
466+
#endif
467+
468+
ndebug_print("Time increment is {}ns", syndbSim.timeIncrement);
469+
ndebug_print("Running simulation for {}ns ...\n",syndbSim.totalTime);
470+
}
471+
436472
void Simulation::cleanUp(){
437473

438474
ndebug_print_yellow("Flushing remaining normal pkts");

simulation/simulation.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ typedef struct Simulation
5959
void logTriggerInfoMap();
6060
void showLinkUtilizations();
6161

62+
void printSimulationSetup();
6263
void printSimulationStats();
6364
void cleanUp();
6465

syndb-sim.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ int main(){
2222

2323
syndbSim = Simulation();
2424

25+
// Init Step 0: Open files for logging
26+
#if LOGGING
27+
syndbSim.pktDumper->openFiles(syndbConfig.numSwitches, syndbConfig.numHosts);
28+
#endif
29+
syndbSim.printSimulationSetup();
30+
2531
// Init Step 1: Build the topology
2632
syndbSim.buildTopo();
2733

@@ -38,13 +44,6 @@ int main(){
3844
// Init Step 3: Initialize the hosts
3945
syndbSim.initHosts();
4046

41-
// Init Step 4: Open files for logging
42-
#if LOGGING
43-
syndbSim.pktDumper->openFiles(syndbConfig.numSwitches, syndbConfig.numHosts);
44-
#endif
45-
46-
ndebug_print("Time increment is {}ns", syndbSim.timeIncrement);
47-
ndebug_print("Running simulation for {}ns ...",syndbSim.totalTime);
4847

4948
// Main simulation loop: at time = 0; all event lists are empty. Only step 4 does some work.
5049
for ( ; syndbSim.currTime <= syndbSim.totalTime; syndbSim.currTime += syndbSim.timeIncrement)

traffic/incastGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ void IncastGenerator::generateIncast(){
126126
// ndebug_print("Incast pkt ID: {}", host->nextPkt->id);
127127
}
128128

129+
syndbSim.pktDumper->dumpIncastInfo(*this->nextIncast);
130+
129131
this->updateNextIncast();
130132
}
131133

traffic/incastGenerator.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <memory>
55
#include <functional>
66
#include <list>
7+
#include <set>
78
#include "utils/types.hpp"
89

910

utils/logger.hpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <stdarg.h>
66
#include <fmt/core.h>
77
#include <fmt/color.h>
8+
#include "simulation/simulation.hpp"
89

910

1011
void log_debug(const std::string &msg);
@@ -31,13 +32,26 @@ void debug_print_yellow(const std::string &format, const Args&... args){
3132

3233
template <typename... Args>
3334
void ndebug_print(const std::string &format, const Args&... args){
34-
fmt::print(format, args...);
35+
36+
std::string msg = fmt::format(format, args...);
37+
38+
#if LOGGING
39+
syndbSim.pktDumper->logSimSummary(msg);
40+
#endif
41+
42+
fmt::print(msg);
3543
std::putc('\n', stdout);
3644
}
3745

3846
template <typename... Args>
3947
void ndebug_print_yellow(const std::string &format, const Args&... args){
40-
std::string msg = fmt::format(format, args...);
48+
49+
std::string msg = fmt::format(format, args...);
50+
51+
#if LOGGING
52+
syndbSim.pktDumper->logSimSummary(msg);
53+
#endif
54+
4155
fmt::print(fg(fmt::color::yellow), msg);
4256
std::putc('\n', stdout);
4357
}

utils/pktdumper.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include <typeinfo>
33

44
#include "utils/pktdumper.hpp"
5+
#include "utils/logger.hpp"
6+
#include "traffic/triggerGenerator.hpp"
57
#include <spdlog/cfg/env.h>
68

79

@@ -13,19 +15,25 @@ void PktDumper::openFiles(switch_id_t numberOfSwitches, host_id_t numberOfHosts)
1315
const std::tm *calendarTime = std::localtime(&currentTime);
1416

1517
// clear stpdlog default pattern
18+
debug_print("Clearing default spdlog dump pattern.");
1619
spdlog::set_pattern("%v");
1720
spdlog::init_thread_pool(QUEUE_SIZE, 1);
18-
debug_print("Clearing default spdlog dump pattern.");
21+
1922

2023
this->prefixStringForFileName = "dump_" + std::to_string(calendarTime->tm_hour) + "_" +
2124
std::to_string(calendarTime->tm_min) + "_" +
2225
std::to_string(calendarTime->tm_sec) + "_";
23-
ndebug_print("PktDump file prefix: {}", this->prefixStringForFileName);
26+
27+
std::string simSummaryFileName = "./data/" + prefixStringForFileName + "summary.txt";
28+
this->simSummaryFilePointer = spdlog::basic_logger_mt("summary", simSummaryFileName);
2429

2530
// open all file pointers in write/output mode
2631
std::string triggerFileName = "./data/" + prefixStringForFileName + "trigger.txt";
2732
this->triggerFilePointer = spdlog::basic_logger_mt<spdlog::async_factory>("trigger", triggerFileName);
2833

34+
std::string incastFileName = "./data/" + prefixStringForFileName + "incast.txt";
35+
this->incastFilePointer = spdlog::basic_logger_mt<spdlog::async_factory>("incast", incastFileName);
36+
2937
std::string sourceDestinationFile = "./data/" + prefixStringForFileName + "sourceDestination.txt";
3038
this->sourceDestinationFilePointer = spdlog::basic_logger_mt<spdlog::async_factory>("sourceDestination", sourceDestinationFile);
3139

@@ -37,6 +45,8 @@ void PktDumper::openFiles(switch_id_t numberOfSwitches, host_id_t numberOfHosts)
3745
}
3846

3947
debug_print("Number of Hosts: {}", numberOfHosts);
48+
49+
ndebug_print("PktDump file prefix: {}", this->prefixStringForFileName);
4050
}
4151

4252

@@ -52,7 +62,7 @@ PktDumper::~PktDumper() {
5262
}
5363

5464

55-
void PktDumper::dumpPacket(normalpkt_p pkt){
65+
void PktDumper::dumpPacket(const normalpkt_p pkt){
5666

5767
debug_print_yellow("-------- HOSTS ----------");
5868
debug_print("Start Time: {}", pkt->startTime);
@@ -68,7 +78,7 @@ void PktDumper::dumpPacket(normalpkt_p pkt){
6878
}
6979

7080

71-
void PktDumper::dumpTriggerInfo(trigger_id_t triggerId, triggerInfo tinfo, SwitchType switchType){
81+
void PktDumper::dumpTriggerInfo(const trigger_id_t &triggerId, triggerInfo &tinfo, const SwitchType &switchType){
7282

7383
std::string stringForTriggerFile = std::to_string(triggerId) + "\t" + std::to_string(tinfo.triggerOrigTime) + "\t" + std::to_string(tinfo.originSwitch);
7484

@@ -79,3 +89,12 @@ void PktDumper::dumpTriggerInfo(trigger_id_t triggerId, triggerInfo tinfo, Switc
7989

8090
this->triggerFilePointer->info("{}", stringForTriggerFile);
8191
}
92+
93+
void PktDumper::dumpIncastInfo(const incastScheduleInfo &incastInfo){
94+
this->incastFilePointer->info("{}\t{}", incastInfo.time, incastInfo.targetHostId);
95+
}
96+
97+
void PktDumper::logSimSummary(const std::string &msg){
98+
// this->simSummaryFilePointer->info("{}",msg);
99+
this->simSummaryFilePointer->info("{}", msg);
100+
}

utils/pktdumper.hpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#ifndef PACKETDUMPER_H
1+
#ifndef PACKETDUMPER_H
22
#define PACKETDUMPER_H
33

44
#include <map>
@@ -8,34 +8,35 @@
88
#include <time.h>
99

1010
#include "traffic/packet.hpp"
11+
#include "traffic/incastGenerator.hpp"
12+
#include "traffic/triggerGenerator.hpp"
1113
#include "topology/switch.hpp"
12-
#include "utils/logger.hpp"
14+
#include <fmt/core.h>
15+
#include <fmt/color.h>
16+
1317

1418
// need to declare logger.hpp first because of conflict in fmt
1519
#include <spdlog/async.h>
20+
#include <spdlog/logger.h>
1621
#include <spdlog/sinks/basic_file_sink.h>
1722

1823
#define QUEUE_SIZE 32768 * 2
19-
20-
struct triggerInfo {
21-
sim_time_t triggerOrigTime;
22-
switch_id_t originSwitch;
23-
std::map<switch_id_t, sim_time_t> rxSwitchTimes;
24-
};
25-
26-
typedef struct PktDumper
24+
typedef struct PktDumper
2725
{
2826
std::string prefixStringForFileName;
2927

30-
std::shared_ptr<spdlog::logger> triggerFilePointer, sourceDestinationFilePointer;
28+
std::shared_ptr<spdlog::logger> triggerFilePointer, sourceDestinationFilePointer, incastFilePointer, simSummaryFilePointer;
3129
std::vector<std::shared_ptr<spdlog::logger>> switchFilePointers;
3230

3331
~PktDumper();
3432
PktDumper() = default;
3533

3634
void openFiles(switch_id_t numberOfSwitches, host_id_t numberOfHosts);
37-
void dumpPacket(normalpkt_p pkt);
38-
void dumpTriggerInfo(trigger_id_t triggerId, triggerInfo tinfo, SwitchType switchType);
35+
void dumpPacket(const normalpkt_p pkt);
36+
void dumpTriggerInfo(const trigger_id_t &triggerId, triggerInfo &tinfo, const SwitchType &switchType);
37+
void dumpIncastInfo(const incastScheduleInfo &incastInfo);
38+
void logSimSummary(const std::string &msg);
39+
3940
} PktDumper;
4041

4142

utils/types.hpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define TYPES_H
33

44
#include <cstdint>
5+
#include <fmt/core.h>
56

67
/* Simulation Related Types */
78
typedef uint64_t sim_time_t;
@@ -46,4 +47,39 @@ enum class TrafficPatternType {SimpleTopo, AlltoAll, FtUniform, FtMixed};
4647
enum class TrafficGenType {Continuous, Distribution};
4748
enum class TrafficDstType {IntraRack, InterRack};
4849

50+
inline std::string trafficPatternTypeToString(TrafficPatternType type){
51+
switch(type){
52+
case TrafficPatternType::SimpleTopo:
53+
return "SimpleTopo";
54+
break;
55+
case TrafficPatternType::AlltoAll:
56+
return "AlltoAll";
57+
break;
58+
case TrafficPatternType::FtUniform:
59+
return "FtUniform";
60+
break;
61+
case TrafficPatternType::FtMixed:
62+
return "FtMixed";
63+
break;
64+
default:
65+
std::string msg = fmt::format("Unknown TrafficPatternType {}", type);
66+
throw std::logic_error(msg);
67+
break;
68+
}
69+
}
70+
71+
inline std::string trafficGenTypeToString(TrafficGenType type){
72+
switch(type){
73+
case TrafficGenType::Continuous:
74+
return "Continuous";
75+
break;
76+
case TrafficGenType::Distribution:
77+
return "Distribution";
78+
break;
79+
default:
80+
std::string msg = fmt::format("Unknown TrafficGenType {}", type);
81+
throw std::logic_error(msg);
82+
}
83+
}
84+
4985
#endif

0 commit comments

Comments
 (0)