summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2017-12-05 12:08:56 +0000
committerDean Michael Berris <dberris@google.com>2017-12-05 12:08:56 +0000
commitfaed8464752e5c9ff234c96f167dda4bc448e618 (patch)
tree0c346c35f2fe597a55695eb30ca3db177af1e9b4 /test
parent0234ef5fc965f8b87cd249997459dd885602972d (diff)
[XRay][compiler-rt] Implement logging implementation registration
Summary: This change allows for registration of multiple logging implementations through a central mechanism in XRay, mapping an implementation to a "mode". Modes are strings that are used as keys to determine which implementation to install through a single API. This mechanism allows users to choose which implementation to install either from the environment variable 'XRAY_OPTIONS' with the `xray_mode=` flag, or programmatically using the `__xray_select_mode(...)` function. Here, we introduce two API functions for the XRay logging: __xray_log_register_mode(Mode, Impl): Associates an XRayLogImpl to a string Mode. We can only have one implementation associated with a given Mode. __xray_log_select_mode(Mode): Finds the associated Impl for Mode and installs it as if by calling `__xray_set_log_impl(...)`. Along with these changes, we also deprecate the xray_naive_log and xray_fdr_log flags and encourage users to instead use the xray_mode flag. Reviewers: kpw, dblaikie, eizan, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D40703 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@319759 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/xray/TestCases/Linux/logging-modes.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/test/xray/TestCases/Linux/logging-modes.cc b/test/xray/TestCases/Linux/logging-modes.cc
new file mode 100644
index 000000000..22f6942b7
--- /dev/null
+++ b/test/xray/TestCases/Linux/logging-modes.cc
@@ -0,0 +1,59 @@
+// Check that we can install an implementation associated with a mode.
+//
+// RUN: %clangxx_xray -std=c++11 %s -o %t
+// RUN: %run %t | FileCheck %s
+//
+// UNSUPPORTED: target-is-mips64,target-is-mips64el
+
+#include "xray/xray_interface.h"
+#include "xray/xray_log_interface.h"
+#include <cassert>
+#include <cstdio>
+
+[[clang::xray_never_instrument]] void printing_handler(int32_t fid,
+ XRayEntryType) {
+ thread_local volatile bool printing = false;
+ if (printing)
+ return;
+ printing = true;
+ std::printf("printing %d\n", fid);
+ printing = false;
+}
+
+[[clang::xray_never_instrument]] XRayLogInitStatus
+printing_init(size_t, size_t, void *, size_t) {
+ return XRayLogInitStatus::XRAY_LOG_INITIALIZED;
+}
+
+[[clang::xray_never_instrument]] XRayLogInitStatus printing_finalize() {
+ return XRayLogInitStatus::XRAY_LOG_FINALIZED;
+}
+
+[[clang::xray_never_instrument]] XRayLogFlushStatus printing_flush_log() {
+ return XRayLogFlushStatus::XRAY_LOG_FLUSHED;
+}
+
+[[clang::xray_always_instrument]] void callme() { std::printf("called me!\n"); }
+
+static bool unused = [] {
+ assert(__xray_log_register_mode("custom",
+ {printing_init, printing_finalize,
+ printing_handler, printing_flush_log}) ==
+ XRayLogRegisterStatus::XRAY_REGISTRATION_OK);
+ return true;
+}();
+
+int main(int argc, char **argv) {
+ assert(__xray_log_select_mode("custom") ==
+ XRayLogRegisterStatus::XRAY_REGISTRATION_OK);
+ assert(__xray_patch() == XRayPatchingStatus::SUCCESS);
+ assert(__xray_log_init(0, 0, nullptr, 0) ==
+ XRayLogInitStatus::XRAY_LOG_INITIALIZED);
+ // CHECK: printing {{.*}}
+ callme(); // CHECK: called me!
+ // CHECK: printing {{.*}}
+ assert(__xray_log_finalize() == XRayLogInitStatus::XRAY_LOG_FINALIZED);
+ assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
+ assert(__xray_log_select_mode("not-found") ==
+ XRayLogRegisterStatus::XRAY_MODE_NOT_FOUND);
+}