Skip to content

Commit

Permalink
Add tracing for total instruction count
Browse files Browse the repository at this point in the history
  • Loading branch information
Mingle Chen committed Oct 7, 2022
1 parent f7417a1 commit c27dd7d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions trace_extra/memory_interceptor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ DynamorioTraceInterceptor::ThreadLocalState::ThreadLocalState(
}

io::filtering_ostream DynamorioTraceInterceptor::mem_logfile;
uint64_t DynamorioTraceInterceptor::instr_count = 0;

void DynamorioTraceInterceptor::OnTracePacket(InterceptorContext context)
{
Expand All @@ -57,6 +58,7 @@ void DynamorioTraceInterceptor::OnTracePacket(InterceptorContext context)
perfetto::protos::pbzero::Opcode::Decoder opcode(
instr.opcode_obj());
if (opcode.has_size()) {
++instr_count;
trace_entry_t entry;
entry.type = TRACE_TYPE_INSTR;
entry.addr = reinterpret_cast<addr_t>(instr.pc());
Expand Down
1 change: 1 addition & 0 deletions trace_extra/memory_interceptor.hh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class DynamorioTraceInterceptor

public:
static io::filtering_ostream mem_logfile;
static uint64_t instr_count;
~DynamorioTraceInterceptor() override = default;

struct ThreadLocalState
Expand Down
21 changes: 18 additions & 3 deletions trace_extra/trace_perfetto.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ std::unique_ptr<perfetto::TracingSession> session;
fs::path logfile("qemu_trace.pb");

/* perfetto interceptor trace file */
string mem_logfile_name = "mem_access.trace.gz";
string mem_logfile = "mem_trace.gz";

/* instrcution count file */
string instr_count_file;

/* enable perfetto interceptor */
bool enable_interceptor = false;
Expand Down Expand Up @@ -134,9 +137,15 @@ bool perfetto_start_tracing(void)
perfetto::TrackEvent::Register();

if (enable_interceptor) {
// hardcode instr_path for now
fs::path mem_logfile_path(mem_logfile);
instr_count_file =
mem_logfile_path.parent_path().parent_path().string() +
"/instr_count.txt";

DynamorioTraceInterceptor::mem_logfile.push(io::gzip_compressor());
DynamorioTraceInterceptor::mem_logfile.push(
io::file_descriptor_sink(mem_logfile_name));
io::file_descriptor_sink(mem_logfile));

// drcachesim needs a header in the file, so we create it here
trace_entry_t header{ .type = TRACE_TYPE_HEADER,
Expand Down Expand Up @@ -229,6 +238,12 @@ void perfetto_tracing_stop(void)
DynamorioTraceInterceptor::mem_logfile.write((char *)&footer,
sizeof(footer));
io::close(DynamorioTraceInterceptor::mem_logfile);

// store the number of instructions executed
ofstream outfile;
outfile.open(instr_count_file);
outfile << DynamorioTraceInterceptor::instr_count << std::endl;
outfile.close();
}
}

Expand Down Expand Up @@ -518,7 +533,7 @@ qemu_log_instr_perfetto_conf_categories(const char *category_str)

extern "C" void qemu_log_instr_perfetto_interceptor_logfile(const char *name)
{
mem_logfile_name = name;
mem_logfile = name;
}

extern "C" void qemu_log_instr_perfetto_enable_interceptor()
Expand Down

0 comments on commit c27dd7d

Please sign in to comment.