提交 fba1b3d9 编写于 作者: Y Yinan Xu

emu: add --no-snapshot option to disable saving snapshots

上级 c0bc6fd8
...@@ -15,15 +15,16 @@ void set_nemu_this_pc(uint64_t pc); ...@@ -15,15 +15,16 @@ void set_nemu_this_pc(uint64_t pc);
static inline void print_help(const char *file) { static inline void print_help(const char *file) {
printf("Usage: %s [OPTION...]\n", file); printf("Usage: %s [OPTION...]\n", file);
printf("\n"); printf("\n");
printf(" -s, --seed=NUM use this seed\n"); printf(" -s, --seed=NUM use this seed\n");
printf(" -C, --max-cycles=NUM execute at most NUM cycles\n"); printf(" -C, --max-cycles=NUM execute at most NUM cycles\n");
printf(" -I, --max-instr=NUM execute at most NUM instructions\n"); printf(" -I, --max-instr=NUM execute at most NUM instructions\n");
printf(" -i, --image=FILE run with this image file\n"); printf(" -i, --image=FILE run with this image file\n");
printf(" -b, --log-begin=NUM display log from NUM th cycle\n"); printf(" -b, --log-begin=NUM display log from NUM th cycle\n");
printf(" -e, --log-end=NUM stop display log at NUM th cycle\n"); printf(" -e, --log-end=NUM stop display log at NUM th cycle\n");
printf(" --load-snapshot=PATH load snapshot from PATH\n"); printf(" --load-snapshot=PATH load snapshot from PATH\n");
printf(" --dump-wave dump waveform when log is enabled\n"); printf(" --no-snapshot disable saving snapshots\n");
printf(" -h, --help print program help info\n"); printf(" --dump-wave dump waveform when log is enabled\n");
printf(" -h, --help print program help info\n");
printf("\n"); printf("\n");
} }
...@@ -33,6 +34,7 @@ inline EmuArgs parse_args(int argc, const char *argv[]) { ...@@ -33,6 +34,7 @@ inline EmuArgs parse_args(int argc, const char *argv[]) {
const struct option long_options[] = { const struct option long_options[] = {
{ "load-snapshot", 1, NULL, 0 }, { "load-snapshot", 1, NULL, 0 },
{ "dump-wave", 0, NULL, 0 }, { "dump-wave", 0, NULL, 0 },
{ "no-snapshot", 0, NULL, 0 },
{ "seed", 1, NULL, 's' }, { "seed", 1, NULL, 's' },
{ "max-cycles", 1, NULL, 'C' }, { "max-cycles", 1, NULL, 'C' },
{ "max-instr", 1, NULL, 'I' }, { "max-instr", 1, NULL, 'I' },
...@@ -51,6 +53,7 @@ inline EmuArgs parse_args(int argc, const char *argv[]) { ...@@ -51,6 +53,7 @@ inline EmuArgs parse_args(int argc, const char *argv[]) {
switch (long_index) { switch (long_index) {
case 0: args.snapshot_path = optarg; continue; case 0: args.snapshot_path = optarg; continue;
case 1: args.enable_waveform = true; continue; case 1: args.enable_waveform = true; continue;
case 2: args.enable_snapshot = false; continue;
} }
// fall through // fall through
default: default:
...@@ -129,7 +132,7 @@ Emulator::~Emulator() { ...@@ -129,7 +132,7 @@ Emulator::~Emulator() {
ram_finish(); ram_finish();
#ifdef VM_SAVABLE #ifdef VM_SAVABLE
if (trapCode != STATE_GOODTRAP && trapCode != STATE_LIMIT_EXCEEDED) { if (args.enable_snapshot && trapCode != STATE_GOODTRAP && trapCode != STATE_LIMIT_EXCEEDED) {
printf("Saving snapshots to file system. Please wait.\n"); printf("Saving snapshots to file system. Please wait.\n");
snapshot_slot[0].save(); snapshot_slot[0].save();
snapshot_slot[1].save(); snapshot_slot[1].save();
...@@ -321,7 +324,7 @@ uint64_t Emulator::execute(uint64_t max_cycle, uint64_t max_instr) { ...@@ -321,7 +324,7 @@ uint64_t Emulator::execute(uint64_t max_cycle, uint64_t max_instr) {
} }
#ifdef VM_SAVABLE #ifdef VM_SAVABLE
static int snapshot_count = 0; static int snapshot_count = 0;
if (trapCode != STATE_GOODTRAP && t - lasttime_snapshot > 6000 * SNAPSHOT_INTERVAL) { if (args.enable_snapshot && trapCode != STATE_GOODTRAP && t - lasttime_snapshot > 6000 * SNAPSHOT_INTERVAL) {
// save snapshot every 60s // save snapshot every 60s
time_t now = time(NULL); time_t now = time(NULL);
snapshot_save(snapshot_filename(now)); snapshot_save(snapshot_filename(now));
......
...@@ -14,6 +14,7 @@ struct EmuArgs { ...@@ -14,6 +14,7 @@ struct EmuArgs {
const char *image; const char *image;
const char *snapshot_path; const char *snapshot_path;
bool enable_waveform; bool enable_waveform;
bool enable_snapshot;
EmuArgs() { EmuArgs() {
seed = 0; seed = 0;
...@@ -24,6 +25,7 @@ struct EmuArgs { ...@@ -24,6 +25,7 @@ struct EmuArgs {
snapshot_path = NULL; snapshot_path = NULL;
image = NULL; image = NULL;
enable_waveform = false; enable_waveform = false;
enable_snapshot = true;
} }
}; };
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册