[clang] [compiler-rt] [XRay][Darwin] Enable XRay runtime on macOS (arm64/x86_64) (PR #196848)
Dan Blackwell via llvm-commits
llvm-commits at lists.llvm.org
Tue May 12 02:40:33 PDT 2026
================
@@ -0,0 +1,57 @@
+// Verify that XRay produces monotonically increasing timestamps on macOS.
+
+// RUN: %clangxx_xray -fxray-instruction-threshold=1 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// REQUIRES: target={{(arm64|x86_64)-apple-.*}}
+
+#include "xray/xray_interface.h"
+#include <cstdint>
+#include <cstdio>
+
+static uint64_t last_ts = 0;
+static int monotonic_violations = 0;
+static int calls = 0;
+
+#if defined(__x86_64__)
+static uint64_t rdtsc() {
+ unsigned int lo, hi;
+ __asm__ volatile("rdtsc" : "=a"(lo), "=d"(hi));
+ return ((uint64_t)hi << 32) | lo;
+}
+#else
+// clang-format off
+#include <time.h>
+// clang-format on
+[[clang::xray_never_instrument]] static uint64_t rdtsc() {
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
----------------
DanBlackwell wrote:
This seems to be duplicating internal implementation details of the runtime - should this be a unit test?
https://github.com/llvm/llvm-project/pull/196848
More information about the llvm-commits
mailing list