summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/xray_fdr_logging.cc
diff options
context:
space:
mode:
authorKeith Wyss <wyssman@gmail.com>2018-04-17 21:28:53 +0000
committerKeith Wyss <wyssman@gmail.com>2018-04-17 21:28:53 +0000
commitadb092e0aefc7da8fe68d5b49f0e61ae68d8f595 (patch)
treed1e87c5bb1aa6e289cd13dabf5fc18abd010ad1e /compiler-rt/lib/xray/xray_fdr_logging.cc
parent2b8158f441da74d8432c7629b005a7107a44186b (diff)
downloadbcm5719-llvm-adb092e0aefc7da8fe68d5b49f0e61ae68d8f595.tar.gz
bcm5719-llvm-adb092e0aefc7da8fe68d5b49f0e61ae68d8f595.zip
Implement trampoline and handler for typed xray event tracing.
Summary: Compiler-rt support first before defining the __xray_typedevent() lowering in llvm. I'm looking for some early feedback before I touch much more code. Reviewers: dberris Subscribers: delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D43668 llvm-svn: 330218
Diffstat (limited to 'compiler-rt/lib/xray/xray_fdr_logging.cc')
-rw-r--r--compiler-rt/lib/xray/xray_fdr_logging.cc58
1 files changed, 58 insertions, 0 deletions
diff --git a/compiler-rt/lib/xray/xray_fdr_logging.cc b/compiler-rt/lib/xray/xray_fdr_logging.cc
index 72776e2c17f..fcb33fc87a5 100644
--- a/compiler-rt/lib/xray/xray_fdr_logging.cc
+++ b/compiler-rt/lib/xray/xray_fdr_logging.cc
@@ -289,6 +289,63 @@ void fdrLoggingHandleCustomEvent(void *Event,
endBufferIfFull();
}
+void fdrLoggingHandleTypedEvent(
+ uint16_t EventType, const void *Event,
+ std::size_t EventSize) noexcept XRAY_NEVER_INSTRUMENT {
+ using namespace __xray_fdr_internal;
+ auto TC = getTimestamp();
+ auto &TSC = TC.TSC;
+ auto &CPU = TC.CPU;
+ RecursionGuard Guard{Running};
+ if (!Guard)
+ return;
+ if (EventSize > std::numeric_limits<int32_t>::max()) {
+ using Empty = struct {};
+ static Empty Once = [&] {
+ Report("Event size too large = %zu ; > max = %d\n", EventSize,
+ std::numeric_limits<int32_t>::max());
+ return Empty();
+ }();
+ (void)Once;
+ }
+ int32_t ReducedEventSize = static_cast<int32_t>(EventSize);
+ auto &TLD = getThreadLocalData();
+ if (!isLogInitializedAndReady(TLD.BQ, TSC, CPU, clock_gettime))
+ return;
+
+ // Here we need to prepare the log to handle:
+ // - The metadata record we're going to write. (16 bytes)
+ // - The additional data we're going to write. Currently, that's the size of
+ // the event we're going to dump into the log as free-form bytes.
+ if (!prepareBuffer(TSC, CPU, clock_gettime, MetadataRecSize + EventSize)) {
+ TLD.BQ = nullptr;
+ return;
+ }
+ // Write the custom event metadata record, which consists of the following
+ // information:
+ // - 8 bytes (64-bits) for the full TSC when the event started.
+ // - 4 bytes (32-bits) for the length of the data.
+ // - 2 bytes (16-bits) for the event type. 3 bytes remain since one of the
+ // bytes has the record type (Metadata Record) and kind (TypedEvent).
+ // We'll log the error if the event type is greater than 2 bytes.
+ // Event types are generated sequentially, so 2^16 is enough.
+ MetadataRecord TypedEvent;
+ TypedEvent.Type = uint8_t(RecordType::Metadata);
+ TypedEvent.RecordKind =
+ uint8_t(MetadataRecord::RecordKinds::TypedEventMarker);
+ constexpr auto TSCSize = sizeof(TC.TSC);
+ std::memcpy(&TypedEvent.Data, &ReducedEventSize, sizeof(int32_t));
+ std::memcpy(&TypedEvent.Data[sizeof(int32_t)], &TSC, TSCSize);
+ std::memcpy(&TypedEvent.Data[sizeof(int32_t) + TSCSize], &EventType,
+ sizeof(EventType));
+ std::memcpy(TLD.RecordPtr, &TypedEvent, sizeof(TypedEvent));
+
+ TLD.RecordPtr += sizeof(TypedEvent);
+ std::memcpy(TLD.RecordPtr, Event, ReducedEventSize);
+ incrementExtents(MetadataRecSize + EventSize);
+ endBufferIfFull();
+}
+
XRayLogInitStatus fdrLoggingInit(std::size_t BufferSize, std::size_t BufferMax,
void *Options,
size_t OptionsSize) XRAY_NEVER_INSTRUMENT {
@@ -352,6 +409,7 @@ XRayLogInitStatus fdrLoggingInit(std::size_t BufferSize, std::size_t BufferMax,
// Install the actual handleArg0 handler after initialising the buffers.
__xray_set_handler(fdrLoggingHandleArg0);
__xray_set_customevent_handler(fdrLoggingHandleCustomEvent);
+ __xray_set_typedevent_handler(fdrLoggingHandleTypedEvent);
__sanitizer::atomic_store(&LoggingStatus,
XRayLogInitStatus::XRAY_LOG_INITIALIZED,
OpenPOWER on IntegriCloud