summaryrefslogtreecommitdiff
path: root/test/esan
diff options
context:
space:
mode:
authorDerek Bruening <bruening@google.com>2016-06-03 16:14:07 +0000
committerDerek Bruening <bruening@google.com>2016-06-03 16:14:07 +0000
commitd5bcae95c1d1b013893bd3ca6cc04e7f7f5d5736 (patch)
tree97124f984e3e8aa833e4960444193770683a4730 /test/esan
parent031c1e40660c8eaaa418ce84b16b82b37ca32652 (diff)
[esan] Add sideline itimer support
Summary: Adds support for creating a separate thread for performing "sideline" actions on a periodic basis via an itimer. A new class SidelineThread implements this feature, exposing a sampling callback to the caller. Adds initial usage of sideline sampling to the working set tool. For now it simply prints the usage at each snapshot at verbosity level 1. Adds a test of this behavior. Adds a new option -record_snapshots to control whether we sample and a new option -sample_freq to control the periodicity of the sampling. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits, kubabrecka Differential Revision: http://reviews.llvm.org/D20751 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@271682 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/esan')
-rw-r--r--test/esan/TestCases/workingset-samples.cpp26
-rw-r--r--test/esan/Unit/circular_buffer.cpp2
-rw-r--r--test/esan/lit.cfg1
3 files changed, 28 insertions, 1 deletions
diff --git a/test/esan/TestCases/workingset-samples.cpp b/test/esan/TestCases/workingset-samples.cpp
new file mode 100644
index 000000000..cb0ce01e8
--- /dev/null
+++ b/test/esan/TestCases/workingset-samples.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_esan_wset -O0 %s -o %t 2>&1
+// RUN: %env_esan_opts=verbosity=1 %run %t 2>&1 | FileCheck %s
+
+#include <sched.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+const int size = 0x1 << 25; // 523288 cache lines
+
+int main(int argc, char **argv) {
+ char *buf = (char *)mmap(0, size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ // Try to increase the probability that the sideline thread is
+ // scheduled. Unfortunately we can't do proper synchronization
+ // without some form of annotation or something.
+ sched_yield();
+ // Do enough work to get at least 2 samples.
+ for (int i = 0; i < size; ++i)
+ buf[i] = i;
+ munmap(buf, size);
+ // CHECK: {{.*}}EfficiencySanitizer: snapshot {{.*}}
+ // CHECK-NEXT: {{.*}}EfficiencySanitizer: snapshot {{.*}}
+ // CHECK: {{.*}} EfficiencySanitizer: the total working set size: 32 MB (5242{{[0-9][0-9]}} cache lines)
+ return 0;
+}
diff --git a/test/esan/Unit/circular_buffer.cpp b/test/esan/Unit/circular_buffer.cpp
index a788418b7..00999a272 100644
--- a/test/esan/Unit/circular_buffer.cpp
+++ b/test/esan/Unit/circular_buffer.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_unit -O0 %s -o %t 2>&1
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %env_esan_opts="record_snapshots=0" %run %t 2>&1 | FileCheck %s
#include "esan/esan_circular_buffer.h"
#include "sanitizer_common/sanitizer_placement_new.h"
diff --git a/test/esan/lit.cfg b/test/esan/lit.cfg
index 9eb296d90..5f7ba16dc 100644
--- a/test/esan/lit.cfg
+++ b/test/esan/lit.cfg
@@ -17,6 +17,7 @@ wset_cflags = (["-fsanitize=efficiency-working-set"] + base_cflags)
esan_incdir = config.test_source_root + "/../../lib"
unit_cxxflags = (["-I%s" % esan_incdir, "-std=c++11",
# We need to link with the esan runtime.
+ # Tests should pass %env_esan_opts="record_snapshots=0".
"-fsanitize=efficiency-working-set"] + base_cxxflags)
def build_invocation(compile_flags):