Skip to content

Commit

Permalink
Print a more detailed progress for writing frame data.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 authored and thestr4ng3r committed Apr 10, 2024
1 parent 2f4de2b commit a0a023e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
5 changes: 5 additions & 0 deletions rz-tracetest/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ int main(int argc, const char *argv[]) {
ut64 stats[FRAME_CHECK_RESULT_COUNT] = {};
std::unique_ptr<frame> cur_frame = trace.get_frame();

printf("\nCompare frames...\n");
ut64 n = trace.get_num_frames();
ut64 total = 0;
while (cur_frame && !rz_cons_is_breaked() && count) {
std::unique_ptr<frame> next_frame = trace.end_of_trace() ? nullptr : trace.get_frame();
Expand All @@ -154,7 +156,10 @@ int main(int argc, const char *argv[]) {
res == FrameCheckResult::PostStateMismatch) {
break;
}
float done = 100.00f * (float) total / (float) n;
printf("\rFrames: %llu Done: %5.2f%%", n, done);
}
printf("\n");

printf("\n--------------------------------------\n");
bool all_succeeded = true;
Expand Down
15 changes: 14 additions & 1 deletion rz-tracetest/rzemu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ void RizinEmulator::SetMem(SerializedTrace::TraceContainerReader &trace) {
printf("Write frame bytes to memory...\n");
uint64_t i = 0;
trace.seek(0);
ut64 n = trace.get_num_frames();
ut64 total_written = 0;
// Trace which bytes were written, so we do not write them twice.
std::set<uint64_t> written = std::set<uint64_t>();

rz_io_cache_reset(core->io, RZ_PERM_R | RZ_PERM_W);
while (!trace.end_of_trace()) {
std::unique_ptr<frame> frame = trace.get_frame();
Expand All @@ -98,10 +103,18 @@ void RizinEmulator::SetMem(SerializedTrace::TraceContainerReader &trace) {
}
const std_frame &sf = frame.get()->std_frame();
ut64 pc = sf.address();

const uint8_t *data = (const ut8 *)sf.rawbytes().data();
ut32 size = sf.rawbytes().size();
float done = 100.00f * (float) i++ / (float) n;
printf("\rTotal frames: %lu Done: %5.2f%% (written: %lu kb)", n, done, total_written / 1000);

if (written.count(pc) != 0) {
continue;
}
written.emplace(pc);
rz_io_write_at(core->io, pc, data, size);
printf("\rFrame: %d", i++);
total_written += size;
}
trace.seek(0);
printf("\nDONE Write frame bytes to memory...\n");
Expand Down

0 comments on commit a0a023e

Please sign in to comment.