920 Commits
Author SHA1 Message Date
Simon BoorerandClaude Opus 5.5 56c9612137 Keep the dladdr symbol address for frames libbacktrace can't resolve.
When libbacktrace has no debug info for a pc, CallstackDataCb names the
frame from dladdr but keeps libbacktrace's lowaddr, which is 0 there, as
its symbol address, and SymInfoCallback then overwrites it with
libbacktrace's symval, also 0, since libbacktrace has no symbol for it
either. Every such frame (on macOS, every frame in a system library) gets
symbol address 0, so the sampling statistics count all of them as one
symbol with no name.

Record dli_saddr as the frame's symbol address, as the dladdr-only
DecodeCallstackPtr (TRACY_HAS_CALLSTACK 5) does, and have SymInfoCallback
keep the address CallstackDataCb found when libbacktrace reports no
symbol.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 13:29:21 +00:00
Bartosz Taudul 26a27896ff Merge pull request #1507 from fknorr/econnrefused
Use poll()/getsockopt() to detect ECONNREFUSED
2026-11-17 17:34:34 +01:00
Bartosz Taudul aa5240ca19 Use LZ4_initStream instead of deprecated reset calls. 2026-11-14 13:55:43 +01:00
Bartosz Taudul 2ce0e5ad9b Bump LZ4 to 1.11.1. 2026-11-14 13:55:43 +01:00
Fabian Knorr aa8a4c1264 Socket: Use poll()/select() + getsockopt() to reliably detect ECONNREFUSED
On macOS, calling connect() twice on a non-blocking socket does not allow distinguishing between successful and unsuccessful completion.

poll() / WSAPoll() would be the correct cross-platform API to check for socket readiness, however on Windows before 10 2004 WSAPoll() never completes on a failed connect().
https://learn.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-connect documents that select() should be used instead. select() is an inferior choice on Unices,
where descriptors (ints) in fd_set are limited to < FD_SETSIZE (1024).
2026-11-13 09:53:05 +01:00
Clément GrégoireandClaude Opus 5.5 6fddfdbe22 Client: don't overflow the broadcast program name
GetBroadcastMessage is given strlen(m_programName), which can exceed
WelcomeMessageProgramNameSize when the program name is set with a long
string (e.g. by the Python bindings). Clamp the length inside
GetBroadcastMessage, which owns the fixed-size buffer.

Also null-terminate names stored in the Python NameBuffer and reject
names that leave no room for the terminator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 18:19:40 +01:00
Bartosz Taudul f2a4f2529e Release 0.15.0. 2026-11-05 21:02:56 +01:00
Bartosz Taudul 3dced9c241 Bump LZ4 to 1.11.0. 2026-11-05 00:58:54 +01:00
Bartosz Taudul be917984f5 Advance the system time deadline on failed samples. 2026-11-04 19:06:16 +01:00
Bartosz Taudul 094be55320 Handle system time sampling failures safely. 2026-11-04 19:06:15 +01:00
Bartosz Taudul 453ecc3b74 Add GpuContextNone enumerator. 2026-11-04 19:06:13 +01:00
Bartosz Taudul 0766a5ce7e Fix the sanitizer detection on older preprocessors. 2026-11-02 20:40:03 +01:00
Bartosz Taudul e2600f0314 Use raw write syscall for safe copy under AddressSanitizer.
The sanitizer's write() interceptor aborts the process when the buffer
touches poisoned bytes, even if the pages are mapped. Global redzones
are such bytes, and clang counts them in the global's symbol size, so
a symbol code query can request a range spanning the redzone and kill
the profiled app. syscall() is not intercepted; the kernel does the
copy and fails unmapped pages with EFAULT, like without the sanitizer.
2026-11-02 20:09:51 +01:00
Bartosz Taudul af6b4fa729 Merge pull request #1504 from Lectem/windows-dll-unload-hang
Don't deadlock when joining threads from a DLL being unloaded.
2026-10-29 19:20:29 +01:00
Bartosz TaudulandTim Jammer 63c0a2f723 Leak statics that profiler threads use during exit.
Function-local statics are destroyed in reverse order of initialization,
on the same atexit stack that carries the shutdown handler installed at
profiler startup. Statics initialized lazily while profiling are
therefore destroyed before that handler runs, while worker and network
threads may still be using them; with TRACY_NO_EXIT the handler blocks
in the exit sequence until the server disconnects, keeping the threads
live across the entire destruction. On Android this let a symbol query
execute `s_mappings = ParseMappings()` on a destroyed vector, causing a
use-after-free and a double free. The legacy-GCC thread data key carried
the same hazard: pthread_key_delete at static destruction while threads
could still call pthread_getspecific on the key.

Construct the objects on the heap and never free them. The allocations
are one-time and stay referenced, so leak sanitizers classify them as
still reachable.

Co-authored-by: Tim Jammer <tim.jammer@web.de>
2026-10-29 18:17:07 +01:00
Bartosz Taudul aaccc47036 Merge pull request #1490 from Lectem/shared-sampling-rings
Shared sampling rings for monitor
2026-10-29 17:51:31 +01:00
Clément Grégoire a181b62a6a Don't deadlock when joining threads from a DLL being unloaded.
When Tracy is built into a DLL, the static `Profiler` is destroyed inside `DllMain(DLL_PROCESS_DETACH)` while the loader lock is held. `Thread::~Thread()` waited for the thread to exit, but a thread can only exit by taking the loader lock for `DLL_THREAD_DETACH`, so `FreeLibrary` hung forever (typically in `s_symbolThread->~Thread()`).

The thread function now signals an event when it is done and parks in an alertable sleep instead of returning. The destructor waits for that event rather than for the thread itself. Inside a loader callout (detected with `RtlIsThreadWithinLoaderCallout`) the parked thread is terminated, which is safe as it holds no locks at that point. Everywhere else it is woken with an APC and exits normally, so `thread_local` destructors still run. If the ntdll export is unavailable, the previous behaviour is kept.

Same approach as `asio::detail::win_thread`.

Reproduced with a test DLL embedding Tracy (`TRACY_ON_DEMAND`) loaded and freed in a loop: `FreeLibrary` hung on the first unload before the change, and 100 cycles pass after it when the DLL stays loaded for at least a few ms. Unloading immediately after loading still hangs if the Tracy threads are blocked on the loader lock during their startup (e.g. in `gethostname` or `SymInitialize`), as they never reach the parking point. Startup and shutdown timings are unchanged.
2026-10-29 14:14:20 +01:00
Clément Grégoire 4ff170540e Address review comments on the shared sampling rings
Move the shared ring comment onto `OpenSampleEvent`, where the sharing happens. Name the number of sampling event kinds with `NumSampleEventKinds` instead of using `EventVsync` directly, and assert in `OpenSampleEvent` that the event id is below it.
2026-10-29 13:15:46 +01:00
Alan TseandClaude Sonnet 5.5 a03c657cb5 fix(d3d11): resume GPU timing after reconnect
When the client disconnects while a disjoint query result is pending,
the not-connected branch of Collect resets the checkpoints without
re-issuing Begin. The next connected Collect then calls End twice, so
no GpuTime items are produced and every later connection shows GPU
zones with no timings.

Drain the pending result and Begin the query before resetting.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01L3DnWkXakGRgz9C8BaLM47
2026-10-27 02:32:29 -07:00
tuket 270691f485 remove assert that was failing in Android 9 2026-10-26 09:02:42 +01:00
Juan Jose Casafranca d0ddff87da Rename TRACY_CUDA_SERIALIZED_KERNEL_ACTIVITY to TRACY_CUDA_FORCE_KERNEL_SERIAL_EXECUTION. 2026-10-22 21:30:24 +00:00
Juan Jose Casafranca 52ebe6c258 Add an option to collect CUDA kernel activity as CUPTI_ACTIVITY_KIND_KERNEL.
With CONCURRENT_KERNEL, MEMCPY or MEMSET activity enabled, CUPTI 13.0
faults the device with an illegal memory access once the nodes inside CUDA
graph conditional (IF/WHILE) bodies have executed about 699,050 times in a
context. TRACY_CUDA_SERIALIZED_KERNEL_ACTIVITY enables KERNEL activity
instead, which avoids the fault at the cost of serializing kernels. In that
mode CUPTI reports conditional-body kernels once per graph launch without
timestamps, so those records are skipped.
2026-10-22 19:45:43 +00:00
Lectem 71d2513d0e 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.
2026-10-20 19:54:22 +02:00
Lectem b8935a8a56 Group sampling globals into SysTraceState
Move the sampling client's file-level globals into a single SysTraceState
struct, so that the state of a trace session is in one place.
2026-10-20 19:54:22 +02:00
Bartosz Taudul 23755c9fc8 Merge pull request #1478 from jonathanharg/master
Various improvements for Apple platforms
2026-10-04 01:27:11 +02:00
Jonathan Hargreaves f977c27ab7 Emit pthread ids for sampled callstacks on Apple platforms
Previously mach thread ids were emitted, which wouldn't match those
recorded in instrumented zones.
2026-10-03 23:11:17 +01:00
Jonathan Hargreaves 41bb4f58b4 Automatic thread naming on Apple 2026-10-03 23:11:05 +01:00
develOseven fbf3a3d738 Add C API for Sections 2026-10-03 23:22:20 +02:00
Jonathan Hargreaves 275b578c1b Improve Apple platform details
- Include OS version
- Add CPU details
- Correct username
2026-10-02 22:01:25 +01:00
jvf.dev 3d861a4bff Wrap if-based helpers in do-while and remove trailing semicolons 2026-09-30 21:00:07 +01:00
jvf.dev 3bd767a6e9 Remove semicolons from previously missed macros 2026-09-30 20:55:00 +01:00
jvf.dev 39484791f2 Standardize macro semicolon usage
Remove semicolons from public macros
2026-09-30 02:50:54 +01:00
Bartosz Taudul d92cc589d6 Fix TracyCSharedLockAnnounce macro name in disabled builds. 2026-09-21 18:14:12 +02:00
Bartosz Taudul b14dad2c42 Lock release event must happen before the actual release.
With unlock -> notify order the thread can be preempted by other thread,
for example one that wants to lock the very same lock. This would produce
incorrect ordering of lock release and acquire events.
2026-09-21 18:14:11 +02:00
Bartosz Taudul 3ed0a42214 Store lock events with a 16-bit thread slot. 2026-09-21 18:14:09 +02:00
Marcos Slomp 841fae2371 code review: formating consistency 2026-09-14 10:16:24 -07:00
Marcos Slomp 016ae062e9 addressing review comments 2026-09-14 08:48:23 -07:00
Marcos Slomp 8cbf2b14a2 use FastVector for the shadow buffer 2026-09-14 08:48:23 -07:00
Marcos Slomp 6be14cff4e increasing the total query limit to 64K queries 2026-09-14 08:48:23 -07:00
Marcos Slomp a11c8ab40c refactoring (isolating) Tracy protocol bits 2026-09-14 08:48:23 -07:00
Bartosz Taudul 35b4922ed4 Bump LZ4 to 1.10.0. 2026-09-11 00:47:22 +02:00
Bartosz Taudul b892dd0b96 Cherry-pick queue memory-ordering fixes from concurrentqueue v1.0.5. 2026-09-10 00:51:12 +02:00
Bartosz Taudul 25ba41c44e Read tracepoint field offsets from tracefs format files.
The client decoded sched_switch, sched_waking and drm_vblank_event at
fixed positions behind an 8-byte common header. The kernel can extend the
header, which shifts the field positions.

The format files are generated from the live trace_entry (offsetof/ALIGN),
making them the authoritative layout.
2026-09-08 22:08:16 +02:00
Bartosz Taudul 538af5c89c Learn the actual port of an adopted listen socket.
Adopting a pre-bound socket via SetReservedListenSocket left Worker()'s
port bookkeeping untouched, so GetPort() and the broadcast announcement
reported the computed default instead of the port the socket listens on.
The monitor kept this correct by mirroring the reserved port into
TRACY_PORT; direct users of the public API had no such coupling.

The bound socket is now authoritative: Worker() reads the local port
back via getsockname after binding. The search-loop bookkeeping stays
only as a fallback for a getsockname failure.
2026-08-31 19:30:23 +02:00
Bartosz Taudul f52bf6a718 Merge pull request #1461 from ofoure/master
Added Profiler::GetPort() and TracyPort macro
2026-08-31 19:07:37 +02:00
Bartosz Taudul c756e7418e Fix android build. 2026-08-31 02:48:20 +02:00
Bartosz Taudul c9d3ec0088 Harden external thread name lookups against dead threads.
A thread exiting between fopen and read leaves the comm and status
buffers under-filled or uninitialized: zero-initialize them, treat a
short or empty read as unknown, and never scan the status when the read
returned nothing.
2026-08-31 01:12:39 +02:00
Bartosz Taudul e5d20e1377 Free the tid buffer when thread enumeration yields nothing.
A task directory yielding no numeric entries (the target exiting
mid-enumeration) returned 0 with the freshly allocated array still
handed back through *out, and the caller's failure path returned without
freeing it.
2026-08-31 01:12:39 +02:00
Bartosz Taudul da0d2328f5 Require per-target events for external sampling success.
SysTraceStart only failed when no event of any kind opened, but in
external mode the global sched/vsync tracepoints (pid -1) succeed
independently of the target: a target exiting after thread enumeration
left every per-target open failing while the startup still reported
success. s_ctxBufferIdx is the per-target ring count right after the
per-target setup, so in external mode require it to be non-zero as well.
2026-08-31 01:12:39 +02:00
Bartosz Taudul 8db1a298c4 Open external sampling as CPU-gated per-CPU events.
The previous external shape - one per-task (cpu = -1) inherit event per
existing thread - cannot be mmap'd at all: perf_mmap() in
kernel/events/core.c refuses inherited per-task counters (-EINVAL, all
children would write the same ring), so no sample ring was ever created.
A per-CPU event filtered on the target's tgid (the self-profiling shape)
only covers the group leader; the kernel does not retro-inherit onto
pre-existing sibling threads.

Open one CPU-gated event per ring instead - perf_event_open(attr, pid,
cpu), one open per CPU and per target thread, the same shape as perf's
open loop (tools/perf/util/evsel.c:3031). The thread enumeration picks
the fan-out: at launch, per-CPU events on the target pid, inherited by
every later-spawned thread; on attach, per-thread per-CPU events for
every existing tid. Failing opens degrade gracefully: the affected
thread is simply not sampled.
2026-08-31 01:12:39 +02:00