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();
}
int replay_logfile(const char *fn) {
int replay_logfile(const char *fn, bool verbose) {
drv::ReplayPlayer player;
player.open_logfile(fn);
if (verbose) {
player.enable_stdout();
}
while (true) {
drv::ReplayPlayer::Status st = player.step();
if (st != drv::ReplayPlayer::ST_REPLAYING) {
@@ -493,17 +496,22 @@ public:
// If argv contains "replay <filename>", do a replay,
// and then skip everything else.
if ((argc >= 1) && (strcmp(argv[0], "replay") == 0)) {
if (argc >= 1) {
std::string cmd(argv[0]);
if ((cmd == "replay") || (cmd == "vreplay")) {
if (argc != 2) {
std::cerr << "usage: " << program << " replay <filename>" << std::endl;
exit(1);
return 1;
}
return replay_logfile(argv[1], cmd == "vreplay");
}
return replay_logfile(argv[1]);
}
// If argv contains "record <filename>", start recording,
// and remove the "record <filename>" from argv.
if ((argc >= 1) && (strcmp(argv[0], "record") == 0)) {
if (argc >= 1) {
std::string cmd = argv[0];
if (cmd == "record") {
if (argc < 2) {
DrivenEngine::print_usage(std::cerr, program);
return 1;
@@ -515,6 +523,7 @@ public:
}
argc -= 2; argv += 2;
}
}
// Create the engine.
if (argc < 1) {

View File

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

View File

@@ -96,6 +96,7 @@ private:
Status status_;
std::string logfn_;
std::string engine_;
bool enable_stdout_;
void set_status(Status e);
@@ -119,6 +120,15 @@ public:
//
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.
//
// Returns a status code, which is usually ST_REPLAYING.