-
Notifications
You must be signed in to change notification settings - Fork 566
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
i#1729 offline traces: add static bursty trace support
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
1 parent
cb3cfd9
commit d868d95
Showing
4 changed files
with
187 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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][,\.]..% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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 () | ||
|
||
|