summaryrefslogtreecommitdiff
path: root/test/xray/TestCases/Linux/coverage-sample.cc
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2017-12-14 02:51:20 +0000
committerDean Michael Berris <dberris@google.com>2017-12-14 02:51:20 +0000
commit089c958f36cf198c6e9ca431b5abd3ea1e597827 (patch)
treed9bdf564857e5bbe270d9fabd667391f1fe00417 /test/xray/TestCases/Linux/coverage-sample.cc
parent993d9a6a013d6618bc9690a32a5a6a57a474d707 (diff)
[XRay][compiler-rt] Coalesce calls to mprotect to reduce patching overhead
Summary: Before this change, XRay would conservatively patch sections of the code one sled at a time. Upon testing/profiling, this turns out to take an inordinate amount of time and cycles. For an instrumented clang binary, the cycles spent both in the patching/unpatching routine constituted 4% of the cycles -- this didn't count the time spent in the kernel while performing the mprotect calls in quick succession. With this change, we're coalescing the number of calls to mprotect from being linear to the number of instrumentation points, to now being a lower constant when patching all the sleds through `__xray_patch()` or `__xray_unpatch()`. In the case of calling `__xray_patch_function()` or `__xray_unpatch_function()` we're now doing an mprotect call once for all the sleds for that function (reduction of at least 2x calls to mprotect). Reviewers: kpw, eizan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D41153 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320664 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/xray/TestCases/Linux/coverage-sample.cc')
-rw-r--r--test/xray/TestCases/Linux/coverage-sample.cc15
1 files changed, 8 insertions, 7 deletions
diff --git a/test/xray/TestCases/Linux/coverage-sample.cc b/test/xray/TestCases/Linux/coverage-sample.cc
index 9ec22dcd6..62c13ba3d 100644
--- a/test/xray/TestCases/Linux/coverage-sample.cc
+++ b/test/xray/TestCases/Linux/coverage-sample.cc
@@ -9,6 +9,7 @@
#include <set>
#include <cstdio>
+#include <cassert>
std::set<int32_t> function_ids;
@@ -36,9 +37,9 @@ std::set<int32_t> function_ids;
[[clang::xray_always_instrument]] int main(int argc, char *argv[]) {
__xray_set_handler(coverage_handler);
- __xray_patch();
+ assert(__xray_patch() == XRayPatchingStatus::SUCCESS);
foo();
- __xray_unpatch();
+ assert(__xray_unpatch() == XRayPatchingStatus::SUCCESS);
// print out the function_ids.
printf("first pass.\n");
@@ -58,11 +59,11 @@ std::set<int32_t> function_ids;
// patch the functions we've called before.
for (const auto id : called_fns)
- __xray_patch_function(id);
+ assert(__xray_patch_function(id) == XRayPatchingStatus::SUCCESS);
// then call them again.
foo();
- __xray_unpatch();
+ assert(__xray_unpatch() == XRayPatchingStatus::SUCCESS);
// confirm that we've seen the same functions again.
printf("second pass.\n");
@@ -76,10 +77,10 @@ std::set<int32_t> function_ids;
// Now we want to make sure that if we unpatch one, that we're only going to
// see two calls of the coverage_handler.
function_ids.clear();
- __xray_patch();
- __xray_unpatch_function(1);
+ assert(__xray_patch() == XRayPatchingStatus::SUCCESS);
+ assert(__xray_unpatch_function(1) == XRayPatchingStatus::SUCCESS);
foo();
- __xray_unpatch();
+ assert(__xray_unpatch() == XRayPatchingStatus::SUCCESS);
// confirm that we don't see function id one called anymore.
printf("missing 1.\n");