From fdff78584ab4daec5be21ef0594849bfddb020ec Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sun, 30 Aug 2026 16:49:15 +0200 Subject: [PATCH] Raise the fd limit for the sample events. External sampling opens one event per CPU for each existing thread (attach) or per CPU (launch) per event type, so a multithreaded target needs many fds. --- monitor/src/monitor.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/monitor/src/monitor.cpp b/monitor/src/monitor.cpp index ebab8e33..cad44d8f 100644 --- a/monitor/src/monitor.cpp +++ b/monitor/src/monitor.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -868,6 +869,25 @@ int main( int argc, char** argv ) return 1; } + // external sampling opens one event per CPU for each existing thread + // (attach) or per CPU (launch) per event type; raise the soft fd limit + // so multithreaded targets fit (failing opens degrade gracefully). + { + struct rlimit rl = {}; + if( getrlimit( RLIMIT_NOFILE, &rl ) == 0 && rl.rlim_cur < 65536 ) + { + const rlim_t want = rl.rlim_max > 65536 ? 65536 : rl.rlim_max; + if( want > rl.rlim_cur ) + { + rl.rlim_cur = want; + if( setrlimit( RLIMIT_NOFILE, &rl ) != 0 ) + { + fprintf( stderr, "tracy-monitor: warning: could not raise RLIMIT_NOFILE (%s); very multithreaded targets may be only partially sampled.\n", strerror( errno ) ); + } + } + } + } + pid_t attachPid = 0; char attachName[128] = {}; bool wantAttach = false;