From 71d2513d0e6f2e3fcd77b8ed7cd5705edfa87867 Mon Sep 17 00:00:00 2001 From: Lectem Date: Tue, 20 Oct 2026 19:54:22 +0200 Subject: [PATCH] Share one ring per event kind and CPU in the sampling client Sampling events of one kind on one CPU now share a ring: the first thread's event owns it, and the others are redirected into it with PERF_EVENT_IOC_SET_OUTPUT. Redirected fds are kept open and enabled by the worker. --- public/client/TracySysTrace.cpp | 46 ++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/public/client/TracySysTrace.cpp b/public/client/TracySysTrace.cpp index 58ec5e80..4672c485 100644 --- a/public/client/TracySysTrace.cpp +++ b/public/client/TracySysTrace.cpp @@ -420,10 +420,22 @@ struct SysTraceState int ctxBufferIdx = 0; bool ctxSwitchCallchain = false; RingBuffer* ring = nullptr; + int* redirectFd = nullptr; + int numRedirectFd = 0; }; static SysTraceState s_state; +// Sampling events of one kind on one CPU share a ring: the first thread's event owns it +// (the sharedRingFd array, per event kind and CPU), the others are redirected into it with +// PERF_EVENT_IOC_SET_OUTPUT. Redirected fds are kept open, and enabled by the worker. +static void CloseRedirectFds() +{ + for( int i=0; i