Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i#4083 func trace: Add func_view tool #4150

Merged
merged 5 commits into from
Mar 4, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ macro (add_exported_library name type)
add_library(${name} ${type} ${ARGN})
DR_export_target(${name})
install_exported_target(${name} ${INSTALL_CLIENTS_LIB})
add_dependencies(${name} api_headers)
endmacro ()

add_exported_library(drmemtrace_reuse_distance STATIC tools/reuse_distance.cpp)
Expand All @@ -92,6 +93,7 @@ add_exported_library(drmemtrace_reuse_time STATIC tools/reuse_time.cpp)
add_exported_library(drmemtrace_basic_counts STATIC tools/basic_counts.cpp)
add_exported_library(drmemtrace_opcode_mix STATIC tools/opcode_mix.cpp)
add_exported_library(drmemtrace_view STATIC tools/view.cpp)
add_exported_library(drmemtrace_func_view STATIC tools/func_view.cpp)
configure_DynamoRIO_standalone(drmemtrace_opcode_mix)
configure_DynamoRIO_standalone(drmemtrace_view)

Expand Down Expand Up @@ -153,7 +155,8 @@ configure_DynamoRIO_standalone(drcachesim)
# Link in our tools:
target_link_libraries(drcachesim drmemtrace_simulator drmemtrace_reuse_distance
drmemtrace_histogram drmemtrace_reuse_time drmemtrace_basic_counts
drmemtrace_opcode_mix drmemtrace_view drmemtrace_raw2trace directory_iterator)
drmemtrace_opcode_mix drmemtrace_view drmemtrace_func_view
drmemtrace_raw2trace directory_iterator)
if (libsnappy)
target_link_libraries(drcachesim snappy)
endif ()
Expand Down Expand Up @@ -202,6 +205,8 @@ install_client_nonDR_header(drmemtrace tools/opcode_mix_create.h)
install_client_nonDR_header(drmemtrace simulator/cache_simulator.h)
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 tracer/raw2trace.h)

# We show one example of how to create a standalone analyzer of trace
Expand Down Expand Up @@ -331,6 +336,7 @@ restore_nonclient_flags(drmemtrace_reuse_time)
restore_nonclient_flags(drmemtrace_basic_counts)
restore_nonclient_flags(drmemtrace_opcode_mix)
restore_nonclient_flags(drmemtrace_view)
restore_nonclient_flags(drmemtrace_func_view)
restore_nonclient_flags(drmemtrace_analyzer)

# We need to pass /EHsc and we pull in libcmtd into drcachesim from a dep lib.
Expand Down Expand Up @@ -374,6 +380,7 @@ add_win32_flags(drmemtrace_reuse_time)
add_win32_flags(drmemtrace_basic_counts)
add_win32_flags(drmemtrace_opcode_mix)
add_win32_flags(drmemtrace_view)
add_win32_flags(drmemtrace_func_view)
add_win32_flags(drmemtrace_analyzer)
add_win32_flags(directory_iterator)
if (WIN32 AND DEBUG)
Expand Down
30 changes: 21 additions & 9 deletions clients/drcachesim/common/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ droption_t<std::string> op_module_file(
"If the file is named modules.log and is in the same directory as the trace file, "
"or a raw/ subdirectory below the trace file, this parameter can be omitted.");

droption_t<std::string> op_funclist_file(
DROPTION_SCOPE_ALL, "funclist_file", "",
"Path to function map file for func_view tool",
"The func_view tool needs the mapping from function name to identifier that was "
"recorded during offline tracing. This data is stored in its own separate "
"file in the raw/ subdirectory. If the file is named funclist.log and is in the same "
"directory as the trace file, or a raw/ subdirectory below the trace file, this "
"parameter can be omitted.");

droption_t<unsigned int> op_num_cores(DROPTION_SCOPE_FRONTEND, "cores", 4,
"Number of cores",
"Specifies the number of cores to simulate.");
Expand Down Expand Up @@ -276,20 +285,23 @@ droption_t<std::string>
"Specifies the replacement policy for TLBs. "
"Supported policies: LFU (Least Frequently Used).");

droption_t<std::string> op_simulator_type(DROPTION_SCOPE_FRONTEND, "simulator_type",
CPU_CACHE,
"Simulator type (" CPU_CACHE ", " MISS_ANALYZER
", " TLB ", " REUSE_DIST ", " REUSE_TIME
", " HISTOGRAM ", or " BASIC_COUNTS ").",
"Specifies the type of the simulator. "
"Supported types: " CPU_CACHE ", " MISS_ANALYZER
", " TLB ", " REUSE_DIST ", " REUSE_TIME
", " HISTOGRAM "or " BASIC_COUNTS ".");
droption_t<std::string> op_simulator_type(
DROPTION_SCOPE_FRONTEND, "simulator_type", CPU_CACHE,
"Simulator type (" CPU_CACHE ", " MISS_ANALYZER ", " TLB ", " REUSE_DIST
", " REUSE_TIME ", " HISTOGRAM ", " VIEW ", " FUNC_VIEW ", or " BASIC_COUNTS ").",
"Specifies the type of the simulator. "
"Supported types: " CPU_CACHE ", " MISS_ANALYZER ", " TLB ", " REUSE_DIST
", " REUSE_TIME ", " HISTOGRAM "or " BASIC_COUNTS ".");

droption_t<unsigned int> op_verbose(DROPTION_SCOPE_ALL, "verbose", 0, 0, 64,
"Verbosity level",
"Verbosity level for notifications.");

droption_t<bool>
op_show_func_trace(DROPTION_SCOPE_FRONTEND, "show_func_trace", true,
"Show every traced call in the func_trace tool",
"In the func_trace tool, this controls whether every traced call "
"is shown or instead only aggregate statistics are shown.");
#ifdef DEBUG
droption_t<bool> op_test_mode(DROPTION_SCOPE_ALL, "test_mode", false, "Run sanity tests",
"Run extra analyses for sanity checks on the trace.");
Expand Down
5 changes: 4 additions & 1 deletion clients/drcachesim/common/options.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2015-2019 Google, Inc. All rights reserved.
* Copyright (c) 2015-2020 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -50,6 +50,7 @@
#define BASIC_COUNTS "basic_counts"
#define OPCODE_MIX "opcode_mix"
#define VIEW "view"
#define FUNC_VIEW "func_view"
#define CACHE_TYPE_INSTRUCTION "instruction"
#define CACHE_TYPE_DATA "data"
#define CACHE_TYPE_UNIFIED "unified"
Expand All @@ -65,6 +66,7 @@ extern droption_t<std::string> op_subdir_prefix;
extern droption_t<std::string> op_infile;
extern droption_t<std::string> op_indir;
extern droption_t<std::string> op_module_file;
extern droption_t<std::string> op_funclist_file;
extern droption_t<unsigned int> op_num_cores;
extern droption_t<unsigned int> op_line_size;
extern droption_t<bytesize_t> op_L1I_size;
Expand Down Expand Up @@ -97,6 +99,7 @@ extern droption_t<unsigned int> op_TLB_L2_assoc;
extern droption_t<std::string> op_TLB_replace_policy;
extern droption_t<std::string> op_simulator_type;
extern droption_t<unsigned int> op_verbose;
extern droption_t<bool> op_show_func_trace;
extern droption_t<int> op_jobs;
#ifdef DEBUG
extern droption_t<bool> op_test_mode;
Expand Down
81 changes: 72 additions & 9 deletions clients/drcachesim/drcachesim.dox.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2015-2019 Google, Inc. All rights reserved.
* Copyright (c) 2015-2020 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -55,6 +55,7 @@ online and offline.
- \ref sec_drcachesim_core
- \ref sec_drcachesim_extend
- \ref sec_drcachesim_tracer
- \ref sec_drcachesim_funcs
- \ref sec_drcachesim_newtool
- \ref sec_drcachesim_ops
- \ref sec_drcachesim_limit
Expand Down Expand Up @@ -509,6 +510,42 @@ Here is an example of a signal handler interrupting the regular flow:
00 00
\endcode

The func_view tool records function argument and return values for
function names specified at tracing time. See \ref sec_drcachesim_funcs for
more information.

\code
$ bin64/drrun -t drcachesim -offline -record_function 'fib|1' -- ~/test/fib 5
Estimation of pi is 3.142425985001098
$ bin64/drrun -t drcachesim -simulator_type func_view -indir drmemtrace.*.dir
0x7fc06d2288eb => common.fib!fib(0x5)
0x7fc06d22888e => common.fib!fib(0x4)
0x7fc06d22888e => common.fib!fib(0x3)
0x7fc06d22888e => common.fib!fib(0x2)
0x7fc06d22888e => common.fib!fib(0x1) => 0x1
0x7fc06d22889d => common.fib!fib(0x0) => 0x1
=> 0x2
0x7fc06d22889d => common.fib!fib(0x1) => 0x1
=> 0x3
0x7fc06d22889d => common.fib!fib(0x2)
0x7fc06d22888e => common.fib!fib(0x1) => 0x1
0x7fc06d22889d => common.fib!fib(0x0) => 0x1
=> 0x2
=> 0x5
0x7fc06d22889d => common.fib!fib(0x3)
0x7fc06d22888e => common.fib!fib(0x2)
0x7fc06d22888e => common.fib!fib(0x1) => 0x1
0x7fc06d22889d => common.fib!fib(0x0) => 0x1
=> 0x2
0x7fc06d22889d => common.fib!fib(0x1) => 0x1
=> 0x3
=> 0x8
Function view tool results:
Function id=0: common.fib!fib
15 calls
15 returns
\endcode

The top referenced cache lines are displayed by the \p histogram tool:

\code
Expand Down Expand Up @@ -923,6 +960,31 @@ drmemtrace_custom_module_data(). The custom data may be retrieved by
creating a custom offline trace post-processor and using the #module_mapper_t
class.

****************************************************************************
\section sec_drcachesim_funcs Tracing Function Calls

The tracer supports recording argument and return values for specified
functions. This feature is currently limited to offline mode only
(\ref sec_drcachesim_offline). The -record_function parameter lists
which function names to trace. Requested names will be located per
library and each instance traced separately. The number of arguments
to record is specified for each name, using a bar character to
separate them. An ampersand separates functions. Here is an example:

\code
$ bin64/drrun -t drcachesim -offline -record_function 'fib|1&calloc|2'
\endcode

Within the trace, each function is identified by a numeric identifier.
The list of recorded functions, each with its identifier, is placed
into a file "funclist.log" in the trace directory, where the sample
tool \p func_view uses it to provide a linear function call trace as
well as summary statistics as shown above.

The -record_heap parameter requests recording of a pre-determined set
of functions related to heap allocation. The -record_heap_value
paramter controls the contents of this set.

****************************************************************************
\section sec_drcachesim_newtool Creating New Analysis Tools

Expand Down Expand Up @@ -985,14 +1047,15 @@ drmemtrace/ headers:
use_DynamoRIO_drmemtrace(mytool)
\endcode

The \p drmemtrace_analyzer library exported by the DynamoRIO package is the
main library to link when building a new tool. The tools described above
are also exported as the libraries \p drmemtrace_basic_counts, \p drmemtrace_view,
\p drmemtrace_opcode_mix, \p drmemtrace_histogram, \p drmemtrace_reuse_distance, \p
drmemtrace_reuse_time, and \p drmemtrace_simulator and can be created using
the basic_counts_tool_create(), opcode_mix_tool_create(), histogram_tool_create(),
reuse_distance_tool_create(), reuse_time_tool_create(), view_tool_create(),
cache_simulator_create(), and tlb_simulator_create() functions.
The \p drmemtrace_analyzer library exported by the DynamoRIO package is the main
library to link when building a new tool. The tools described above are also
exported as the libraries \p drmemtrace_basic_counts, \p drmemtrace_view, \p
drmemtrace_opcode_mix, \p drmemtrace_histogram, \p drmemtrace_reuse_distance, \p
drmemtrace_reuse_time, \p drmemtrace_simulator, and \p drmemtrace_func_view and can
be created using the basic_counts_tool_create(), opcode_mix_tool_create(),
histogram_tool_create(), reuse_distance_tool_create(), reuse_time_tool_create(),
view_tool_create(), cache_simulator_create(), tlb_simulator_create(), and
func_view_create() functions.

****************************************************************************
\section sec_drcachesim_ops Simulator Parameters
Expand Down
54 changes: 36 additions & 18 deletions clients/drcachesim/simulator/analyzer_interface.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* **********************************************************
* Copyright (c) 2017-2018 Google, Inc. All rights reserved.
* Copyright (c) 2017-2020 Google, Inc. All rights reserved.
* **********************************************************/

/*
Expand Down Expand Up @@ -46,43 +46,47 @@
#include "../tools/basic_counts_create.h"
#include "../tools/opcode_mix_create.h"
#include "../tools/view_create.h"
#include "../tools/func_view_create.h"
#include "../tracer/raw2trace.h"
#include <fstream>

/* Get the path to the modules.log file by examining
* 1. the module_file option
* 2. the trace directory
/* Get the path to an auxiliary file by examining
* 1. The corresponding command line option
* 2. The trace directory
* If a trace file is provided instead of a trace directory, it searches in the
* directory which contains the trace file.
*/
static std::string
get_module_file_path()
get_aux_file_path(std::string option_val, std::string default_filename)
{
std::string module_file_path;
if (!op_module_file.get_value().empty())
module_file_path = op_module_file.get_value();
std::string file_path;
if (!option_val.empty())
file_path = option_val;
else {
std::string trace_dir;
if (!op_indir.get_value().empty())
trace_dir = op_indir.get_value();
else {
if (op_infile.get_value().empty()) {
ERRMSG("Usage error: the opcode mix tool requires offline traces.\n");
return "";
}
size_t sep_index = op_infile.get_value().find_last_of(DIRSEP ALT_DIRSEP);
if (sep_index != std::string::npos)
trace_dir = std::string(op_infile.get_value(), 0, sep_index);
}
module_file_path =
trace_dir + std::string(DIRSEP) + DRMEMTRACE_MODULE_LIST_FILENAME;
if (!std::ifstream(module_file_path.c_str()).good()) {
file_path = trace_dir + std::string(DIRSEP) + default_filename;
if (!std::ifstream(file_path.c_str()).good()) {
trace_dir += std::string(DIRSEP) + OUTFILE_SUBDIR;
module_file_path =
trace_dir + std::string(DIRSEP) + DRMEMTRACE_MODULE_LIST_FILENAME;
file_path = trace_dir + std::string(DIRSEP) + default_filename;
}
}
return module_file_path;
return file_path;
}

static std::string
get_module_file_path()
{
return get_aux_file_path(op_module_file.get_value(), DRMEMTRACE_MODULE_LIST_FILENAME);
}

/* Get the cache simulator knobs used by the cache simulator
Expand Down Expand Up @@ -166,20 +170,34 @@ drmemtrace_analysis_tool_create()
return basic_counts_tool_create(op_verbose.get_value());
} else if (op_simulator_type.get_value() == OPCODE_MIX) {
std::string module_file_path = get_module_file_path();
if (module_file_path.empty())
if (module_file_path.empty()) {
ERRMSG("Usage error: the opcode_mix tool requires offline traces.\n");
return nullptr;
}
return opcode_mix_tool_create(module_file_path, op_verbose.get_value());
} else if (op_simulator_type.get_value() == VIEW) {
std::string module_file_path = get_module_file_path();
if (module_file_path.empty())
if (module_file_path.empty()) {
ERRMSG("Usage error: the view tool requires offline traces.\n");
return nullptr;
}
return view_tool_create(module_file_path, op_skip_refs.get_value(),
op_sim_refs.get_value(), op_view_syntax.get_value(),
op_verbose.get_value());
} else if (op_simulator_type.get_value() == FUNC_VIEW) {
std::string funclist_file_path = get_aux_file_path(
op_funclist_file.get_value(), DRMEMTRACE_FUNCTION_MAP_FILENAME);
if (funclist_file_path.empty()) {
ERRMSG("Usage error: the func_view tool requires offline traces.\n");
return nullptr;
}
return func_view_tool_create(funclist_file_path, op_show_func_trace.get_value(),
op_verbose.get_value());
} else {
ERRMSG("Usage error: unsupported analyzer type. "
"Please choose " CPU_CACHE ", " MISS_ANALYZER ", " TLB ", " HISTOGRAM
", " REUSE_DIST ", " BASIC_COUNTS ", " OPCODE_MIX " or " VIEW ".\n");
", " REUSE_DIST ", " BASIC_COUNTS ", " OPCODE_MIX ", " VIEW
" or " FUNC_VIEW ".\n");
return nullptr;
}
}
27 changes: 27 additions & 0 deletions clients/drcachesim/tests/offline-func_view.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
fib\(5\)=8
0x.* => common.fib!fib\(0x5\)
0x.* => common.fib!fib\(0x4\)
0x.* => common.fib!fib\(0x3\)
0x.* => common.fib!fib\(0x2\)
0x.* => common.fib!fib\(0x1\) => 0x1
0x.* => common.fib!fib\(0x0\) => 0x1
=> 0x2
0x.* => common.fib!fib\(0x1\) => 0x1
=> 0x3
0x.* => common.fib!fib\(0x2\)
0x.* => common.fib!fib\(0x1\) => 0x1
0x.* => common.fib!fib\(0x0\) => 0x1
=> 0x2
=> 0x5
0x.* => common.fib!fib\(0x3\)
0x.* => common.fib!fib\(0x2\)
0x.* => common.fib!fib\(0x1\) => 0x1
0x.* => common.fib!fib\(0x0\) => 0x1
=> 0x2
0x.* => common.fib!fib\(0x1\) => 0x1
=> 0x3
=> 0x8
Function view tool results:
Function id=0: common.fib!fib
15 calls
15 returns
Loading