Skip to content

Commit

Permalink
i#1729 offline traces: add static bursty trace support
Browse files Browse the repository at this point in the history
Adds testing for gathering a bursty trace using statically linked code:

Adds a static client drmemtrace_static.

Adds a test tool.drcacheoff.burst_static which includes an application that
uses the start/stop API to start DR midway through a big loop and to detach
fully from DR a few iterations later.  This "bursty trace" is saved by the
linked drmemtrace_static client to a file and passed to the cache simulator
as part of the test.

Review-URL: https://codereview.appspot.com/307330043
  • Loading branch information
derekbruening committed Sep 20, 2016
1 parent cb3cfd9 commit d868d95
Show file tree
Hide file tree
Showing 4 changed files with 187 additions and 32 deletions.
54 changes: 39 additions & 15 deletions clients/drcachesim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,31 @@ if (UNIX)
target_link_libraries(drcachesim drinjectlib drconfiglib drfrontendlib)
use_DynamoRIO_extension(drcachesim droption)

add_library(drmemtrace SHARED
tracer/tracer.cpp
tracer/physaddr.cpp
common/named_pipe_${os_name}.cpp
common/options.cpp
common/trace_entry.cpp
)
configure_DynamoRIO_client(drmemtrace)
use_DynamoRIO_extension(drmemtrace drmgr)
use_DynamoRIO_extension(drmemtrace drreg)
use_DynamoRIO_extension(drmemtrace drutil)
use_DynamoRIO_extension(drmemtrace drx)
use_DynamoRIO_extension(drmemtrace droption)
macro(add_drmemtrace name type)
if (${type} STREQUAL "STATIC")
set(ext_sfx "_static")
else ()
set(ext_sfx "")
endif ()
add_library(${name} ${type}
tracer/tracer.cpp
tracer/physaddr.cpp
common/named_pipe_${os_name}.cpp
common/options.cpp
common/trace_entry.cpp
)
configure_DynamoRIO_client(${name})
use_DynamoRIO_extension(${name} drmgr${ext_sfx})
use_DynamoRIO_extension(${name} drreg${ext_sfx})
use_DynamoRIO_extension(${name} drutil${ext_sfx})
use_DynamoRIO_extension(${name} drx${ext_sfx})
use_DynamoRIO_extension(${name} droption)
add_dependencies(${name} api_headers)
install_target(${name} ${INSTALL_CLIENTS_LIB})
endmacro()

add_drmemtrace(drmemtrace SHARED)
add_drmemtrace(drmemtrace_static STATIC)

# Restore debug and other flags to our non-client executable
set_target_properties(drcachesim PROPERTIES
Expand All @@ -91,7 +103,6 @@ if (UNIX)

place_shared_lib_in_lib_dir(drmemtrace)

add_dependencies(drmemtrace api_headers)
add_dependencies(drcachesim api_headers)

# Provide a hint for how to use the client
Expand All @@ -103,7 +114,6 @@ if (UNIX)
VERBATIM)
endif ()

install_target(drmemtrace ${INSTALL_CLIENTS_LIB})
install_target(drcachesim ${INSTALL_CLIENTS_BIN})

set(INSTALL_DRCACHESIM_CONFIG ${INSTALL_CLIENTS_BASE})
Expand Down Expand Up @@ -138,6 +148,20 @@ if (UNIX)
DR_install(FILES "${CONFIG_INSTALL}" DESTINATION ${INSTALL_DRCACHESIM_CONFIG})
register_tool_file("drcachesim")


##################################################
# Test executables
#
# We build larger executables here. All tests are added in suite/tests/.
# Be sure to give the targets qualified test names ("tool.drcache*...").

add_executable(tool.drcacheoff.burst_static tests/burst_static.cpp)
configure_DynamoRIO_static(tool.drcacheoff.burst_static)
use_DynamoRIO_static_client(tool.drcacheoff.burst_static drmemtrace_static)
if (WIN32)
append_property_string(TARGET tool.drcacheoff.burst_static COMPILE_FLAGS "/EHsc")
endif ()

endif (UNIX)

##################################################
Expand Down
97 changes: 97 additions & 0 deletions clients/drcachesim/tests/burst_static.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* **********************************************************
* Copyright (c) 2016 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 GOOGLE, 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.
*/

/* This application links in drmemtrace_static and acquires a trace during
* a "burst" of execution in the middle of the application. It then detaches.
*/

#include <assert.h>
#include <iostream>
#include <math.h>
#include <stdlib.h>

#include "dr_api.h"

bool
my_setenv(const char *var, const char *value)
{
#ifdef UNIX
return setenv(var, value, 1/*override*/) == 0;
#else
return SetEnvironmentVariable(var, value) == TRUE;
#endif
}

static int
do_some_work(int i)
{
static int iters = 512;
double val = (double)i;
for (int i = 0; i < iters; ++i) {
val += sin(val);
}
return (val > 0);
}

int
main(int argc, const char *argv[])
{
static int outer_iters = 2048;
/* We trace a 4-iter burst of execution. */
static int iter_start = outer_iters/3;
static int iter_stop = iter_start + 4;

my_setenv("DYNAMORIO_OPTIONS", "-stderr_mask 0xc -client_lib ';;-offline'");

std::cerr << "pre-DR init\n";
dr_app_setup();
assert(!dr_app_running_under_dynamorio());

for (int i = 0; i < outer_iters; ++i) {
if (i == iter_start) {
std::cerr << "pre-DR start\n";
dr_app_start();
}
if (i >= iter_start && i <= iter_stop)
assert(dr_app_running_under_dynamorio());
else
assert(!dr_app_running_under_dynamorio());
if (do_some_work(i) < 0)
std::cerr << "error in computation\n";
if (i == iter_stop) {
std::cerr << "pre-DR detach\n";
dr_app_stop_and_cleanup();
}
}
std::cerr << "all done\n";
return 0;
}
22 changes: 22 additions & 0 deletions clients/drcachesim/tests/offline-burst_static.templatex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
pre-DR init
pre-DR start
pre-DR detach
all done
Core #0 \(1 thread\(s\)\)
L1I stats:
Hits: *[0-9,\.]*.....
Misses: [0-9]..
.* Miss rate: 0[,\.]..%
L1D stats:
Hits: *[0-9,\.]*.....
Misses: *[0-9]*.
.* Miss rate: 0[,\.]..%
Core #1 \(0 thread\(s\)\)
Core #2 \(0 thread\(s\)\)
Core #3 \(0 thread\(s\)\)
LL stats:
Hits: *[0-9]*
Misses: *[0-9]*..
.* Local miss rate: *[0-9]*[,\.]..%
Child hits: *[0-9,\.]*...
Total miss rate: [0-1][,\.]..%
46 changes: 29 additions & 17 deletions suite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,11 @@ function(torun test key source native standalone_dr dr_ops exe_ops added_out)
# Some apps have enough output that ctest runs out of memory when
# doing its built-in regex cmp so we use a separate script.
# We also use this approach for tests that need custom success tests.
set(cmd_with_at ${rundr} ${exepath} ${exe_ops})
if (DEFINED ${key}_nodr)
set(cmd_with_at ${exepath} ${exe_ops})
else ()
set(cmd_with_at ${rundr} ${exepath} ${exe_ops})
endif ()
# we pass intra-arg spaces via @@ and inter-arg via @ and ; via !
# to get around the pain of trying to quote everything just right:
# much simpler this way.
Expand Down Expand Up @@ -2407,22 +2411,30 @@ if (CLIENT_INTERFACE)
# Test offline traces.
# XXX: we could exclude the pipe files and build the offline trace
# support by itself for Windows and Android.
torunonly_ci(tool.drcacheoff.simple ${ci_shared_app} drcachesim
# We could use drcachesim-simple.templatex if we had the launcher fork
# and print out the "---- <application exited with code 0> ----".
"offline-simple.c" # for templatex basename
"-offline" "" "")
set(tool.drcacheoff.simple_toolname "drcachesim")
set(tool.drcacheoff.simple_basedir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests")
set(tool.drcacheoff.simple_rawtemp ON) # no preprocessor
get_target_path_for_execution(drcachesim_path drcachesim)
prefix_cmd_if_necessary(drcachesim_path ON ${drcachesim_path})
set(tool.drcacheoff.simple_runcmp "${CMAKE_CURRENT_SOURCE_DIR}/runmulti.cmake")
set(tool.drcacheoff.simple_precmd
"${CMAKE_COMMAND}@-E@[email protected]_app.*.log")
set(tool.drcacheoff.simple_postcmd
"${drcachesim_path}@[email protected]_app.*.log")
macro (torunonly_drcacheoff testname exetgt)
torunonly_ci(tool.drcacheoff.${testname} ${exetgt} drcachesim
"offline-${testname}.c" # for templatex basename
"-offline" "" "")
set(tool.drcacheoff.${testname}_toolname "drcachesim")
set(tool.drcacheoff.${testname}_basedir
"${PROJECT_SOURCE_DIR}/clients/drcachesim/tests")
set(tool.drcacheoff.${testname}_rawtemp ON) # no preprocessor
get_target_path_for_execution(drcachesim_path drcachesim)
prefix_cmd_if_necessary(drcachesim_path ON ${drcachesim_path})
set(tool.drcacheoff.${testname}_runcmp
"${CMAKE_CURRENT_SOURCE_DIR}/runmulti.cmake")
set(tool.drcacheoff.${testname}_precmd
"${CMAKE_COMMAND}@-E@remove@memtrace.${exetgt}.*.log")
set(tool.drcacheoff.${testname}_postcmd
"${drcachesim_path}@-infile@memtrace.${exetgt}.*.log")
endmacro()

# We could share drcachesim-simple.templatex if we had the launcher fork
# and print out the "---- <application exited with code 0> ----".
torunonly_drcacheoff(simple ${ci_shared_app})
torunonly_drcacheoff(burst_static tool.drcacheoff.burst_static)
set(tool.drcacheoff.burst_static_nodr ON)

endif ()
endif ()

Expand Down

0 comments on commit d868d95

Please sign in to comment.