Skip to content

Commit

Permalink
Updated according to review comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuriershov committed Oct 9, 2023
1 parent 1bb867a commit 013a2b6
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
16 changes: 8 additions & 8 deletions clients/drcachesim/docs/drcachesim.dox.in
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ reuse_time_tool_create(), view_tool_create(), cache_simulator_create(),
tlb_simulator_create(), func_view_create(), and syscall_mix_tool_create()
functions.

\section external_tools Separately-built tools
\section external_tools Separately-Built Tools

\p drcachesim \p drmemtrace analysis tool framework allows to load
non-predefined separately-built external tools. This tool can be loaded by drcachesim
Expand All @@ -1613,9 +1613,9 @@ using the \p -simulator_type option.

The tool package should consist of
- <tt>Registration file</tt> called \p toolname.drcachesim.
- <tt>Static library</tt> containing subclass
#dynamorio::drmemtrace::analysis_tool_t with tool internal logic. This library described
in prevoius section.
- <tt>Static library</tt> containing a subclass of
#dynamorio::drmemtrace::analysis_tool_t with tool internal logic. This library was
described in previous section.
- <tt>Tool creator dynamic library</tt> containing tool factory function.

Registration file should be placed to the \p tools subdirectory of the root of the
Expand All @@ -1628,21 +1628,21 @@ CREATOR_BIN32=/absolute/path/to/32-bit-creator-library
CREATOR_BIN64=/absolute/path/to/64-bit-creator-library
\endcode

This enables \p drcachsim to locate the tool's creator library. The 32 and
This enables \p drcachesim to locate the tool's creator library. The 32 and
64 specifiers allow pointing at alternate-bitwidth paths for use if
the target application creates a child process of a different bitwidth.

For more extensive actions on launching the tool, a custom front-end
executable can be created that replaces \p drcachesim modeled after histogram_launcher.cpp
or opcode_mix_launcher.cpp.

Creator dynamic library should contain 2 export functions:
The creator dynamic library should contain 2 export functions:

\code
extern "C" EXPORT const char *
get_tool_name()
{
return "name-of-concrete-tool";
return "name-of-tool";
}

extern "C" EXPORT analysis_tool_t *
Expand All @@ -1652,7 +1652,7 @@ analysis_tool_create()
}
\endcode

which allows \p drcachsim to create appropriate analyis tool. As an
which allows \p drcachesim to create an analyis tool. As an
example, see <a
href="https://github.com/DynamoRIO/dynamorio/blob/master/clients/drcachesim/tools/external/example">
minimal external analysis tool</a>.
Expand Down
11 changes: 8 additions & 3 deletions clients/drcachesim/tools/external/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ target_link_libraries(empty_launcher
use_DynamoRIO_extension(empty_launcher droption)
add_dependencies(empty_launcher api_headers)

# These add_win32_flags() calls are necessary only for building the project inside
# the DR top level project.
add_win32_flags(drmemtrace_empty)
add_win32_flags(empty_creator)
add_win32_flags(empty_launcher)
Expand Down Expand Up @@ -98,20 +100,23 @@ if (X86 AND X64 AND ZIP_FOUND)
set_tests_properties(tool.empty_launcher PROPERTIES TIMEOUT ${test_seconds})

# Simple test to ensure empty tool can be loaded by drcachesim.
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/empty.templatex" empty_regex)
set(trace_dir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests/drmemtrace.threadsig.x64.tracedir")
add_test(NAME drcachesim.empty_load
COMMAND ${PROJECT_BINARY_DIR}/bin64/drrun -t drcachesim -offline
-simulator_type empty -indir ${trace_dir})
set(empty_regex "Empty tool created\nEmpty tool results:")
set_tests_properties(drcachesim.empty_load
PROPERTIES PASS_REGULAR_EXPRESSION "${empty_regex}")

# Simple test to ensure non-existent tool load by drcachesim should fail.
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/nonexistent.templatex" nonexistent_regex)
add_test(NAME drcachesim.non-existent_load
COMMAND ${PROJECT_BINARY_DIR}/bin64/drrun -t drcachesim -offline
-simulator_type non-existent -indir ${trace_dir})
set(nonexistent_regex "Usage error: unsupported analyzer type "non-existent".
Please choose cache, miss_analyzer, TLB, histogram, reuse_distance, basic_counts,
opcode_mix, syscall_mix, view, func_view, or some external analyzer.\nERROR: failed
to initialize analyzer: Failed to create analysis tool:")
set_tests_properties(drcachesim.non-existent_load
PROPERTIES PASS_REGULAR_EXPRESSION "${nonexistent_regex}")
endif ()
endif ()
5 changes: 2 additions & 3 deletions clients/drcachesim/tools/external/example/empty.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

#include "dr_api.h"
#include "empty.h"
#include <iostream>

const std::string empty_t::TOOL_NAME = "Empty tool";

Expand All @@ -46,7 +45,7 @@ empty_tool_create(unsigned int verbose)

empty_t::empty_t(unsigned int verbose)
{
std::cout << "Empty tool created" << std::endl;
fprintf(stderr, "Empty tool created\n");
}

std::string
Expand Down Expand Up @@ -110,6 +109,6 @@ empty_t::process_memref(const memref_t &memref)
bool
empty_t::print_results()
{
std::cout << "Empty tool results:" << std::endl;
fprintf(stderr, "Empty tool results:\n");
return true;
}
2 changes: 1 addition & 1 deletion clients/drcachesim/tools/external/example/empty.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using dynamorio::drmemtrace::memref_t;

class empty_t : public analysis_tool_t {
public:
empty_t(unsigned int verbose);
explicit empty_t(unsigned int verbose);
virtual ~empty_t();
std::string
initialize() override;
Expand Down
2 changes: 0 additions & 2 deletions clients/drcachesim/tools/external/example/empty.templatex

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion clients/drcachesim/tools/loader/external_tool_creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class external_tool_creator_t : public dynamic_lib_t {
analysis_tool_t *
create_tool();

public:
private:
using get_tool_name_t = const char *(*)();
using create_tool_t = analysis_tool_t *(*)();

Expand Down

0 comments on commit 013a2b6

Please sign in to comment.