From b48eed0130852d40f437bfc80b457e4fd045efc3 Mon Sep 17 00:00:00 2001 From: edeiana Date: Wed, 10 Apr 2024 17:37:47 -0700 Subject: [PATCH 01/18] i#6751 trace_entry_t: pretty printer Skeleton for record_view, a new tool to visualize trace_entry_t records. Currently it prints the type of all trace_entry_t in a trace. Issue #6751 --- clients/drcachesim/CMakeLists.txt | 14 +- clients/drcachesim/analyzer_multi.cpp | 3 + clients/drcachesim/common/options.h | 1 + clients/drcachesim/tools/record_view.cpp | 147 ++++++++++++++++++ clients/drcachesim/tools/record_view.h | 95 +++++++++++ clients/drcachesim/tools/record_view_create.h | 58 +++++++ 6 files changed, 314 insertions(+), 4 deletions(-) create mode 100644 clients/drcachesim/tools/record_view.cpp create mode 100644 clients/drcachesim/tools/record_view.h create mode 100644 clients/drcachesim/tools/record_view_create.h diff --git a/clients/drcachesim/CMakeLists.txt b/clients/drcachesim/CMakeLists.txt index 75b366ed495..bbd19c229d7 100644 --- a/clients/drcachesim/CMakeLists.txt +++ b/clients/drcachesim/CMakeLists.txt @@ -165,6 +165,7 @@ add_exported_library(drmemtrace_opcode_mix STATIC tools/opcode_mix.cpp) add_exported_library(drmemtrace_syscall_mix STATIC tools/syscall_mix.cpp) add_exported_library(drmemtrace_view STATIC tools/view.cpp) add_exported_library(drmemtrace_func_view STATIC tools/func_view.cpp) +add_exported_library(drmemtrace_record_view STATIC tools/record_view.cpp) add_exported_library(drmemtrace_invariant_checker STATIC tools/invariant_checker.cpp) add_exported_library(drmemtrace_schedule_stats STATIC tools/schedule_stats.cpp) @@ -172,6 +173,7 @@ target_link_libraries(drmemtrace_invariant_checker drdecode) configure_DynamoRIO_standalone(drmemtrace_opcode_mix) configure_DynamoRIO_standalone(drmemtrace_view) +configure_DynamoRIO_standalone(drmemtrace_record_view) configure_DynamoRIO_standalone(drmemtrace_invariant_checker) # We combine the cache and TLB simulators as they share code already. @@ -276,8 +278,8 @@ configure_DynamoRIO_standalone(drcachesim) target_link_libraries(drcachesim drmemtrace_simulator drmemtrace_reuse_distance drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view - drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker - drmemtrace_schedule_stats drmemtrace_record_filter) + drmemtrace_record_view drmemtrace_raw2trace directory_iterator + drmemtrace_invariant_checker drmemtrace_schedule_stats drmemtrace_record_filter) if (UNIX) target_link_libraries(drcachesim dl) endif () @@ -357,6 +359,7 @@ install_client_nonDR_header(drmemtrace simulator/cache_simulator_create.h) install_client_nonDR_header(drmemtrace simulator/tlb_simulator_create.h) install_client_nonDR_header(drmemtrace tools/view_create.h) install_client_nonDR_header(drmemtrace tools/func_view_create.h) +install_client_nonDR_header(drmemtrace tools/record_view_create.h) # TODO i#6412: Create a separate directory for non-tracer headers so that # we can more cleanly separate tracer and raw2trace code. install_client_nonDR_header(drmemtrace tracer/raw2trace.h) @@ -578,6 +581,7 @@ restore_nonclient_flags(drmemtrace_opcode_mix) restore_nonclient_flags(drmemtrace_syscall_mix) restore_nonclient_flags(drmemtrace_view) restore_nonclient_flags(drmemtrace_func_view) +restore_nonclient_flags(drmemtrace_record_view) restore_nonclient_flags(drmemtrace_record_filter) restore_nonclient_flags(drmemtrace_analyzer) restore_nonclient_flags(drmemtrace_invariant_checker) @@ -644,6 +648,7 @@ add_win32_flags(drmemtrace_opcode_mix) add_win32_flags(drmemtrace_syscall_mix) add_win32_flags(drmemtrace_view) add_win32_flags(drmemtrace_func_view) +add_win32_flags(drmemtrace_record_view) add_win32_flags(drmemtrace_record_filter) add_win32_flags(drmemtrace_analyzer) add_win32_flags(drmemtrace_invariant_checker) @@ -821,8 +826,9 @@ if (BUILD_TESTS) drmemtrace_raw2trace drmemtrace_simulator drmemtrace_reuse_distance drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view - drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker - drmemtrace_schedule_stats drmemtrace_analyzer drmemtrace_record_filter) + drmemtrace_record_view drmemtrace_raw2trace directory_iterator + drmemtrace_invariant_checker drmemtrace_schedule_stats drmemtrace_analyzer + drmemtrace_record_filter) if (UNIX) target_link_libraries(tool.drcachesim.core_sharded dl) endif () diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index ca68fd2dcf8..1333e28763c 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -64,6 +64,7 @@ #include "tools/reuse_distance_create.h" #include "tools/reuse_time_create.h" #include "tools/view_create.h" +#include "tools/record_view_create.h" #include "tools/loader/external_config_file.h" #include "tools/loader/external_tool_creator.h" #include "tools/filter/record_filter_create.h" @@ -265,6 +266,8 @@ analyzer_multi_t::create_analysis_tool_from_options(const std::string &simulator } return func_view_tool_create(funclist_file_path, op_show_func_trace.get_value(), op_verbose.get_value()); + } else if (simulator_type == RECORD_VIEW) { + return record_view_tool_create(); } else if (simulator_type == INVARIANT_CHECKER) { return create_invariant_checker(); } else if (simulator_type == SCHEDULE_STATS) { diff --git a/clients/drcachesim/common/options.h b/clients/drcachesim/common/options.h index 096a45fe5b1..7944ff9ac57 100644 --- a/clients/drcachesim/common/options.h +++ b/clients/drcachesim/common/options.h @@ -49,6 +49,7 @@ #define SYSCALL_MIX "syscall_mix" #define VIEW "view" #define FUNC_VIEW "func_view" +#define RECORD_VIEW "record_view" #define INVARIANT_CHECKER "invariant_checker" #define SCHEDULE_STATS "schedule_stats" #define RECORD_FILTER "record_filter" diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp new file mode 100644 index 00000000000..e4fbb17e856 --- /dev/null +++ b/clients/drcachesim/tools/record_view.cpp @@ -0,0 +1,147 @@ +/* ********************************************************** + * Copyright (c) 2024 Google, Inc. All rights reserved. + * **********************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Google, Inc. nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +#include "record_view.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAS_ZLIB +# include "common/gzip_ostream.h" +#endif +#ifdef HAS_ZIP +# include "common/zipfile_ostream.h" +#endif +#include "memref.h" +#include "memtrace_stream.h" +#include "raw2trace_shared.h" +#include "trace_entry.h" +#include "utils.h" + +#undef VPRINT +#ifdef DEBUG +# define VPRINT(reader, level, ...) \ + do { \ + if ((reader)->verbosity_ >= (level)) { \ + fprintf(stderr, "%s ", (reader)->output_prefix_); \ + fprintf(stderr, __VA_ARGS__); \ + } \ + } while (0) +// clang-format off +# define UNUSED(x) /* nothing */ +// clang-format on +#else +# define VPRINT(reader, level, ...) /* nothing */ +# define UNUSED(x) ((void)(x)) +#endif + +namespace dynamorio { +namespace drmemtrace { + +record_analysis_tool_t * +record_view_tool_create(void) +{ + return new dynamorio::drmemtrace::record_view_t(); +} + +record_view_t::record_view_t() +{ +} + +record_view_t::~record_view_t() +{ +} + +bool +record_view_t::parallel_shard_supported() +{ + return false; +} + +std::string +record_view_t::initialize_shard_type(shard_type_t shard_type) +{ + return ""; +} + +void * +record_view_t::parallel_shard_init_stream(int shard_index, void *worker_data, + memtrace_stream_t *shard_stream) +{ + return shard_stream; +} + +bool +record_view_t::parallel_shard_exit(void *shard_data) +{ + return true; +} + +std::string +record_view_t::parallel_shard_error(void *shard_data) +{ + return ""; +} + +bool +record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entry) +{ + const char *trace_type_name = trace_type_names[entry.type]; + std::cerr << std::string(trace_type_name) << "\n"; + + return true; +} + +bool +record_view_t::process_memref(const trace_entry_t &entry) +{ + return parallel_shard_memref(NULL, entry); +} + +bool +record_view_t::print_results() +{ + return true; +} + +} // namespace drmemtrace +} // namespace dynamorio diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/record_view.h new file mode 100644 index 00000000000..3997498c24d --- /dev/null +++ b/clients/drcachesim/tools/record_view.h @@ -0,0 +1,95 @@ +/* ********************************************************** + * Copyright (c) 2024 Google, Inc. All rights reserved. + * **********************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Google, Inc. nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +#ifndef _RECORD_VIEW_H_ +#define _RECORD_VIEW_H_ 1 + +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "analysis_tool.h" +#include "archive_ostream.h" +#include "memref.h" +#include "memtrace_stream.h" +#include "raw2trace_shared.h" +#include "trace_entry.h" + +namespace dynamorio { +namespace drmemtrace { + +/** + * Analysis tool that prints #trace_entry_t records of an offline trace in human readable + * form. + */ +class record_view_t : public record_analysis_tool_t { +public: + record_view_t(); + + ~record_view_t() override; + + bool + process_memref(const trace_entry_t &entry) override; + + bool + print_results() override; + + bool + parallel_shard_supported() override; + + std::string + initialize_shard_type(shard_type_t shard_type) override; + + void * + parallel_shard_init_stream(int shard_index, void *worker_data, + memtrace_stream_t *shard_stream) override; + + bool + parallel_shard_exit(void *shard_data) override; + + bool + parallel_shard_memref(void *shard_data, const trace_entry_t &entry) override; + + std::string + parallel_shard_error(void *shard_data) override; +}; + +} // namespace drmemtrace +} // namespace dynamorio + +#endif /* _RECORD_VIEW_H_ */ diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h new file mode 100644 index 00000000000..1fde6d7f271 --- /dev/null +++ b/clients/drcachesim/tools/record_view_create.h @@ -0,0 +1,58 @@ +/* ********************************************************** + * Copyright (c) 2024 Google, Inc. All rights reserved. + * **********************************************************/ + +/* + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * * Neither the name of Google, Inc. nor the names of its contributors may be + * used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + */ + +/* record view tool creation */ + +#ifndef _RECORD_VIEW_CREATE_H_ +#define _RECORD_VIEW_CREATE_H_ 1 + +#include "analysis_tool.h" + +namespace dynamorio { +namespace drmemtrace { + +/** + * @file drmemtrace/record_view_create.h + * @brief DrMemtrace record view trace analysis tool creation. + */ + +/** + * Creates an analysis tool which prints out the the #trace_entry_t records in a trace + * file. + */ +analysis_tool_t * +record_view_tool_create(void); + +} // namespace drmemtrace +} // namespace dynamorio + +#endif /* _RECORD_VIEW_CREATE_H_ */ From 20db00bb19c78a76a470462198ec612fbc704993 Mon Sep 17 00:00:00 2001 From: edeiana Date: Wed, 10 Apr 2024 18:09:33 -0700 Subject: [PATCH 02/18] Added -sim_refs support to print only the first sim_refs records. --- clients/drcachesim/analyzer_multi.cpp | 2 +- clients/drcachesim/tools/record_view.cpp | 20 ++++++++++++++++--- clients/drcachesim/tools/record_view.h | 8 +++++++- clients/drcachesim/tools/record_view_create.h | 2 +- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index 1333e28763c..5fe58b8c735 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -267,7 +267,7 @@ analyzer_multi_t::create_analysis_tool_from_options(const std::string &simulator return func_view_tool_create(funclist_file_path, op_show_func_trace.get_value(), op_verbose.get_value()); } else if (simulator_type == RECORD_VIEW) { - return record_view_tool_create(); + return record_view_tool_create(op_sim_refs.get_value()); } else if (simulator_type == INVARIANT_CHECKER) { return create_invariant_checker(); } else if (simulator_type == SCHEDULE_STATS) { diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index e4fbb17e856..ff8b1212aff 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -78,12 +78,13 @@ namespace dynamorio { namespace drmemtrace { record_analysis_tool_t * -record_view_tool_create(void) +record_view_tool_create(uint64_t sim_refs) { - return new dynamorio::drmemtrace::record_view_t(); + return new dynamorio::drmemtrace::record_view_t(sim_refs); } -record_view_t::record_view_t() +record_view_t::record_view_t(uint64_t sim_refs) + : sim_refs_(sim_refs) { } @@ -91,6 +92,16 @@ record_view_t::~record_view_t() { } +bool +record_view_t::should_skip(void) +{ + if (sim_refs_ > 0) { + --sim_refs_; + return false; + } + return true; +} + bool record_view_t::parallel_shard_supported() { @@ -125,6 +136,9 @@ record_view_t::parallel_shard_error(void *shard_data) bool record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entry) { + if (should_skip()) + return true; + const char *trace_type_name = trace_type_names[entry.type]; std::cerr << std::string(trace_type_name) << "\n"; diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/record_view.h index 3997498c24d..1210fa2b555 100644 --- a/clients/drcachesim/tools/record_view.h +++ b/clients/drcachesim/tools/record_view.h @@ -59,7 +59,7 @@ namespace drmemtrace { */ class record_view_t : public record_analysis_tool_t { public: - record_view_t(); + record_view_t(uint64_t sim_refs); ~record_view_t() override; @@ -87,6 +87,12 @@ class record_view_t : public record_analysis_tool_t { std::string parallel_shard_error(void *shard_data) override; + +protected: + bool + should_skip(void); + + uint64_t sim_refs_; }; } // namespace drmemtrace diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h index 1fde6d7f271..7dbb0706c44 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/record_view_create.h @@ -50,7 +50,7 @@ namespace drmemtrace { * file. */ analysis_tool_t * -record_view_tool_create(void); +record_view_tool_create(uint64_t sim_refs); } // namespace drmemtrace } // namespace dynamorio From dd802348a48d7b8bb63510033ad6d2b0fa49e8ad Mon Sep 17 00:00:00 2001 From: edeiana Date: Thu, 11 Apr 2024 17:16:39 -0700 Subject: [PATCH 03/18] Added record_view to record_analysis_tool_t tool launcher. Printing the type before was working by sheer luck, due to layout of trace_entry_t and memref_t struct. --- clients/drcachesim/analyzer_multi.cpp | 4 ++-- clients/drcachesim/launcher.cpp | 3 ++- clients/drcachesim/tools/record_view.cpp | 6 ++++-- clients/drcachesim/tools/record_view_create.h | 2 +- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index 5fe58b8c735..0d44714e9b2 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -266,8 +266,6 @@ analyzer_multi_t::create_analysis_tool_from_options(const std::string &simulator } return func_view_tool_create(funclist_file_path, op_show_func_trace.get_value(), op_verbose.get_value()); - } else if (simulator_type == RECORD_VIEW) { - return record_view_tool_create(op_sim_refs.get_value()); } else if (simulator_type == INVARIANT_CHECKER) { return create_invariant_checker(); } else if (simulator_type == SCHEDULE_STATS) { @@ -338,6 +336,8 @@ record_analyzer_multi_t::create_analysis_tool_from_options( op_filter_cache_size.get_value(), op_filter_trace_types.get_value(), op_filter_marker_types.get_value(), op_trim_before_timestamp.get_value(), op_trim_after_timestamp.get_value(), op_verbose.get_value()); + } else if (simulator_type == RECORD_VIEW) { + return record_view_tool_create(op_sim_refs.get_value()); } ERRMSG("Usage error: unsupported record analyzer type \"%s\". Only " RECORD_FILTER " is supported.\n", diff --git a/clients/drcachesim/launcher.cpp b/clients/drcachesim/launcher.cpp index 3b61905ef6a..fc009d761f6 100644 --- a/clients/drcachesim/launcher.cpp +++ b/clients/drcachesim/launcher.cpp @@ -323,7 +323,8 @@ _tmain(int argc, const TCHAR *targv[]) FATAL_ERROR("invalid -outdir %s", op_outdir.get_value().c_str()); } } else { - if (op_simulator_type.get_value() == RECORD_FILTER) { + if (op_simulator_type.get_value() == RECORD_FILTER || + op_simulator_type.get_value() == RECORD_VIEW) { record_analyzer = new record_analyzer_multi_t; if (!*record_analyzer) { std::string error_string_ = record_analyzer->get_error_string(); diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index ff8b1212aff..2c72f3b2e5a 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -139,8 +139,10 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr if (should_skip()) return true; - const char *trace_type_name = trace_type_names[entry.type]; - std::cerr << std::string(trace_type_name) << "\n"; + std::string line = ""; + // trace_type_t type = (trace_type_t)entry.type; + // const char *trace_type_name = trace_type_names[type]; + std::cerr << entry.type << " " << entry.size << " " << entry.addr << "\n"; return true; } diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h index 7dbb0706c44..4e67733d65a 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/record_view_create.h @@ -49,7 +49,7 @@ namespace drmemtrace { * Creates an analysis tool which prints out the the #trace_entry_t records in a trace * file. */ -analysis_tool_t * +record_analysis_tool_t * record_view_tool_create(uint64_t sim_refs); } // namespace drmemtrace From b10b1a2a7c55a74b4df77776c3cca2abd34e8fa1 Mon Sep 17 00:00:00 2001 From: edeiana Date: Fri, 12 Apr 2024 20:14:21 -0700 Subject: [PATCH 04/18] Printing all info, although printing of markers can be improved. --- clients/drcachesim/common/trace_entry.cpp | 50 +++++++ clients/drcachesim/common/trace_entry.h | 2 + clients/drcachesim/tools/record_view.cpp | 130 ++++++++++++------ clients/drcachesim/tools/record_view.h | 9 -- clients/drcachesim/tools/record_view_create.h | 4 +- 5 files changed, 144 insertions(+), 51 deletions(-) diff --git a/clients/drcachesim/common/trace_entry.cpp b/clients/drcachesim/common/trace_entry.cpp index 2cc0036975f..9650aeee1c3 100644 --- a/clients/drcachesim/common/trace_entry.cpp +++ b/clients/drcachesim/common/trace_entry.cpp @@ -88,5 +88,55 @@ const char *const trace_type_names[] = { "untaken_jump", }; +const char *const trace_version_names[] = { + "", + "", + "trace_entry_version_no_kernel_pc", + "trace_entry_version_kernel_pc", + "trace_entry_version_encodings", + "trace_entry_version_branch_info", + "trace_entry_version_frequent_timestamps", +}; + +const char *const trace_marker_names[] = { + "trace_marker_type_kernel_event", + "trace_marker_type_kernel_xfer", + "trace_marker_type_timestamp", + "trace_marker_type_cpu_id", + "trace_marker_type_func_id", + "trace_marker_type_func_retaddr", + "trace_marker_type_func_arg", + "trace_marker_type_func_retval", + "trace_marker_type_split_value", + "trace_marker_type_filetype", + "trace_marker_type_cache_line_size", + "trace_marker_type_instruction_count", + "trace_marker_type_version", + "trace_marker_type_rseq_abort", + "trace_marker_type_window_id", + "trace_marker_type_physical_address", + "trace_marker_type_physical_address_not_available", + "trace_marker_type_virtual_address", + "trace_marker_type_page_size", + "trace_marker_type_syscall_idx", + "trace_marker_type_chunk_instr_count", + "trace_marker_type_chunk_footer", + "trace_marker_type_record_ordinal", + "trace_marker_type_filter_endpoint", + "trace_marker_type_rseq_entry", + "trace_marker_type_syscall", + "trace_marker_type_maybe_blocking_syscall", + "trace_marker_type_syscall_trace_start", + "trace_marker_type_syscall_trace_end", + "trace_marker_type_branch_target", + "trace_marker_type_syscall_failed", + "trace_marker_type_direct_thread_switch", + "trace_marker_type_core_wait", + "trace_marker_type_core_idle", + "trace_marker_type_context_switch_start", + "trace_marker_type_context_switch_end", + "trace_marker_type_vector_length", +}; + } // namespace drmemtrace } // namespace dynamorio diff --git a/clients/drcachesim/common/trace_entry.h b/clients/drcachesim/common/trace_entry.h index 49fd8528604..9a167019674 100644 --- a/clients/drcachesim/common/trace_entry.h +++ b/clients/drcachesim/common/trace_entry.h @@ -652,6 +652,8 @@ enum class func_trace_t : uint64_t { // VS2019 won't infer 64-bit with "enum {". }; extern const char *const trace_type_names[]; +extern const char *const trace_version_names[]; +extern const char *const trace_marker_names[]; /** * Returns whether the type represents an instruction fetch. diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index 2c72f3b2e5a..fa58fc596bf 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -32,47 +32,14 @@ #include "record_view.h" -#include -#include - #include -#include +#include #include -#include -#include +#include #include -#include -#include -#include - -#ifdef HAS_ZLIB -# include "common/gzip_ostream.h" -#endif -#ifdef HAS_ZIP -# include "common/zipfile_ostream.h" -#endif -#include "memref.h" + #include "memtrace_stream.h" -#include "raw2trace_shared.h" #include "trace_entry.h" -#include "utils.h" - -#undef VPRINT -#ifdef DEBUG -# define VPRINT(reader, level, ...) \ - do { \ - if ((reader)->verbosity_ >= (level)) { \ - fprintf(stderr, "%s ", (reader)->output_prefix_); \ - fprintf(stderr, __VA_ARGS__); \ - } \ - } while (0) -// clang-format off -# define UNUSED(x) /* nothing */ -// clang-format on -#else -# define VPRINT(reader, level, ...) /* nothing */ -# define UNUSED(x) ((void)(x)) -#endif namespace dynamorio { namespace drmemtrace { @@ -139,11 +106,94 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr if (should_skip()) return true; - std::string line = ""; - // trace_type_t type = (trace_type_t)entry.type; - // const char *trace_type_name = trace_type_names[type]; - std::cerr << entry.type << " " << entry.size << " " << entry.addr << "\n"; + trace_type_t trace_type = (trace_type_t)entry.type; + if (trace_type == TRACE_TYPE_INVALID) { + std::cerr << "ERROR: trace_entry_t invalid.\n"; + return false; + } + std::string trace_type_name = std::string(trace_type_names[trace_type]); + + /* Large if-else for all TRACE_TYPE_. Prints one line per trace_entry_t. + * In some cases we use some helper functions (e.g., type_is_instr()), which group + * similar TRACE_TYPE_ together, otherwise we compare trace_type against one or two + * specific TRACE_TYPE_ directly. + */ + if (trace_type == TRACE_TYPE_HEADER) { + trace_version_t trace_version = (trace_version_t)entry.addr; + std::string trace_version_name = std::string(trace_version_names[trace_version]); + std::cerr << trace_type_name << ", trace_version: " << trace_version_name << "\n"; + } else if (trace_type == TRACE_TYPE_FOOTER) { + std::cerr << trace_type_name << "\n"; + } else if ((trace_type == TRACE_TYPE_THREAD) || + (trace_type == TRACE_TYPE_THREAD_EXIT)) { + uint tid = (uint)entry.addr; + std::cerr << trace_type_name << ", tid: " << tid << "\n"; + } else if (trace_type == TRACE_TYPE_PID) { + uint pid = (uint)entry.addr; + std::cerr << trace_type_name << ", pid: " << pid << "\n"; + } else if (trace_type == TRACE_TYPE_MARKER) { + /* XXX i#6751: we have a lot of different types of markers; we should use some + * kind of dispatching mechanism to print a more informative output for each of + * them. For now we only do so only for a few markers here. + */ + trace_marker_type_t trace_marker_type = (trace_marker_type_t)entry.size; + std::string trace_marker_name = + std::string(trace_marker_names[trace_marker_type]); + addr_t trace_marker_value = entry.addr; + if (trace_marker_type == TRACE_MARKER_TYPE_FILETYPE) { + std::string file_type = + std::string(trace_arch_string((offline_file_type_t)trace_marker_value)); + std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name + << ", trace_marker_value: " << file_type << "\n"; + } else if (trace_marker_type == TRACE_MARKER_TYPE_VERSION) { + trace_version_t trace_version = (trace_version_t)entry.addr; + std::string trace_version_name = + std::string(trace_version_names[trace_version]); + std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name + << ", trace_marker_value: " << trace_version_name << "\n"; + } else { // For all remaining markers we print their value in hex. + std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name + << ", trace_marker_value: 0x" << std::hex << trace_marker_value + << std::dec << "\n"; + } + } else if (trace_type == TRACE_TYPE_ENCODING) { + unsigned short num_encoding_bytes = entry.size; + std::cerr << trace_type_name << ", num_encoding_bytes: " << num_encoding_bytes + << ", encoding_bytes: 0x" << std::hex; + /* Print encoding byte by byte (little-endian). + */ + for (int i = num_encoding_bytes - 1; i >= 0; --i) { + uint encoding_byte = static_cast(entry.encoding[i]); + std::cerr << encoding_byte; + } + std::cerr << std::dec << "\n"; + } else if (trace_type == TRACE_TYPE_INSTR_BUNDLE) { + unsigned short num_instructions_in_bundle = entry.size; + std::cerr << trace_type_name + << ", num_instructions_in_bundle: " << num_instructions_in_bundle + << ", instrs_length:"; + /* Print length of each instr in the bundle. + */ + for (int i = 0; i < num_instructions_in_bundle; ++i) { + unsigned char instr_length = entry.length[i]; + std::cerr << " " << instr_length; + } + std::cerr << "\n"; + } else if (type_is_instr(trace_type)) { + unsigned short instr_length = entry.size; + addr_t pc = entry.addr; + std::cerr << trace_type_name << ", length: " << instr_length << ", pc: 0x" + << std::hex << pc << std::dec << "\n"; + } else if (type_has_address(trace_type)) { // Includes no-fetch, prefetch, and flush. + unsigned short memref_size = entry.size; + addr_t memref_addr = entry.addr; + std::cerr << trace_type_name << ", memref_size: " << memref_size + << ", memref_addr: 0x" << std::hex << memref_addr << std::dec << "\n"; + } else { + std::cerr << "ERROR: unrecognized trace_entry_t.\n"; + return false; + } return true; } diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/record_view.h index 1210fa2b555..5da2d762484 100644 --- a/clients/drcachesim/tools/record_view.h +++ b/clients/drcachesim/tools/record_view.h @@ -35,19 +35,10 @@ #include -#include -#include -#include -#include #include -#include -#include #include "analysis_tool.h" -#include "archive_ostream.h" -#include "memref.h" #include "memtrace_stream.h" -#include "raw2trace_shared.h" #include "trace_entry.h" namespace dynamorio { diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h index 4e67733d65a..8f64ea94927 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/record_view_create.h @@ -46,8 +46,8 @@ namespace drmemtrace { */ /** - * Creates an analysis tool which prints out the the #trace_entry_t records in a trace - * file. + * Creates an analysis tool which prints out the #trace_entry_t records in a trace file + * to std::err. */ record_analysis_tool_t * record_view_tool_create(uint64_t sim_refs); From 00eefa090c4958c081ab4bac2b311b488992fa94 Mon Sep 17 00:00:00 2001 From: edeiana Date: Fri, 12 Apr 2024 20:28:29 -0700 Subject: [PATCH 05/18] Tentative fix for windows build. --- clients/drcachesim/tools/record_view.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index fa58fc596bf..c1f8dd6f1ec 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -44,6 +44,8 @@ namespace dynamorio { namespace drmemtrace { +typedef unsigned int uint; + record_analysis_tool_t * record_view_tool_create(uint64_t sim_refs) { @@ -135,7 +137,7 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr } else if (trace_type == TRACE_TYPE_MARKER) { /* XXX i#6751: we have a lot of different types of markers; we should use some * kind of dispatching mechanism to print a more informative output for each of - * them. For now we only do so only for a few markers here. + * them. For now we do so only for a few markers here. */ trace_marker_type_t trace_marker_type = (trace_marker_type_t)entry.size; std::string trace_marker_name = From 793f6a40117ba1ce5ba9a3d6fe9a6620cb86bf04 Mon Sep 17 00:00:00 2001 From: edeiana Date: Thu, 18 Apr 2024 11:27:36 -0700 Subject: [PATCH 06/18] Added skip_refs functionality. --- clients/drcachesim/analyzer_multi.cpp | 2 +- clients/drcachesim/tools/record_view.cpp | 13 +++++++++---- clients/drcachesim/tools/record_view.h | 3 ++- clients/drcachesim/tools/record_view_create.h | 7 ++++--- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index bb4a54fcc22..f62d15b0a39 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -337,7 +337,7 @@ record_analyzer_multi_t::create_analysis_tool_from_options( op_filter_marker_types.get_value(), op_trim_before_timestamp.get_value(), op_trim_after_timestamp.get_value(), op_verbose.get_value()); } else if (simulator_type == RECORD_VIEW) { - return record_view_tool_create(op_sim_refs.get_value()); + return record_view_tool_create(op_skip_refs.get_value(), op_sim_refs.get_value()); } ERRMSG("Usage error: unsupported record analyzer type \"%s\". Only " RECORD_FILTER " is supported.\n", diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index c1f8dd6f1ec..5f2e86d2279 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -47,13 +47,14 @@ namespace drmemtrace { typedef unsigned int uint; record_analysis_tool_t * -record_view_tool_create(uint64_t sim_refs) +record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs) { - return new dynamorio::drmemtrace::record_view_t(sim_refs); + return new dynamorio::drmemtrace::record_view_t(skip_refs, sim_refs); } -record_view_t::record_view_t(uint64_t sim_refs) - : sim_refs_(sim_refs) +record_view_t::record_view_t(uint64_t skip_refs, uint64_t sim_refs) + : skip_refs_(skip_refs) + , sim_refs_(sim_refs) { } @@ -64,6 +65,10 @@ record_view_t::~record_view_t() bool record_view_t::should_skip(void) { + if (skip_refs_ > 0) { + --skip_refs_; + return true; + } if (sim_refs_ > 0) { --sim_refs_; return false; diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/record_view.h index 5da2d762484..0e936b686ed 100644 --- a/clients/drcachesim/tools/record_view.h +++ b/clients/drcachesim/tools/record_view.h @@ -50,7 +50,7 @@ namespace drmemtrace { */ class record_view_t : public record_analysis_tool_t { public: - record_view_t(uint64_t sim_refs); + record_view_t(uint64_t skip_refs, uint64_t sim_refs); ~record_view_t() override; @@ -83,6 +83,7 @@ class record_view_t : public record_analysis_tool_t { bool should_skip(void); + uint64_t skip_refs_; uint64_t sim_refs_; }; diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h index 8f64ea94927..daac8ff5578 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/record_view_create.h @@ -32,10 +32,11 @@ /* record view tool creation */ +#include #ifndef _RECORD_VIEW_CREATE_H_ -#define _RECORD_VIEW_CREATE_H_ 1 +# define _RECORD_VIEW_CREATE_H_ 1 -#include "analysis_tool.h" +# include "analysis_tool.h" namespace dynamorio { namespace drmemtrace { @@ -50,7 +51,7 @@ namespace drmemtrace { * to std::err. */ record_analysis_tool_t * -record_view_tool_create(uint64_t sim_refs); +record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs); } // namespace drmemtrace } // namespace dynamorio From c7881a691f2d24a35339d9b7e300cff9735c0cd8 Mon Sep 17 00:00:00 2001 From: edeiana Date: Thu, 18 Apr 2024 12:58:29 -0700 Subject: [PATCH 07/18] Fixed comment typo: std::err -> std::cerr. --- clients/drcachesim/tools/record_view_create.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/record_view_create.h index daac8ff5578..f9fff04b524 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/record_view_create.h @@ -48,7 +48,7 @@ namespace drmemtrace { /** * Creates an analysis tool which prints out the #trace_entry_t records in a trace file - * to std::err. + * to std::cerr. */ record_analysis_tool_t * record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs); From b3a3d386eb9fed5149a6d67e2e088e8d6d92de49 Mon Sep 17 00:00:00 2001 From: edeiana Date: Fri, 19 Apr 2024 20:24:33 -0700 Subject: [PATCH 08/18] Added string representation of TRACE_MARKER_TYPE_RESERVED_END. --- clients/drcachesim/common/trace_entry.cpp | 63 +++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/clients/drcachesim/common/trace_entry.cpp b/clients/drcachesim/common/trace_entry.cpp index 9650aeee1c3..72f435c4385 100644 --- a/clients/drcachesim/common/trace_entry.cpp +++ b/clients/drcachesim/common/trace_entry.cpp @@ -136,6 +136,69 @@ const char *const trace_marker_names[] = { "trace_marker_type_context_switch_start", "trace_marker_type_context_switch_end", "trace_marker_type_vector_length", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_unused", + "trace_marker_type_reserved_end", }; } // namespace drmemtrace From 2af0d6704bb08f49a3e5e7d6e0863847c1adb22b Mon Sep 17 00:00:00 2001 From: edeiana Date: Mon, 22 Apr 2024 18:20:54 -0700 Subject: [PATCH 09/18] Improved names for string representation of enums. --- clients/drcachesim/common/trace_entry.cpp | 215 +++++++++++----------- 1 file changed, 108 insertions(+), 107 deletions(-) diff --git a/clients/drcachesim/common/trace_entry.cpp b/clients/drcachesim/common/trace_entry.cpp index 72f435c4385..e15ca9e2d40 100644 --- a/clients/drcachesim/common/trace_entry.cpp +++ b/clients/drcachesim/common/trace_entry.cpp @@ -35,6 +35,8 @@ namespace dynamorio { namespace drmemtrace { +/* Keep synched with trace_type_t enum in trace_entry.h. + */ const char *const trace_type_names[] = { "read", "write", @@ -88,117 +90,116 @@ const char *const trace_type_names[] = { "untaken_jump", }; +/* Keep synched with trace_version_t enum in trace_entry.h. + */ const char *const trace_version_names[] = { - "", - "", - "trace_entry_version_no_kernel_pc", - "trace_entry_version_kernel_pc", - "trace_entry_version_encodings", - "trace_entry_version_branch_info", - "trace_entry_version_frequent_timestamps", + "", "", "no_kernel_pc", "kernel_pc", + "encodings", "branch_info", "frequent_timestamps", }; +/* Keep synched with trace_marker_type_t enum in trace_entry.h. + */ const char *const trace_marker_names[] = { - "trace_marker_type_kernel_event", - "trace_marker_type_kernel_xfer", - "trace_marker_type_timestamp", - "trace_marker_type_cpu_id", - "trace_marker_type_func_id", - "trace_marker_type_func_retaddr", - "trace_marker_type_func_arg", - "trace_marker_type_func_retval", - "trace_marker_type_split_value", - "trace_marker_type_filetype", - "trace_marker_type_cache_line_size", - "trace_marker_type_instruction_count", - "trace_marker_type_version", - "trace_marker_type_rseq_abort", - "trace_marker_type_window_id", - "trace_marker_type_physical_address", - "trace_marker_type_physical_address_not_available", - "trace_marker_type_virtual_address", - "trace_marker_type_page_size", - "trace_marker_type_syscall_idx", - "trace_marker_type_chunk_instr_count", - "trace_marker_type_chunk_footer", - "trace_marker_type_record_ordinal", - "trace_marker_type_filter_endpoint", - "trace_marker_type_rseq_entry", - "trace_marker_type_syscall", - "trace_marker_type_maybe_blocking_syscall", - "trace_marker_type_syscall_trace_start", - "trace_marker_type_syscall_trace_end", - "trace_marker_type_branch_target", - "trace_marker_type_syscall_failed", - "trace_marker_type_direct_thread_switch", - "trace_marker_type_core_wait", - "trace_marker_type_core_idle", - "trace_marker_type_context_switch_start", - "trace_marker_type_context_switch_end", - "trace_marker_type_vector_length", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_unused", - "trace_marker_type_reserved_end", + "kernel_event", + "kernel_xfer", + "timestamp", + "cpu_id", + "func_id", + "func_retaddr", + "func_arg", + "func_retval", + "split_value", + "filetype", + "cache_line_size", + "instruction_count", + "version", + "rseq_abort", + "window_id", + "physical_address", + "physical_address_not_available", + "virtual_address", + "page_size", + "syscall_idx", + "chunk_instr_count", + "chunk_footer", + "record_ordinal", + "filter_endpoint", + "rseq_entry", + "syscall", + "maybe_blocking_syscall", + "syscall_trace_start", + "syscall_trace_end", + "branch_target", + "syscall_failed", + "direct_thread_switch", + "core_wait", + "core_idle", + "context_switch_start", + "context_switch_end", + "vector_length", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "unused", + "reserved_end", }; } // namespace drmemtrace From 8b1ef16b39e86821f6de9cceb5fad8bc69f27bab Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 20:04:53 -0700 Subject: [PATCH 10/18] Now sharing code with view.cpp when printing markers. --- clients/drcachesim/common/trace_entry.cpp | 201 +++++++++++----------- clients/drcachesim/common/trace_entry.h | 114 ++++++++++++ clients/drcachesim/tools/record_view.cpp | 60 +++---- clients/drcachesim/tools/view.cpp | 150 +++------------- 4 files changed, 261 insertions(+), 264 deletions(-) diff --git a/clients/drcachesim/common/trace_entry.cpp b/clients/drcachesim/common/trace_entry.cpp index e15ca9e2d40..777c00fb9a5 100644 --- a/clients/drcachesim/common/trace_entry.cpp +++ b/clients/drcachesim/common/trace_entry.cpp @@ -100,106 +100,107 @@ const char *const trace_version_names[] = { /* Keep synched with trace_marker_type_t enum in trace_entry.h. */ const char *const trace_marker_names[] = { - "kernel_event", - "kernel_xfer", - "timestamp", - "cpu_id", - "func_id", - "func_retaddr", - "func_arg", - "func_retval", - "split_value", - "filetype", - "cache_line_size", - "instruction_count", - "version", - "rseq_abort", - "window_id", - "physical_address", - "physical_address_not_available", - "virtual_address", - "page_size", - "syscall_idx", - "chunk_instr_count", - "chunk_footer", - "record_ordinal", - "filter_endpoint", - "rseq_entry", - "syscall", - "maybe_blocking_syscall", - "syscall_trace_start", - "syscall_trace_end", - "branch_target", - "syscall_failed", - "direct_thread_switch", - "core_wait", - "core_idle", - "context_switch_start", - "context_switch_end", - "vector_length", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "unused", - "reserved_end", + "marker: kernel xfer", /* TRACE_MARKER_TYPE_KERNEL_EVENT */ + "marker: syscall xfer", /* TRACE_MARKER_TYPE_KERNEL_XFER */ + "marker: timestamp", /* TRACE_MARKER_TYPE_TIMESTAMP */ + "marker: cpu id", /* TRACE_MARKER_TYPE_CPU_ID */ + "marker: function", /* TRACE_MARKER_TYPE_FUNC_ID */ + "marker: function return address", /* TRACE_MARKER_TYPE_FUNC_RETADDR */ + "marker: function argument", /* TRACE_MARKER_TYPE_FUNC_ARG */ + "marker: function return value", /* TRACE_MARKER_TYPE_FUNC_RETVAL */ + "marker: split value", /* TRACE_MARKER_TYPE_SPLIT_VALUE */ + "marker: filetype", /* TRACE_MARKER_TYPE_FILETYPE */ + "marker: cache line size", /* TRACE_MARKER_TYPE_CACHE_LINE_SIZE */ + "marker: instruction count", /* TRACE_MARKER_TYPE_INSTRUCTION_COUNT */ + "marker: version", /* TRACE_MARKER_TYPE_VERSION */ + "marker: rseq abort", /* TRACE_MARKER_TYPE_RSEQ_ABORT */ + "marker: window", /* TRACE_MARKER_TYPE_WINDOW_ID */ + "marker: physical address", /* TRACE_MARKER_TYPE_PHYSICAL_ADDRESS */ + "marker: physical address not available", /* TRACE_MARKER_TYPE_PHYSICAL_ADDRESS_NOT_ + AVAILABLE */ + "marker: virtual address", /* TRACE_MARKER_TYPE_VIRTUAL_ADDRESS */ + "marker: page size", /* TRACE_MARKER_TYPE_PAGE_SIZE */ + "marker: system call idx", /* TRACE_MARKER_TYPE_SYSCALL_IDX */ + "marker: chunk instruction count", /* TRACE_MARKER_TYPE_CHUNK_INSTR_COUNT */ + "marker: chunk footer", /* TRACE_MARKER_TYPE_CHUNK_FOOTER */ + "marker: record ordinal", /* TRACE_MARKER_TYPE_RECORD_ORDINAL */ + "marker: filter endpoint", /* TRACE_MARKER_TYPE_FILTER_ENDPOINT */ + "marker: rseq entry", /* TRACE_MARKER_TYPE_RSEQ_ENTRY */ + "marker: system call", /* TRACE_MARKER_TYPE_SYSCALL */ + "marker: maybe-blocking system call", /* TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL */ + "marker: trace start for system call", /* TRACE_MARKER_TYPE_SYSCALL_TRACE_START */ + "marker: trace end for system call", /* TRACE_MARKER_TYPE_SYSCALL_TRACE_END */ + "marker: indirect branch target", /* TRACE_MARKER_TYPE_BRANCH_TARGET */ + "marker: system call failed", /* TRACE_MARKER_TYPE_SYSCALL_FAILED */ + "marker: direct switch to thread", /* TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH */ + "marker: wait for another core", /* TRACE_MARKER_TYPE_CORE_WAIT */ + "marker: core is idle", /* TRACE_MARKER_TYPE_CORE_IDLE */ + "marker: trace start for context switch", /* TRACE_MARKER_TYPE_CONTEXT_SWITCH_START */ + "marker: trace end for context switch", /* TRACE_MARKER_TYPE_CONTEXT_SWITCH_END */ + "marker: vector length", /* TRACE_MARKER_TYPE_VECTOR_LENGTH */ + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: unused", + "marker: reserved end", /* TRACE_MARKER_TYPE_RESERVED_END */ }; } // namespace drmemtrace diff --git a/clients/drcachesim/common/trace_entry.h b/clients/drcachesim/common/trace_entry.h index 9a167019674..5d334192082 100644 --- a/clients/drcachesim/common/trace_entry.h +++ b/clients/drcachesim/common/trace_entry.h @@ -44,6 +44,8 @@ #define _TRACE_ENTRY_H_ 1 #include +#include +#include #include #include @@ -985,6 +987,118 @@ trace_arch_string(offline_file_type_t type) : "unspecified"))); } +static inline std::string +trace_marker_type_value_as_string(trace_marker_type_t marker_type, uintptr_t marker_value) +{ + std::stringstream ss; + const char *marker_name = trace_marker_names[marker_type]; + switch (marker_type) { + /* Handle all the cases where marker_value doesn't matter. + */ + case TRACE_MARKER_TYPE_FILTER_ENDPOINT: + case TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL: + case TRACE_MARKER_TYPE_CORE_WAIT: + case TRACE_MARKER_TYPE_CORE_IDLE: ss << "<" << marker_name << ">\n"; break; + + /* Handle all the simple cases where we simply print . + */ + case TRACE_MARKER_TYPE_TIMESTAMP: + case TRACE_MARKER_TYPE_CPU_ID: + case TRACE_MARKER_TYPE_INSTRUCTION_COUNT: + case TRACE_MARKER_TYPE_CACHE_LINE_SIZE: + case TRACE_MARKER_TYPE_PAGE_SIZE: + case TRACE_MARKER_TYPE_CHUNK_INSTR_COUNT: + case TRACE_MARKER_TYPE_SYSCALL: + case TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH: + case TRACE_MARKER_TYPE_WINDOW_ID: + case TRACE_MARKER_TYPE_SYSCALL_IDX: + ss << "<" << marker_name << " " << marker_value << ">\n"; + break; + /* Handle all the simple cases where we simply print . + */ + case TRACE_MARKER_TYPE_FUNC_RETADDR: + case TRACE_MARKER_TYPE_FUNC_ARG: + case TRACE_MARKER_TYPE_FUNC_RETVAL: + case TRACE_MARKER_TYPE_RECORD_ORDINAL: + case TRACE_MARKER_TYPE_SPLIT_VALUE: + case TRACE_MARKER_TYPE_BRANCH_TARGET: + ss << "<" << marker_name << " 0x" << std::hex << marker_value << std::dec + << ">\n"; + break; + /* Handle all remaining cases where we want to print a more informative output. + */ + case TRACE_MARKER_TYPE_SYSCALL_TRACE_START: + case TRACE_MARKER_TYPE_SYSCALL_TRACE_END: + ss << "<" << marker_name << " number " << marker_value << ">\n"; + break; + case TRACE_MARKER_TYPE_CONTEXT_SWITCH_START: + case TRACE_MARKER_TYPE_CONTEXT_SWITCH_END: + ss << "<" << marker_name << " type " << marker_value << ">\n"; + break; + /* We don't have a way to know the trace version here. This might be an offset, + * but we don't make any distinction. + */ + case TRACE_MARKER_TYPE_KERNEL_XFER: + case TRACE_MARKER_TYPE_KERNEL_EVENT: + ss << "<" << marker_name << " from 0x" << std::hex << marker_value << std::dec + << ">\n"; + break; + case TRACE_MARKER_TYPE_VERSION: + ss << "<" << marker_name << " " << static_cast(marker_value) << " " + << trace_version_names[marker_value] << ">\n"; + break; + case TRACE_MARKER_TYPE_FILETYPE: + ss << "<" << marker_name << " 0x" << std::hex + << static_cast(marker_value) << std::dec << " " + << trace_arch_string((offline_file_type_t)marker_value) << ">\n"; + break; + case TRACE_MARKER_TYPE_RSEQ_ABORT: + ss << "<" << marker_name << " from 0x" << std::hex << marker_value << std::dec + << " to handler>\n"; + break; + case TRACE_MARKER_TYPE_RSEQ_ENTRY: + ss << "<" << marker_name << " with end at 0x" << std::hex << marker_value + << std::dec << ">\n"; + break; + case TRACE_MARKER_TYPE_CHUNK_FOOTER: + ss << "<" << marker_name << " #" << marker_value << ">\n"; + break; + case TRACE_MARKER_TYPE_PHYSICAL_ADDRESS: + ss << "<" << marker_name << " for following virtual: 0x" << std::hex + << marker_value << std::dec << ">\n"; + break; + case TRACE_MARKER_TYPE_VIRTUAL_ADDRESS: + ss << "<" << marker_name << " for prior physical: 0x" << std::hex << marker_value + << std::dec << ">\n"; + break; + case TRACE_MARKER_TYPE_PHYSICAL_ADDRESS_NOT_AVAILABLE: + ss << "<" << marker_name << " for 0x" << std::hex << marker_value << std::dec + << ">\n"; + break; + case TRACE_MARKER_TYPE_FUNC_ID: + if (marker_value >= + static_cast(func_trace_t::TRACE_FUNC_ID_SYSCALL_BASE)) { + ss << "<" << marker_name << "==syscall #" + << (marker_value - + static_cast(func_trace_t::TRACE_FUNC_ID_SYSCALL_BASE)) + << ">\n"; + } else { + ss << "<" << marker_name << " #" << marker_value << ">\n"; + } + break; + case TRACE_MARKER_TYPE_SYSCALL_FAILED: + ss << "<" << marker_name << ": " << marker_value << ">\n"; + break; + case TRACE_MARKER_TYPE_VECTOR_LENGTH: + ss << "<" << marker_name << " " << marker_value << " bytes>\n"; + break; + default: + ss << "\n"; + break; + } + return ss.str(); +} + /* We have non-client targets including this header that do not include API * headers defining IF_X86_ELSE, etc. Those don't need this function so we * simply exclude them. diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index 5f2e86d2279..f5fbdf4926e 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -129,44 +129,21 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr if (trace_type == TRACE_TYPE_HEADER) { trace_version_t trace_version = (trace_version_t)entry.addr; std::string trace_version_name = std::string(trace_version_names[trace_version]); - std::cerr << trace_type_name << ", trace_version: " << trace_version_name << "\n"; + std::cerr << "<" << trace_type_name << ", trace_version: " << trace_version + << " == " << trace_version_name << ">\n"; } else if (trace_type == TRACE_TYPE_FOOTER) { - std::cerr << trace_type_name << "\n"; + std::cerr << "<" << trace_type_name << ">\n"; } else if ((trace_type == TRACE_TYPE_THREAD) || (trace_type == TRACE_TYPE_THREAD_EXIT)) { uint tid = (uint)entry.addr; - std::cerr << trace_type_name << ", tid: " << tid << "\n"; + std::cerr << "<" << trace_type_name << ", tid: " << tid << ">\n"; } else if (trace_type == TRACE_TYPE_PID) { uint pid = (uint)entry.addr; - std::cerr << trace_type_name << ", pid: " << pid << "\n"; - } else if (trace_type == TRACE_TYPE_MARKER) { - /* XXX i#6751: we have a lot of different types of markers; we should use some - * kind of dispatching mechanism to print a more informative output for each of - * them. For now we do so only for a few markers here. - */ - trace_marker_type_t trace_marker_type = (trace_marker_type_t)entry.size; - std::string trace_marker_name = - std::string(trace_marker_names[trace_marker_type]); - addr_t trace_marker_value = entry.addr; - if (trace_marker_type == TRACE_MARKER_TYPE_FILETYPE) { - std::string file_type = - std::string(trace_arch_string((offline_file_type_t)trace_marker_value)); - std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name - << ", trace_marker_value: " << file_type << "\n"; - } else if (trace_marker_type == TRACE_MARKER_TYPE_VERSION) { - trace_version_t trace_version = (trace_version_t)entry.addr; - std::string trace_version_name = - std::string(trace_version_names[trace_version]); - std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name - << ", trace_marker_value: " << trace_version_name << "\n"; - } else { // For all remaining markers we print their value in hex. - std::cerr << trace_type_name << ", trace_marker_type: " << trace_marker_name - << ", trace_marker_value: 0x" << std::hex << trace_marker_value - << std::dec << "\n"; - } + std::cerr << "<" << trace_type_name << ", pid: " << pid << ">\n"; } else if (trace_type == TRACE_TYPE_ENCODING) { unsigned short num_encoding_bytes = entry.size; - std::cerr << trace_type_name << ", num_encoding_bytes: " << num_encoding_bytes + std::cerr << "<" << trace_type_name + << ", num_encoding_bytes: " << num_encoding_bytes << ", encoding_bytes: 0x" << std::hex; /* Print encoding byte by byte (little-endian). */ @@ -174,10 +151,10 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr uint encoding_byte = static_cast(entry.encoding[i]); std::cerr << encoding_byte; } - std::cerr << std::dec << "\n"; + std::cerr << std::dec << ">\n"; } else if (trace_type == TRACE_TYPE_INSTR_BUNDLE) { unsigned short num_instructions_in_bundle = entry.size; - std::cerr << trace_type_name + std::cerr << "<" << trace_type_name << ", num_instructions_in_bundle: " << num_instructions_in_bundle << ", instrs_length:"; /* Print length of each instr in the bundle. @@ -186,19 +163,26 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr unsigned char instr_length = entry.length[i]; std::cerr << " " << instr_length; } - std::cerr << "\n"; + std::cerr << ">\n"; } else if (type_is_instr(trace_type)) { unsigned short instr_length = entry.size; addr_t pc = entry.addr; - std::cerr << trace_type_name << ", length: " << instr_length << ", pc: 0x" - << std::hex << pc << std::dec << "\n"; + std::cerr << "<" << trace_type_name << ", length: " << instr_length << ", pc: 0x" + << std::hex << pc << std::dec << ">\n"; } else if (type_has_address(trace_type)) { // Includes no-fetch, prefetch, and flush. unsigned short memref_size = entry.size; addr_t memref_addr = entry.addr; - std::cerr << trace_type_name << ", memref_size: " << memref_size - << ", memref_addr: 0x" << std::hex << memref_addr << std::dec << "\n"; + std::cerr << "<" << trace_type_name << ", memref_size: " << memref_size + << ", memref_addr: 0x" << std::hex << memref_addr << std::dec << ">\n"; + /* trace_entry_t is a marker. Print marker type and value accordingly. + */ + } else if (trace_type == TRACE_TYPE_MARKER) { + trace_marker_type_t trace_marker_type = (trace_marker_type_t)entry.size; + uintptr_t trace_marker_value = static_cast(entry.addr); + std::cerr << trace_marker_type_value_as_string(trace_marker_type, + trace_marker_value); } else { - std::cerr << "ERROR: unrecognized trace_entry_t.\n"; + std::cerr << "ERROR: unrecognized trace_entry_t: " << trace_type << ".\n"; return false; } return true; diff --git a/clients/drcachesim/tools/view.cpp b/clients/drcachesim/tools/view.cpp index 2d7391dcee6..50502340c0a 100644 --- a/clients/drcachesim/tools/view.cpp +++ b/clients/drcachesim/tools/view.cpp @@ -249,14 +249,16 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) if (trace_version_ != -1) { // Old versions may not have a version marker. if (!should_skip(memstream, memref)) { print_prefix(memstream, memref, version_record_ord_); - std::cerr << "\n"; + const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_VERSION]; + std::cerr << "<" << marker_name << " " << trace_version_ << ">\n"; } } if (filetype_ != -1) { // Handle old/malformed versions. if (!should_skip(memstream, memref)) { print_prefix(memstream, memref, filetype_record_ord_); - std::cerr << "\n"; + const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_FILETYPE]; + std::cerr << "<" << marker_name << " 0x" << std::hex << filetype_ + << std::dec << ">\n"; } } } @@ -274,16 +276,19 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) -1); // Already incremented for timestamp above. } if (timestamp_ > 0) { - std::cerr << "\n"; + const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP]; + std::cerr << "<" << marker_name << " " << timestamp_ << ">\n"; timestamp_ = 0; print_prefix(memstream, memref); } - std::cerr << "\n"; + const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_WINDOW_ID]; + std::cerr << "<" << marker_name << " " << memref.marker.marker_value << ">\n"; last_window_[memref.marker.tid] = memref.marker.marker_value; } if (timestamp_ > 0) { print_prefix(memstream, memref, timestamp_record_ord_); - std::cerr << "\n"; + const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP]; + std::cerr << "<" << marker_name << " " << timestamp_ << ">\n"; timestamp_ = 0; } } @@ -293,6 +298,7 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) } if (memref.marker.type == TRACE_TYPE_MARKER) { + const char *marker_name = trace_marker_names[memref.marker.marker_type]; switch (memref.marker.marker_type) { case TRACE_MARKER_TYPE_VERSION: // Handled above. @@ -303,6 +309,9 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) case TRACE_MARKER_TYPE_TIMESTAMP: // Handled above. break; + case TRACE_MARKER_TYPE_WINDOW_ID: + // Handled above. + break; case TRACE_MARKER_TYPE_CPU_ID: // We include the thread ID here under the assumption that we will always // see a cpuid marker on a thread switch. To avoid that assumption @@ -314,142 +323,31 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) case TRACE_MARKER_TYPE_KERNEL_EVENT: if (trace_version_ <= TRACE_ENTRY_VERSION_NO_KERNEL_PC) { // Legacy traces just have the module offset. - std::cerr << "\n"; } else { - std::cerr << "\n"; } break; - case TRACE_MARKER_TYPE_RSEQ_ABORT: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_RSEQ_ENTRY: - std::cerr << "\n"; - break; case TRACE_MARKER_TYPE_KERNEL_XFER: if (trace_version_ <= TRACE_ENTRY_VERSION_NO_KERNEL_PC) { // Legacy traces just have the module offset. - std::cerr << "\n"; } else { - std::cerr << "\n"; } break; - case TRACE_MARKER_TYPE_INSTRUCTION_COUNT: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CACHE_LINE_SIZE: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_PAGE_SIZE: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CHUNK_INSTR_COUNT: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CHUNK_FOOTER: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_FILTER_ENDPOINT: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_PHYSICAL_ADDRESS: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_VIRTUAL_ADDRESS: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_PHYSICAL_ADDRESS_NOT_AVAILABLE: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_FUNC_ID: - if (memref.marker.marker_value >= - static_cast(func_trace_t::TRACE_FUNC_ID_SYSCALL_BASE)) { - std::cerr << "( - func_trace_t::TRACE_FUNC_ID_SYSCALL_BASE)) - << ">\n"; - } else { - std::cerr << "\n"; - } - break; - case TRACE_MARKER_TYPE_FUNC_RETADDR: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_FUNC_ARG: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_FUNC_RETVAL: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_SYSCALL_FAILED: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_RECORD_ORDINAL: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_SYSCALL: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_DIRECT_THREAD_SWITCH: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_WINDOW_ID: - // Handled above. - break; - case TRACE_MARKER_TYPE_SYSCALL_TRACE_START: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_SYSCALL_TRACE_END: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CONTEXT_SWITCH_START: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CONTEXT_SWITCH_END: - std::cerr << "\n"; break; - case TRACE_MARKER_TYPE_BRANCH_TARGET: - // These are not expected to be visible (since the reader adds them - // to memref.instr.indirect_branch_target) but we handle nonetheless. - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CORE_WAIT: - std::cerr << "\n"; - break; - case TRACE_MARKER_TYPE_CORE_IDLE: std::cerr << "\n"; break; - case TRACE_MARKER_TYPE_VECTOR_LENGTH: - std::cerr << "\n"; - break; default: - std::cerr << "\n"; + std::cerr << trace_marker_type_value_as_string(memref.marker.marker_type, + memref.marker.marker_value); break; } return true; From 73f82951f6271c30485bdc65f6ddca0368582d15 Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 20:30:34 -0700 Subject: [PATCH 11/18] Now invoking record_view with internal_record_view. --- clients/drcachesim/common/options.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clients/drcachesim/common/options.h b/clients/drcachesim/common/options.h index 57d0daf002b..9e1e230ee4b 100644 --- a/clients/drcachesim/common/options.h +++ b/clients/drcachesim/common/options.h @@ -49,7 +49,7 @@ #define SYSCALL_MIX "syscall_mix" #define VIEW "view" #define FUNC_VIEW "func_view" -#define RECORD_VIEW "record_view" +#define RECORD_VIEW "internal_record_view" #define INVARIANT_CHECKER "invariant_checker" #define SCHEDULE_STATS "schedule_stats" #define RECORD_FILTER "record_filter" From 58c603203b680d5b36af2d2c00f503f661aef51c Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 21:16:56 -0700 Subject: [PATCH 12/18] Added description to trace_marker_type_value_as_string(). --- clients/drcachesim/common/trace_entry.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clients/drcachesim/common/trace_entry.h b/clients/drcachesim/common/trace_entry.h index 5d334192082..3d11afd8d0b 100644 --- a/clients/drcachesim/common/trace_entry.h +++ b/clients/drcachesim/common/trace_entry.h @@ -987,6 +987,9 @@ trace_arch_string(offline_file_type_t type) : "unspecified"))); } +/* Returns a string representation of marker type and corresponding marker value (if any) + * together. + */ static inline std::string trace_marker_type_value_as_string(trace_marker_type_t marker_type, uintptr_t marker_value) { From cdb3eaabb7cee5045a65f66adb92a40672f13449 Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 21:27:29 -0700 Subject: [PATCH 13/18] Added warning header. --- clients/drcachesim/tools/record_view.cpp | 12 ++++++++++++ clients/drcachesim/tools/record_view.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/record_view.cpp index f5fbdf4926e..ac053233e11 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/record_view.cpp @@ -88,6 +88,18 @@ record_view_t::initialize_shard_type(shard_type_t shard_type) return ""; } +std::string +record_view_t::initialize_stream(memtrace_stream_t *serial_stream) +{ + /* Print warning header. + */ + std::cerr << "The internal_record_view tool is a pretty printer for trace_entry_t " + "records.\nThe trace_entry_t internal record format is not a public " + "interface and is subject to change without notice.\nThis tool is meant " + "for debugging only, please do not rely on the details here.\n"; + return ""; +} + void * record_view_t::parallel_shard_init_stream(int shard_index, void *worker_data, memtrace_stream_t *shard_stream) diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/record_view.h index 0e936b686ed..de696fcb0d7 100644 --- a/clients/drcachesim/tools/record_view.h +++ b/clients/drcachesim/tools/record_view.h @@ -66,6 +66,9 @@ class record_view_t : public record_analysis_tool_t { std::string initialize_shard_type(shard_type_t shard_type) override; + std::string + initialize_stream(memtrace_stream_t *serial_stream) override; + void * parallel_shard_init_stream(int shard_index, void *worker_data, memtrace_stream_t *shard_stream) override; From 612a8eab40a76200edc3fb519ed95e268766efa5 Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 21:30:28 -0700 Subject: [PATCH 14/18] simple simply. ugh. --- clients/drcachesim/common/trace_entry.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clients/drcachesim/common/trace_entry.h b/clients/drcachesim/common/trace_entry.h index 3d11afd8d0b..b8e59e75f94 100644 --- a/clients/drcachesim/common/trace_entry.h +++ b/clients/drcachesim/common/trace_entry.h @@ -1003,7 +1003,7 @@ trace_marker_type_value_as_string(trace_marker_type_t marker_type, uintptr_t mar case TRACE_MARKER_TYPE_CORE_WAIT: case TRACE_MARKER_TYPE_CORE_IDLE: ss << "<" << marker_name << ">\n"; break; - /* Handle all the simple cases where we simply print . + /* Handle all the cases where we simply print . */ case TRACE_MARKER_TYPE_TIMESTAMP: case TRACE_MARKER_TYPE_CPU_ID: @@ -1017,7 +1017,7 @@ trace_marker_type_value_as_string(trace_marker_type_t marker_type, uintptr_t mar case TRACE_MARKER_TYPE_SYSCALL_IDX: ss << "<" << marker_name << " " << marker_value << ">\n"; break; - /* Handle all the simple cases where we simply print . + /* Handle all the cases where we simply print . */ case TRACE_MARKER_TYPE_FUNC_RETADDR: case TRACE_MARKER_TYPE_FUNC_ARG: From 81e6b2493cc244e03918cfeb01bd4578a89c491b Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 23 Apr 2024 23:55:49 -0700 Subject: [PATCH 15/18] Renaming: record_view to internal_record_view. --- clients/drcachesim/CMakeLists.txt | 14 ++++---- clients/drcachesim/analyzer_multi.cpp | 7 ++-- clients/drcachesim/common/options.h | 2 +- clients/drcachesim/launcher.cpp | 2 +- ...cord_view.cpp => internal_record_view.cpp} | 33 ++++++++++--------- .../{record_view.h => internal_record_view.h} | 18 +++++----- ...create.h => internal_record_view_create.h} | 19 ++++------- 7 files changed, 46 insertions(+), 49 deletions(-) rename clients/drcachesim/tools/{record_view.cpp => internal_record_view.cpp} (85%) rename clients/drcachesim/tools/{record_view.h => internal_record_view.h} (85%) rename clients/drcachesim/tools/{record_view_create.h => internal_record_view_create.h} (82%) diff --git a/clients/drcachesim/CMakeLists.txt b/clients/drcachesim/CMakeLists.txt index bbd19c229d7..36a218f9c51 100644 --- a/clients/drcachesim/CMakeLists.txt +++ b/clients/drcachesim/CMakeLists.txt @@ -165,7 +165,7 @@ add_exported_library(drmemtrace_opcode_mix STATIC tools/opcode_mix.cpp) add_exported_library(drmemtrace_syscall_mix STATIC tools/syscall_mix.cpp) add_exported_library(drmemtrace_view STATIC tools/view.cpp) add_exported_library(drmemtrace_func_view STATIC tools/func_view.cpp) -add_exported_library(drmemtrace_record_view STATIC tools/record_view.cpp) +add_exported_library(drmemtrace_internal_record_view STATIC tools/internal_record_view.cpp) add_exported_library(drmemtrace_invariant_checker STATIC tools/invariant_checker.cpp) add_exported_library(drmemtrace_schedule_stats STATIC tools/schedule_stats.cpp) @@ -173,7 +173,7 @@ target_link_libraries(drmemtrace_invariant_checker drdecode) configure_DynamoRIO_standalone(drmemtrace_opcode_mix) configure_DynamoRIO_standalone(drmemtrace_view) -configure_DynamoRIO_standalone(drmemtrace_record_view) +configure_DynamoRIO_standalone(drmemtrace_internal_record_view) configure_DynamoRIO_standalone(drmemtrace_invariant_checker) # We combine the cache and TLB simulators as they share code already. @@ -278,7 +278,7 @@ configure_DynamoRIO_standalone(drcachesim) target_link_libraries(drcachesim drmemtrace_simulator drmemtrace_reuse_distance drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view - drmemtrace_record_view drmemtrace_raw2trace directory_iterator + drmemtrace_internal_record_view drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker drmemtrace_schedule_stats drmemtrace_record_filter) if (UNIX) target_link_libraries(drcachesim dl) @@ -359,7 +359,7 @@ install_client_nonDR_header(drmemtrace simulator/cache_simulator_create.h) install_client_nonDR_header(drmemtrace simulator/tlb_simulator_create.h) install_client_nonDR_header(drmemtrace tools/view_create.h) install_client_nonDR_header(drmemtrace tools/func_view_create.h) -install_client_nonDR_header(drmemtrace tools/record_view_create.h) +install_client_nonDR_header(drmemtrace tools/internal_record_view_create.h) # TODO i#6412: Create a separate directory for non-tracer headers so that # we can more cleanly separate tracer and raw2trace code. install_client_nonDR_header(drmemtrace tracer/raw2trace.h) @@ -581,7 +581,7 @@ restore_nonclient_flags(drmemtrace_opcode_mix) restore_nonclient_flags(drmemtrace_syscall_mix) restore_nonclient_flags(drmemtrace_view) restore_nonclient_flags(drmemtrace_func_view) -restore_nonclient_flags(drmemtrace_record_view) +restore_nonclient_flags(drmemtrace_internal_record_view) restore_nonclient_flags(drmemtrace_record_filter) restore_nonclient_flags(drmemtrace_analyzer) restore_nonclient_flags(drmemtrace_invariant_checker) @@ -648,7 +648,7 @@ add_win32_flags(drmemtrace_opcode_mix) add_win32_flags(drmemtrace_syscall_mix) add_win32_flags(drmemtrace_view) add_win32_flags(drmemtrace_func_view) -add_win32_flags(drmemtrace_record_view) +add_win32_flags(drmemtrace_internal_record_view) add_win32_flags(drmemtrace_record_filter) add_win32_flags(drmemtrace_analyzer) add_win32_flags(drmemtrace_invariant_checker) @@ -826,7 +826,7 @@ if (BUILD_TESTS) drmemtrace_raw2trace drmemtrace_simulator drmemtrace_reuse_distance drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts drmemtrace_opcode_mix drmemtrace_syscall_mix drmemtrace_view drmemtrace_func_view - drmemtrace_record_view drmemtrace_raw2trace directory_iterator + drmemtrace_internal_record_view drmemtrace_raw2trace directory_iterator drmemtrace_invariant_checker drmemtrace_schedule_stats drmemtrace_analyzer drmemtrace_record_filter) if (UNIX) diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index f62d15b0a39..fdaaf3a5129 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -64,7 +64,7 @@ #include "tools/reuse_distance_create.h" #include "tools/reuse_time_create.h" #include "tools/view_create.h" -#include "tools/record_view_create.h" +#include "tools/internal_record_view_create.h" #include "tools/loader/external_config_file.h" #include "tools/loader/external_tool_creator.h" #include "tools/filter/record_filter_create.h" @@ -336,8 +336,9 @@ record_analyzer_multi_t::create_analysis_tool_from_options( op_filter_cache_size.get_value(), op_filter_trace_types.get_value(), op_filter_marker_types.get_value(), op_trim_before_timestamp.get_value(), op_trim_after_timestamp.get_value(), op_verbose.get_value()); - } else if (simulator_type == RECORD_VIEW) { - return record_view_tool_create(op_skip_refs.get_value(), op_sim_refs.get_value()); + } else if (simulator_type == INTERNAL_RECORD_VIEW) { + return internal_record_view_tool_create(op_skip_refs.get_value(), + op_sim_refs.get_value()); } ERRMSG("Usage error: unsupported record analyzer type \"%s\". Only " RECORD_FILTER " is supported.\n", diff --git a/clients/drcachesim/common/options.h b/clients/drcachesim/common/options.h index 9e1e230ee4b..3bdc47fd9b1 100644 --- a/clients/drcachesim/common/options.h +++ b/clients/drcachesim/common/options.h @@ -49,7 +49,7 @@ #define SYSCALL_MIX "syscall_mix" #define VIEW "view" #define FUNC_VIEW "func_view" -#define RECORD_VIEW "internal_record_view" +#define INTERNAL_RECORD_VIEW "internal_record_view" #define INVARIANT_CHECKER "invariant_checker" #define SCHEDULE_STATS "schedule_stats" #define RECORD_FILTER "record_filter" diff --git a/clients/drcachesim/launcher.cpp b/clients/drcachesim/launcher.cpp index fc009d761f6..19fa21601f2 100644 --- a/clients/drcachesim/launcher.cpp +++ b/clients/drcachesim/launcher.cpp @@ -324,7 +324,7 @@ _tmain(int argc, const TCHAR *targv[]) } } else { if (op_simulator_type.get_value() == RECORD_FILTER || - op_simulator_type.get_value() == RECORD_VIEW) { + op_simulator_type.get_value() == INTERNAL_RECORD_VIEW) { record_analyzer = new record_analyzer_multi_t; if (!*record_analyzer) { std::string error_string_ = record_analyzer->get_error_string(); diff --git a/clients/drcachesim/tools/record_view.cpp b/clients/drcachesim/tools/internal_record_view.cpp similarity index 85% rename from clients/drcachesim/tools/record_view.cpp rename to clients/drcachesim/tools/internal_record_view.cpp index ac053233e11..306464a2d2c 100644 --- a/clients/drcachesim/tools/record_view.cpp +++ b/clients/drcachesim/tools/internal_record_view.cpp @@ -30,7 +30,7 @@ * DAMAGE. */ -#include "record_view.h" +#include "internal_record_view.h" #include #include @@ -47,23 +47,23 @@ namespace drmemtrace { typedef unsigned int uint; record_analysis_tool_t * -record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs) +internal_record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs) { - return new dynamorio::drmemtrace::record_view_t(skip_refs, sim_refs); + return new dynamorio::drmemtrace::internal_record_view_t(skip_refs, sim_refs); } -record_view_t::record_view_t(uint64_t skip_refs, uint64_t sim_refs) +internal_record_view_t::internal_record_view_t(uint64_t skip_refs, uint64_t sim_refs) : skip_refs_(skip_refs) , sim_refs_(sim_refs) { } -record_view_t::~record_view_t() +internal_record_view_t::~internal_record_view_t() { } bool -record_view_t::should_skip(void) +internal_record_view_t::should_skip(void) { if (skip_refs_ > 0) { --skip_refs_; @@ -77,19 +77,19 @@ record_view_t::should_skip(void) } bool -record_view_t::parallel_shard_supported() +internal_record_view_t::parallel_shard_supported() { return false; } std::string -record_view_t::initialize_shard_type(shard_type_t shard_type) +internal_record_view_t::initialize_shard_type(shard_type_t shard_type) { return ""; } std::string -record_view_t::initialize_stream(memtrace_stream_t *serial_stream) +internal_record_view_t::initialize_stream(memtrace_stream_t *serial_stream) { /* Print warning header. */ @@ -101,26 +101,27 @@ record_view_t::initialize_stream(memtrace_stream_t *serial_stream) } void * -record_view_t::parallel_shard_init_stream(int shard_index, void *worker_data, - memtrace_stream_t *shard_stream) +internal_record_view_t::parallel_shard_init_stream(int shard_index, void *worker_data, + memtrace_stream_t *shard_stream) { return shard_stream; } bool -record_view_t::parallel_shard_exit(void *shard_data) +internal_record_view_t::parallel_shard_exit(void *shard_data) { return true; } std::string -record_view_t::parallel_shard_error(void *shard_data) +internal_record_view_t::parallel_shard_error(void *shard_data) { return ""; } bool -record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entry) +internal_record_view_t::parallel_shard_memref(void *shard_data, + const trace_entry_t &entry) { if (should_skip()) return true; @@ -201,13 +202,13 @@ record_view_t::parallel_shard_memref(void *shard_data, const trace_entry_t &entr } bool -record_view_t::process_memref(const trace_entry_t &entry) +internal_record_view_t::process_memref(const trace_entry_t &entry) { return parallel_shard_memref(NULL, entry); } bool -record_view_t::print_results() +internal_record_view_t::print_results() { return true; } diff --git a/clients/drcachesim/tools/record_view.h b/clients/drcachesim/tools/internal_record_view.h similarity index 85% rename from clients/drcachesim/tools/record_view.h rename to clients/drcachesim/tools/internal_record_view.h index de696fcb0d7..b9fb3efdf19 100644 --- a/clients/drcachesim/tools/record_view.h +++ b/clients/drcachesim/tools/internal_record_view.h @@ -30,8 +30,8 @@ * DAMAGE. */ -#ifndef _RECORD_VIEW_H_ -#define _RECORD_VIEW_H_ 1 +#ifndef _INTERNAL_RECORD_VIEW_H_ +#define _INTERNAL_RECORD_VIEW_H_ 1 #include @@ -44,15 +44,15 @@ namespace dynamorio { namespace drmemtrace { -/** - * Analysis tool that prints #trace_entry_t records of an offline trace in human readable - * form. +/* Analysis tool that prints #trace_entry_t records of an offline trace in human readable + * form. Note that this is an internal tool for debugging purposes only. Its output is + * subject to changes. */ -class record_view_t : public record_analysis_tool_t { +class internal_record_view_t : public record_analysis_tool_t { public: - record_view_t(uint64_t skip_refs, uint64_t sim_refs); + internal_record_view_t(uint64_t skip_refs, uint64_t sim_refs); - ~record_view_t() override; + ~internal_record_view_t() override; bool process_memref(const trace_entry_t &entry) override; @@ -93,4 +93,4 @@ class record_view_t : public record_analysis_tool_t { } // namespace drmemtrace } // namespace dynamorio -#endif /* _RECORD_VIEW_H_ */ +#endif /* _INTERNAL_RECORD_VIEW_H_ */ diff --git a/clients/drcachesim/tools/record_view_create.h b/clients/drcachesim/tools/internal_record_view_create.h similarity index 82% rename from clients/drcachesim/tools/record_view_create.h rename to clients/drcachesim/tools/internal_record_view_create.h index f9fff04b524..db6ca0b17ff 100644 --- a/clients/drcachesim/tools/record_view_create.h +++ b/clients/drcachesim/tools/internal_record_view_create.h @@ -33,27 +33,22 @@ /* record view tool creation */ #include -#ifndef _RECORD_VIEW_CREATE_H_ -# define _RECORD_VIEW_CREATE_H_ 1 +#ifndef _INTERNAL_RECORD_VIEW_CREATE_H_ +# define _INTERNAL_RECORD_VIEW_CREATE_H_ 1 # include "analysis_tool.h" namespace dynamorio { namespace drmemtrace { -/** - * @file drmemtrace/record_view_create.h - * @brief DrMemtrace record view trace analysis tool creation. - */ - -/** - * Creates an analysis tool which prints out the #trace_entry_t records in a trace file - * to std::cerr. +/* Creates an analysis tool which pretty prints out the #trace_entry_t records in a trace + * file to std::cerr. Note that this is an internal tool for debugging purposes. Its + * output is subject to changes. */ record_analysis_tool_t * -record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs); +internal_record_view_tool_create(uint64_t skip_refs, uint64_t sim_refs); } // namespace drmemtrace } // namespace dynamorio -#endif /* _RECORD_VIEW_CREATE_H_ */ +#endif /* _INTERNAL_RECORD_VIEW_CREATE_H_ */ From 81ff6491d2b1005e5f63000bd482f42b2a27a633 Mon Sep 17 00:00:00 2001 From: edeiana Date: Wed, 24 Apr 2024 00:02:08 -0700 Subject: [PATCH 16/18] Code cleanup. Better comments. --- clients/drcachesim/common/trace_entry.h | 1 - clients/drcachesim/tools/view.cpp | 25 ++++++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/clients/drcachesim/common/trace_entry.h b/clients/drcachesim/common/trace_entry.h index b8e59e75f94..b5d1e364255 100644 --- a/clients/drcachesim/common/trace_entry.h +++ b/clients/drcachesim/common/trace_entry.h @@ -1002,7 +1002,6 @@ trace_marker_type_value_as_string(trace_marker_type_t marker_type, uintptr_t mar case TRACE_MARKER_TYPE_MAYBE_BLOCKING_SYSCALL: case TRACE_MARKER_TYPE_CORE_WAIT: case TRACE_MARKER_TYPE_CORE_IDLE: ss << "<" << marker_name << ">\n"; break; - /* Handle all the cases where we simply print . */ case TRACE_MARKER_TYPE_TIMESTAMP: diff --git a/clients/drcachesim/tools/view.cpp b/clients/drcachesim/tools/view.cpp index 50502340c0a..1058b03d354 100644 --- a/clients/drcachesim/tools/view.cpp +++ b/clients/drcachesim/tools/view.cpp @@ -249,16 +249,15 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) if (trace_version_ != -1) { // Old versions may not have a version marker. if (!should_skip(memstream, memref)) { print_prefix(memstream, memref, version_record_ord_); - const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_VERSION]; - std::cerr << "<" << marker_name << " " << trace_version_ << ">\n"; + std::cerr << "<" << trace_marker_names[TRACE_MARKER_TYPE_VERSION] << " " + << trace_version_ << ">\n"; } } if (filetype_ != -1) { // Handle old/malformed versions. if (!should_skip(memstream, memref)) { print_prefix(memstream, memref, filetype_record_ord_); - const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_FILETYPE]; - std::cerr << "<" << marker_name << " 0x" << std::hex << filetype_ - << std::dec << ">\n"; + std::cerr << "<" << trace_marker_names[TRACE_MARKER_TYPE_FILETYPE] + << " 0x" << std::hex << filetype_ << std::dec << ">\n"; } } } @@ -276,19 +275,19 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) -1); // Already incremented for timestamp above. } if (timestamp_ > 0) { - const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP]; - std::cerr << "<" << marker_name << " " << timestamp_ << ">\n"; + std::cerr << "<" << trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP] << " " + << timestamp_ << ">\n"; timestamp_ = 0; print_prefix(memstream, memref); } - const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_WINDOW_ID]; - std::cerr << "<" << marker_name << " " << memref.marker.marker_value << ">\n"; + std::cerr << "<" << trace_marker_names[TRACE_MARKER_TYPE_WINDOW_ID] << " " + << memref.marker.marker_value << ">\n"; last_window_[memref.marker.tid] = memref.marker.marker_value; } if (timestamp_ > 0) { print_prefix(memstream, memref, timestamp_record_ord_); - const char *marker_name = trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP]; - std::cerr << "<" << marker_name << " " << timestamp_ << ">\n"; + std::cerr << "<" << trace_marker_names[TRACE_MARKER_TYPE_TIMESTAMP] << " " + << timestamp_ << ">\n"; timestamp_ = 0; } } @@ -346,6 +345,10 @@ view_t::parallel_shard_memref(void *shard_data, const memref_t &memref) << memref.marker.marker_value << ">\n"; break; default: + /* The previous cases have state and require extra processing. Here we print + * all the remaining cases that do not need that extra processing and + * bookkeeping. + */ std::cerr << trace_marker_type_value_as_string(memref.marker.marker_type, memref.marker.marker_value); break; From c940f18911ba3464fb08d378a75eb63bbf29a41b Mon Sep 17 00:00:00 2001 From: edeiana Date: Wed, 24 Apr 2024 00:24:04 -0700 Subject: [PATCH 17/18] Fixed formatting. --- clients/drcachesim/tools/internal_record_view_create.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/clients/drcachesim/tools/internal_record_view_create.h b/clients/drcachesim/tools/internal_record_view_create.h index db6ca0b17ff..9370afa6eac 100644 --- a/clients/drcachesim/tools/internal_record_view_create.h +++ b/clients/drcachesim/tools/internal_record_view_create.h @@ -32,11 +32,12 @@ /* record view tool creation */ -#include #ifndef _INTERNAL_RECORD_VIEW_CREATE_H_ -# define _INTERNAL_RECORD_VIEW_CREATE_H_ 1 +#define _INTERNAL_RECORD_VIEW_CREATE_H_ 1 + +#include "analysis_tool.h" -# include "analysis_tool.h" +#include namespace dynamorio { namespace drmemtrace { From 7baee4ed313e3dd9ee631be72ebca73c6646bee6 Mon Sep 17 00:00:00 2001 From: edeiana Date: Tue, 22 Oct 2024 15:26:18 -0700 Subject: [PATCH 18/18] Minor post-merge fixes. --- clients/drcachesim/analyzer_multi.cpp | 2 +- clients/drcachesim/launcher.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/clients/drcachesim/analyzer_multi.cpp b/clients/drcachesim/analyzer_multi.cpp index 3bc52a3f30a..5e62e9d7c17 100644 --- a/clients/drcachesim/analyzer_multi.cpp +++ b/clients/drcachesim/analyzer_multi.cpp @@ -342,7 +342,7 @@ record_analyzer_multi_t::create_analysis_tool_from_options(const std::string &to op_trim_after_timestamp.get_value(), op_encodings2regdeps.get_value(), op_filter_func_ids.get_value(), op_modify_marker_value.get_value(), op_verbose.get_value()); - } else if (simulator_type == INTERNAL_RECORD_VIEW) { + } else if (tool == INTERNAL_RECORD_VIEW) { return internal_record_view_tool_create(op_skip_refs.get_value(), op_sim_refs.get_value()); } diff --git a/clients/drcachesim/launcher.cpp b/clients/drcachesim/launcher.cpp index 19fa21601f2..18ba23d11c1 100644 --- a/clients/drcachesim/launcher.cpp +++ b/clients/drcachesim/launcher.cpp @@ -323,8 +323,8 @@ _tmain(int argc, const TCHAR *targv[]) FATAL_ERROR("invalid -outdir %s", op_outdir.get_value().c_str()); } } else { - if (op_simulator_type.get_value() == RECORD_FILTER || - op_simulator_type.get_value() == INTERNAL_RECORD_VIEW) { + if (op_tool.get_value() == RECORD_FILTER || + op_tool.get_value() == INTERNAL_RECORD_VIEW) { record_analyzer = new record_analyzer_multi_t; if (!*record_analyzer) { std::string error_string_ = record_analyzer->get_error_string();