added --print_sim_time to print simulated time to stdout

This commit is contained in:
Evan Tschannen 2021-11-23 12:10:20 -08:00 committed by Jingyu Zhou
parent b0aad44831
commit 37c9a1320c
3 changed files with 17 additions and 7 deletions

View File

@ -2010,8 +2010,9 @@ public:
machines.erase(machineId);
}
Sim2()
: time(0.0), timerTime(0.0), currentTaskID(TaskPriority::Zero), taskCount(0), yielded(false), yield_limit(0) {
Sim2(bool printSimTime)
: time(0.0), timerTime(0.0), currentTaskID(TaskPriority::Zero), taskCount(0), yielded(false), yield_limit(0),
printSimTime(printSimTime) {
// Not letting currentProcess be nullptr eliminates some annoying special cases
currentProcess =
new ProcessInfo("NoMachine",
@ -2073,6 +2074,9 @@ public:
t.action.send(Never());
} else {
mutex.enter();
if (printSimTime && (int)this->time < (int)t.time) {
printf("Time: %d\n", (int)t.time);
}
this->time = t.time;
this->timerTime = std::max(this->timerTime, this->time);
mutex.leave();
@ -2145,6 +2149,7 @@ public:
// Whether or not yield has returned true during the current iteration of the run loop
bool yielded;
int yield_limit; // how many more times yield may return false before next returning true
bool printSimTime;
private:
MockDNS mockDNS;
@ -2353,9 +2358,9 @@ Future<Reference<IUDPSocket>> Sim2::createUDPSocket(bool isV6) {
return Reference<IUDPSocket>(new UDPSimSocket(localAddress, Optional<NetworkAddress>{}));
}
void startNewSimulator() {
void startNewSimulator(bool printSimTime) {
ASSERT(!g_network);
g_network = g_pSimulator = new Sim2();
g_network = g_pSimulator = new Sim2(printSimTime);
g_simulator.connectionFailuresDisableDuration = deterministicRandom()->random01() < 0.5 ? 0 : 1e6;
}

View File

@ -469,7 +469,7 @@ private:
extern ISimulator* g_pSimulator;
#define g_simulator (*g_pSimulator)
void startNewSimulator();
void startNewSimulator(bool printSimTime);
// Parameters used to simulate disk performance
struct DiskParameters : ReferenceCounted<DiskParameters> {

View File

@ -99,7 +99,7 @@ enum {
OPT_DCID, OPT_MACHINE_CLASS, OPT_BUGGIFY, OPT_VERSION, OPT_BUILD_FLAGS, OPT_CRASHONERROR, OPT_HELP, OPT_NETWORKIMPL, OPT_NOBUFSTDOUT, OPT_BUFSTDOUTERR,
OPT_TRACECLOCK, OPT_NUMTESTERS, OPT_DEVHELP, OPT_ROLLSIZE, OPT_MAXLOGS, OPT_MAXLOGSSIZE, OPT_KNOB, OPT_UNITTESTPARAM, OPT_TESTSERVERS, OPT_TEST_ON_SERVERS, OPT_METRICSCONNFILE,
OPT_METRICSPREFIX, OPT_LOGGROUP, OPT_LOCALITY, OPT_IO_TRUST_SECONDS, OPT_IO_TRUST_WARN_ONLY, OPT_FILESYSTEM, OPT_PROFILER_RSS_SIZE, OPT_KVFILE,
OPT_TRACE_FORMAT, OPT_WHITELIST_BINPATH, OPT_BLOB_CREDENTIAL_FILE, OPT_CONFIG_PATH, OPT_USE_TEST_CONFIG_DB, OPT_FAULT_INJECTION, OPT_PROFILER
OPT_TRACE_FORMAT, OPT_WHITELIST_BINPATH, OPT_BLOB_CREDENTIAL_FILE, OPT_CONFIG_PATH, OPT_USE_TEST_CONFIG_DB, OPT_FAULT_INJECTION, OPT_PROFILER, OPT_PRINT_SIMTIME,
};
CSimpleOpt::SOption g_rgOptions[] = {
@ -187,6 +187,7 @@ CSimpleOpt::SOption g_rgOptions[] = {
{ OPT_FAULT_INJECTION, "-fi", SO_REQ_SEP },
{ OPT_FAULT_INJECTION, "--fault_injection", SO_REQ_SEP },
{ OPT_PROFILER, "--profiler_", SO_REQ_SEP},
{ OPT_PRINT_SIMTIME, "--print_sim_time", SO_NONE },
#ifndef TLS_DISABLED
TLS_OPTION_FLAGS
@ -1004,6 +1005,7 @@ struct CLIOptions {
UnitTestParameters testParams;
std::map<std::string, std::string> profilerConfig;
bool printSimTime = false;
static CLIOptions parseArgs(int argc, char* argv[]) {
CLIOptions opts;
@ -1484,6 +1486,9 @@ private:
case OPT_USE_TEST_CONFIG_DB:
configDBType = ConfigDBType::SIMPLE;
break;
case OPT_PRINT_SIMTIME:
printSimTime = true;
break;
#ifndef TLS_DISABLED
case TLSConfig::OPT_TLS_PLUGIN:
@ -1775,7 +1780,7 @@ int main(int argc, char* argv[]) {
if (role == ServerRole::Simulation || role == ServerRole::CreateTemplateDatabase) {
// startOldSimulator();
startNewSimulator();
startNewSimulator(opts.printSimTime);
openTraceFile(NetworkAddress(), opts.rollsize, opts.maxLogsSize, opts.logFolder, "trace", opts.logGroup);
openTracer(TracerType(deterministicRandom()->randomInt(static_cast<int>(TracerType::DISABLED),
static_cast<int>(TracerType::SIM_END))));