-
Notifications
You must be signed in to change notification settings - Fork 570
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#3048 drcachesim record funcs: infrastructure #3057
Changes from 14 commits
1e28578
f99373e
093cb57
3ba97a3
d1713b9
844b9a3
bb1ead5
32a8f98
647ecec
acba3bd
871c03c
6ec4a13
23e725c
f1ba45b
0c170a9
fafa638
90fc899
341f812
468d837
1943e10
d635d36
d358bf2
8d6c0a2
4f45cdf
0f64c4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,3 +333,39 @@ droption_t<bool> op_reuse_verify_skip | |
"Verifies every skip list-calculated reuse distance with a full list walk. " | ||
"This incurs significant additional overhead. This option is only available " | ||
"in debug builds."); | ||
|
||
#define OP_RECORD_FUNC_ITEM_SEP "&" | ||
// XXX i#3048: replace function return address with function callstack | ||
// XXX i#3048: add a section to drcachesim.dox.in on function tracing | ||
droption_t<std::string> op_record_function | ||
(DROPTION_SCOPE_ALL, "record_function", DROPTION_FLAG_ACCUMULATE, | ||
OP_RECORD_FUNC_ITEM_SEP, "", | ||
"Record invocations trace for the specified function(s).", | ||
"Record invocations trace for the specified function(s) in the option" | ||
" value. Default value is empty. The value should fit this format:" | ||
" function_name|function_id|func_args_num" | ||
" (example: -record_function \"memset|10|3\"). The trace would contain" | ||
" information for function return address, function argument value(s)," | ||
" and function return value. We only record pointer-sized arguments and" | ||
" return value. The trace is labeled with the function_id via an ID entry" | ||
" prior to each set of value entries." | ||
" Note that the provided function id should be unique, and not collide with" | ||
" existing heap functions (see -record_heap_value ) if record_heap" | ||
" option is enabled."); | ||
droption_t<bool> op_record_heap | ||
(DROPTION_SCOPE_ALL, "record_heap", false, | ||
"Enable recording trace for the defined heap functions.", | ||
"It is a convenient option to enable recording trace for the defined heap" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/convenient/convenience/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
" functions in -record_heap_value. Specify this option is equivalent to" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grammar: s/Specify/Specifying/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
" -record_function [heap_functions], where [heap_functions] is" | ||
" the value in -record_heap_value."); | ||
droption_t<std::string> op_record_heap_value | ||
(DROPTION_SCOPE_ALL, "record_heap_value", DROPTION_FLAG_ACCUMULATE, | ||
OP_RECORD_FUNC_ITEM_SEP, | ||
"malloc|0|1" OP_RECORD_FUNC_ITEM_SEP "free|1|1" OP_RECORD_FUNC_ITEM_SEP | ||
"tc_malloc|2|1" OP_RECORD_FUNC_ITEM_SEP "tc_free|3|1" OP_RECORD_FUNC_ITEM_SEP | ||
"__libc_malloc|4|1" OP_RECORD_FUNC_ITEM_SEP "__libc_free|5|1", | ||
" The actual value of the defined heap functions.", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would instead say There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
" The actual value of the defined heap functions. Value should fit the same" | ||
" format required by -record_function. These functions will not" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The separator is not described under -record_function, though, so that makes it a little confusing. Probably best to explain the separator under -record_function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
" be traced unless -record_heap is specified."); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,6 +191,35 @@ typedef enum { | |
*/ | ||
TRACE_MARKER_TYPE_CPU_ID, | ||
|
||
/** | ||
* The marker value contains function id defined by the user in droption. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. grammar: s/function/the function/ The user doesn't know what "in droption" means: s/droption/the -record_function option/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
*/ | ||
TRACE_MARKER_TYPE_FUNC_ID, | ||
|
||
// XXX i#3048: replace return address with callstack information. | ||
/** | ||
* The marker value contains the return address of the function call, | ||
* whose id is specified by the closest previous | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My prior review comments here were not acted on: if you disagree with a review request, that's certainly your prerogative, but please reply either way to say whether you're acting on the request or why you're not -- please don't skip over it with no comment because then the reviewer wonders whether some other requests were silently skipped over...I shouldn't have to go double-check all my prior comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Skipping those comments is definitely NOT deliberate... It is my bad to skip them. Because sometimes I made several commits, and a non-relevant code change might touch the lines that are covered by a comment, which will then turn this comment into hidden, which cause me to skip it. I should have been aware of that a hidden commit is not necessary addressed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* marker entry. | ||
*/ | ||
TRACE_MARKER_TYPE_FUNC_RETADDR, | ||
|
||
/** | ||
* The marker value contains one argument value of the function call, | ||
* whose id is specified by the closest previous #TRACE_MARKER_TYPE_FUNC_ID | ||
* marker entry. The number of such entries for one function invocation is | ||
* expected to be equal to the specified arugment in -record_function or | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My prior review comment was trying to say, why say "expected to be"? That makes it sound like either it's not under our control or it varies somehow...just say "is equal". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spelling (please write these user-facing docs carefully, just like you would with code): argument There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* pre-defined functions in -record_heap (if enabled). | ||
*/ | ||
TRACE_MARKER_TYPE_FUNC_ARG, | ||
|
||
/** | ||
* The marker value contains return value of the function call, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another skipped prior review comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
* whose id is specified by the closest previous #TRACE_MARKER_TYPE_FUNC_ID | ||
* marker entry | ||
*/ | ||
TRACE_MARKER_TYPE_FUNC_RETVAL, | ||
|
||
// ... | ||
// These values are reserved for future built-in marker types. | ||
// ... | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* ********************************************************** | ||
* Copyright (c) 2016-2017 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 and memory allocations (malloc() and free()) | ||
* in the middle of the application. It then detaches. Later it re-attaches | ||
* and detaches again for several times. | ||
*/ | ||
|
||
/* Like burst_static we deliberately do not include configure.h here */ | ||
|
||
#include "dr_api.h" | ||
#include <assert.h> | ||
#include <iostream> | ||
#include <math.h> | ||
#include <stdlib.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 arg) | ||
{ | ||
static const int iters = 1000; | ||
static double *vals[iters]; | ||
|
||
double val = (double)arg; | ||
for (int i = 0; i < iters; ++i) { | ||
vals[i] = (double *)malloc(sizeof(double)); | ||
*vals[i] = sin(val); | ||
val += *vals[i]; | ||
} | ||
for (int i = 0; i < iters; i++) { | ||
val += *vals[i]; | ||
} | ||
for (int i = 0; i < iters; i++) { | ||
free(vals[i]); | ||
} | ||
return (val > 0); | ||
} | ||
|
||
int | ||
main(int argc, const char *argv[]) | ||
{ | ||
/* We also test -rstats_to_stderr */ | ||
if (!my_setenv("DYNAMORIO_OPTIONS", "-stderr_mask 0xc -rstats_to_stderr" | ||
" -client_lib ';;-offline -record_heap" | ||
" -record_function \"malloc|0|1\"'")) | ||
std::cerr << "failed to set env var!\n"; | ||
|
||
for (int i = 0; i < 3; i++) { | ||
std::cerr << "pre-DR init\n"; | ||
dr_app_setup(); | ||
assert(!dr_app_running_under_dynamorio()); | ||
|
||
std::cerr << "pre-DR start\n"; | ||
if (do_some_work(i * 1) < 0) | ||
std::cerr << "error in computation\n"; | ||
|
||
dr_app_start(); | ||
if (do_some_work(i * 2) < 0) | ||
std::cerr << "error in computation\n"; | ||
std::cerr << "pre-DR detach\n"; | ||
dr_app_stop_and_cleanup(); | ||
|
||
if (do_some_work(i * 3) < 0) | ||
std::cerr << "error in computation\n"; | ||
std::cerr << "all done\n"; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
#if defined(UNIX) && defined(TEST_APP_DR_CLIENT_MAIN) | ||
# ifdef __cplusplus | ||
extern "C" { | ||
# endif | ||
|
||
/* This dr_client_main should be called instead of the one in tracer.cpp */ | ||
DR_EXPORT void | ||
dr_client_main(client_id_t id, int argc, const char *argv[]) | ||
{ | ||
std::cerr << "app dr_client_main\n"; | ||
drmemtrace_client_main(id, argc, argv); | ||
} | ||
|
||
# ifdef __cplusplus | ||
} | ||
# endif | ||
#endif /* UNIX && TEST_APP_DR_CLIENT_MAIN */ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pre-DR init | ||
Warning: duplicated function id .* | ||
.* | ||
pre-DR start | ||
pre-DR detach | ||
DynamoRIO statistics: | ||
*Peak threads under DynamoRIO control : *1 | ||
.* | ||
all done | ||
.* | ||
.* 4000 function id markers.* | ||
.* 2000 function return address markers.* | ||
.* 2000 function argument markers.* | ||
.* 2000 function return value markers.* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: inconsistent option reference: -record_heap
nit: space before )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done