diff --git a/trace_extra/memory_interceptor.cc b/trace_extra/memory_interceptor.cc index f948d87d13..cbf3ffd1c6 100644 --- a/trace_extra/memory_interceptor.cc +++ b/trace_extra/memory_interceptor.cc @@ -38,6 +38,7 @@ DynamorioTraceInterceptor::ThreadLocalState::ThreadLocalState( } io::filtering_ostream DynamorioTraceInterceptor::mem_logfile; +uint64_t DynamorioTraceInterceptor::instr_count = 0; void DynamorioTraceInterceptor::OnTracePacket(InterceptorContext context) { @@ -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(instr.pc()); diff --git a/trace_extra/memory_interceptor.hh b/trace_extra/memory_interceptor.hh index b2f985d8e9..e9a8011bc9 100644 --- a/trace_extra/memory_interceptor.hh +++ b/trace_extra/memory_interceptor.hh @@ -46,6 +46,7 @@ class DynamorioTraceInterceptor public: static io::filtering_ostream mem_logfile; + static uint64_t instr_count; ~DynamorioTraceInterceptor() override = default; struct ThreadLocalState diff --git a/trace_extra/trace_perfetto.cc b/trace_extra/trace_perfetto.cc index af1e91352f..c6fe0c391b 100644 --- a/trace_extra/trace_perfetto.cc +++ b/trace_extra/trace_perfetto.cc @@ -71,7 +71,10 @@ std::unique_ptr 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; @@ -134,9 +137,13 @@ 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, @@ -229,6 +236,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(); } } @@ -518,7 +531,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()