Added vreplay with stdout

This commit is contained in:
2022-03-11 19:11:09 -05:00
parent cfd299006f
commit e4ebfcbdb1
3 changed files with 40 additions and 16 deletions

View File

@@ -470,9 +470,12 @@ public:
cleanup_channels(); cleanup_channels();
} }
int replay_logfile(const char *fn) { int replay_logfile(const char *fn, bool verbose) {
drv::ReplayPlayer player; drv::ReplayPlayer player;
player.open_logfile(fn); player.open_logfile(fn);
if (verbose) {
player.enable_stdout();
}
while (true) { while (true) {
drv::ReplayPlayer::Status st = player.step(); drv::ReplayPlayer::Status st = player.step();
if (st != drv::ReplayPlayer::ST_REPLAYING) { if (st != drv::ReplayPlayer::ST_REPLAYING) {
@@ -493,27 +496,33 @@ public:
// If argv contains "replay <filename>", do a replay, // If argv contains "replay <filename>", do a replay,
// and then skip everything else. // and then skip everything else.
if ((argc >= 1) && (strcmp(argv[0], "replay") == 0)) { if (argc >= 1) {
if (argc != 2) { std::string cmd(argv[0]);
std::cerr << "usage: " << program << " replay <filename>" << std::endl; if ((cmd == "replay") || (cmd == "vreplay")) {
exit(1); if (argc != 2) {
std::cerr << "usage: " << program << " replay <filename>" << std::endl;
return 1;
}
return replay_logfile(argv[1], cmd == "vreplay");
} }
return replay_logfile(argv[1]);
} }
// If argv contains "record <filename>", start recording, // If argv contains "record <filename>", start recording,
// and remove the "record <filename>" from argv. // and remove the "record <filename>" from argv.
if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) { if (argc >= 1) {
if (argc < 2) { std::string cmd = argv[0];
DrivenEngine::print_usage(std::cerr, program); if (cmd == "record") {
return 1; if (argc < 2) {
DrivenEngine::print_usage(std::cerr, program);
return 1;
}
bool ok = recorder_.open_logfile(argv[1]);
if (!ok) {
std::cerr << "Could not open logfile: " << argv[1] << std::endl;
return 1;
}
argc -= 2; argv += 2;
} }
bool ok = recorder_.open_logfile(argv[1]);
if (!ok) {
std::cerr << "Could not open logfile: " << argv[1] << std::endl;
return 1;
}
argc -= 2; argv += 2;
} }
// Create the engine. // Create the engine.

View File

@@ -160,6 +160,7 @@ std::string_view rlog_string(std::ifstream &s, char *rlog_buf) {
ReplayPlayer::ReplayPlayer() { ReplayPlayer::ReplayPlayer() {
status_ = ST_REPLAYING; status_ = ST_REPLAYING;
enable_stdout_ = false;
buf_.reset(new char[RLOG_BUFSIZE]); buf_.reset(new char[RLOG_BUFSIZE]);
} }
@@ -344,6 +345,10 @@ void ReplayPlayer::drv_sent_outgoing() {
set_status(ST_NONDERMINISTIC); set_status(ST_NONDERMINISTIC);
return; return;
} }
if ((chid == 0) && (enable_stdout_)) {
std::string_view sub = data.substr(0, nbytes);
std::cout << sub;
}
e_->drv_sent_outgoing(chid, nbytes); e_->drv_sent_outgoing(chid, nbytes);
} }

View File

@@ -96,6 +96,7 @@ private:
Status status_; Status status_;
std::string logfn_; std::string logfn_;
std::string engine_; std::string engine_;
bool enable_stdout_;
void set_status(Status e); void set_status(Status e);
@@ -119,6 +120,15 @@ public:
// //
bool open_logfile(const char *fn); bool open_logfile(const char *fn);
// Enable stdout.
//
// Normally, stdout is suppressed during replay.
// If you enable stdout, then the engine will print
// all the same messages it did when running in the
// first place.
//
void enable_stdout() { enable_stdout_ = true; }
// Execute a single step from the replay log. // Execute a single step from the replay log.
// //
// Returns a status code, which is usually ST_REPLAYING. // Returns a status code, which is usually ST_REPLAYING.