Commit Graph

412 Commits

Author SHA1 Message Date
Ryan Jensen
978b720759 Fix warning [-Wsign-compare] 2026-06-20 17:09:26 -05:00
Bartosz Taudul
801a34ea66 Add trigger parameter. 2026-06-17 22:37:31 +02:00
Bartosz Taudul
0cdb6d365e Initial section enter / leave instrumentation. 2026-06-17 22:37:31 +02:00
Bartosz Taudul
e3f4c72c85 Move TRACY_ATTRIBUTE_FORMAT_PRINTF to its own header. 2026-06-17 22:37:31 +02:00
Bartosz Taudul
62560a6429 Add 8-bit length string transfers to the protocol. 2026-06-15 20:43:55 +02:00
Bartosz Taudul
f7b4e177ff Change misleading etc1buf variable to texbuf. 2026-06-15 19:31:06 +02:00
Bartosz Taudul
084daf0516 Force inline send string strlen helpers. 2026-06-15 19:19:13 +02:00
Bartosz Taudul
d3047f8069 Fix memory discard + callstack.
Bug (High Severity): Wrong queue type in MemDiscardCallstack

In the callstack path of MemDiscardCallstack, the wrong queue type is
sent:

  SendMemDiscard( QueueType::MemDiscard, thread, name );

Every other callstack variant correctly uses its callstack queue type
(MemAllocCallstack, MemFreeCallstack, etc.), but this one uses the
non-callstack type. The SendMemDiscard assertion at line 1026 confirms
MemDiscardCallstack is a valid value.

Impact: The callstack captured by SendCallstackSerial() will be orphaned.
The server processes the event via the non-callstack handler, leaving the
callstack serial data unconsumed, which desynchronizes the serial queue
and corrupts all subsequent events.
2026-06-12 20:30:59 +02:00
Bartosz Taudul
a091bb4ad2 Remove "secure" variant of alloc/free.
Random crashes are not fun. Always use the "secure" code path.
2026-06-12 19:41:17 +02:00
Bartosz Taudul
0544440a34 Remove unused, extremely broken code. 2026-06-11 22:35:25 +02:00
Bartosz Taudul
f622b97436 Backdate init time when a producer token predates it.
A zone emitted from a shared object initializer runs before the
executable's constructors, so its timestamp precedes s_initTime, which
the server uses as the trace epoch (baseTime). Such a zone converts to
negative trace time and its end no longer satisfies IsEndValid(), which
excludes it from statistics reconstruction and makes it render as
never-ending.

Record the current time when a producer token is created before
s_initTime is constructed and use it as the init time, ensuring no event
timestamp precedes the trace epoch.
2026-06-11 20:05:59 +02:00
Bartosz Taudul
dfded9d55d Recover main thread producer orphaned by cross-module init order.
ELF init_priority only orders constructors within a single module. All of
a shared object's initializers run before any of the executable's, so an
instrumented dependency .so emitting a zone from its static initializer
creates the main thread producer token against the zero-initialized
s_queue. The queue constructor then resets the producer list, orphaning
that producer: every zone emitted on the main thread from that point on
is enqueued into blocks no consumer ever iterates and silently lost,
while sampling (worker thread producer) keeps working.

Re-link such a producer right after the queue is constructed. In the
common case, where nothing was emitted during shared object init, this
merely constructs the main thread token eagerly.
2026-06-11 20:05:57 +02:00
Clément Grégoire
0c74658dd3 TRACY_WIN32_NO_DESKTOP should use GetVersionExW explicitly.
Since we use `RTL_OSVERSIONINFOW` we need to use W version explicitly
2026-06-11 12:06:34 +02:00
Clément Grégoire
bfab6d03f4 WORKAROUND_malloc/free should properly route to tracy_malloc/free 2026-06-10 17:15:33 +02:00
MaximeCoutantSonos
7637971e9e Fixed typo inconsistency in Shared lock C api 2026-06-10 14:26:36 +02:00
Bartosz Taudul
7ee4380f64 Merge pull request #1395 from MaximeCoutantSonos/master
Add support for Shared Locks in the C API
2026-06-08 17:34:17 +02:00
Basil Milanich
16cdf3d645 Merge remote-tracking branch 'origin/master' into rocm-on-demand-fix
# Conflicts:
#	public/client/TracyRocprof.cpp
2026-06-08 09:43:07 -05:00
MaximeCoutantSonos
31dbfef97d Added C shared lock to C-API 2026-06-08 15:19:00 +02:00
Bartosz Taudul
20e6835da6 Fix remaining MemWrites. 2026-06-05 00:00:04 +02:00
Bartosz Taudul
6b92ec1a23 Message queue item is already in the right format.
After swapping ptr and tag in TaggedUserlandAddress, the tag part aligns
exactly with the metadata field.
2026-06-04 20:08:07 +02:00
Bartosz Taudul
896a59d00b Simplify. 2026-06-04 12:11:14 +02:00
Bartosz Taudul
d3db50c201 Mingw fixes. 2026-06-04 12:08:53 +02:00
Bartosz Taudul
185482c0d9 MemRead deduces returned type from pointer. 2026-06-04 00:49:02 +02:00
Bartosz Taudul
7d139a7bf1 Use proper data types for MemWrite. 2026-06-04 00:49:02 +02:00
Bartosz Taudul
02e279bd38 Unaligned memory reads must go via MemRead. 2026-06-04 00:00:08 +02:00
Clément Grégoire
e93ddd2aa7 When using the MSVC C runtime, fileno doesn't actually exist, use _fileno instead.
OLDNAMES.lib may not be linked if you use /NODEFAULTLIB.
Note: This uses `_MSC_VER` as a gate and not _WIN32 as MinGW apparently uses `fileno` and not `_fileno`.
2026-05-29 17:51:30 +02:00
Bartosz Taudul
ee37bb40f0 Merge pull request #1372 from wolfpld/slomp/nvcc-msvc-fix
NVCC (with MSVC/cl.exe) build fix
2026-05-24 16:29:58 +02:00
Clément Grégoire
f93d17a96f Add TRACY_PLATFORM_HEADER hook for unsupported platforms.
Extension point so private/unsupported platforms can plug in their own implementations of the kernel/libc primitives Tracy depends on, without patching the `#if`/`#elif` chains.

Projects supply a platform header via `-DTRACY_PLATFORM_HEADER="\"my_platform.h\""` at build time. Tracy includes it in any TU that needs the hooks. The header toggles per-category `TRACY_HAS_CUSTOM_*` macros and declares matching `tracy::Platform*` functions.

Available hooks:

- `TRACY_HAS_CUSTOM_THREAD_ID` → `PlatformGetThreadId`
- `TRACY_HAS_CUSTOM_USER_INFO` → `PlatformGetHostname`, `PlatformGetUserLogin`, `PlatformGetUserFullName`
- `TRACY_HAS_CUSTOM_SAFE_COPY` → `PlatformSafeMemcpy`
- `TRACY_HAS_CUSTOM_ALLOCATOR` → `PlatformMalloc`, `PlatformFree`, `PlatformRealloc`, `PlatformAllocatorInit`, `PlatformAllocatorThreadInit`, `PlatformAllocatorFinalize`, `PlatformAllocatorThreadFinalize`

Each hook is wired as the first arm of its respective `#if`/`#elif` chain, so existing supported platforms are unaffected.

Template files in `examples/CustomPlatform/` and a new subsection in `manual/tracy.tex` document the mechanism.
2026-05-24 15:42:42 +02:00
Clément Grégoire
fd68959223 Rename InitRpmalloc to InitAllocator.
The function is about to dispatch between rpmalloc and a pluggable allocator hook, so the rpmalloc-specific name no longer fits. Pure rename plus a small consequence: the SymbolWorker call site no longer needs the TRACY_USE_RPMALLOC guard, since the no-op static-inline fallback in TracyAlloc.hpp makes InitAllocator() safe to call unconditionally.
2026-05-24 15:04:31 +02:00
Marcos Slomp
564e0e1e71 removing scope qualifiers 2026-05-23 14:20:06 -07:00
Clément Grégoire
e7c71c991c Drop sys/param.h dependency for BSD detection
Replace `#ifdef BSD` (which requires including `<sys/param.h>` first) with explicit checks for `__FreeBSD__`, `__NetBSD__`, `__OpenBSD__` and `__DragonFly__`, matching how these BSDs are already enumerated elsewhere in the codebase (OS name strings, thread id helpers, etc.).

This also avoids leaking the `sys/param.h` requirement through public headers (`TracySysTime.hpp`, `TracyCallstack.h`), where consumers would otherwise need it to correctly see `TRACY_HAS_SYSTIME` / `TRACY_HAS_CALLSTACK`.
`libbacktrace/config.h` is left as-is — it's third-party and only included from .c files where the `BSD` macro can still be picked up locally.

Note: for `setsockopt( m_sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&val, sizeof( val ) );` I added `__APPLE__` too since this was the only place where it was not checked explicitely.
2026-05-21 10:18:30 +02:00
Clément Grégoire
e59601cf1c Fix ProfilerWorker hang when TRACY_HAS_CALLSTACK is not defined 2026-05-20 17:51:42 +02:00
Bartosz Taudul
5cb283073e Store kernel symbol end address, not size.
The end address is now readily available in lower_bound search, instead
of needing to be calculated constantly in the lambda.

The size can be equivalently calculated from the end address, but this
only happens once, after the symbol is found.
2026-05-10 00:15:18 +02:00
Bartosz Taudul
a6c72f1cc7 Do not repeatedly read from all ring buffers to find minimum time entry. 2026-05-09 20:41:29 +02:00
Bartosz Taudul
95416a4b9c Since active[] order doesn't matter, memmove can be replaced with a swap. 2026-05-09 17:48:57 +02:00
Bartosz Taudul
7de27ebffa Force inline RingBuffer::Read(). 2026-05-09 01:05:33 +02:00
Bartosz Taudul
70535435f2 Use masking instead of calculating remainder.
size is power-of-two (asserted).
2026-05-09 00:58:16 +02:00
Bartosz Taudul
61a6fb6780 Batch ring buffer reads. 2026-05-09 00:50:50 +02:00
Bartosz Taudul
305382453d Add callstack sample events with 32 and 16 bit timestamps. 2026-05-07 02:16:53 +02:00
Bartosz Taudul
ccaef5ba0b ZoneBegin / ZoneBeginCallstack with 32 and 16 bit time data. 2026-05-07 02:16:53 +02:00
Bartosz Taudul
4d094c108d Add zone end messages with 32 and 16 byte time deltas.
Change in test application:
    compressed data: 130 Mpbps -> 105 Mbps
    uncompressed: 830 Mbps -> 740 Mbps
2026-05-06 19:09:19 +02:00
Bartosz Taudul
8c2a970222 Merge pull request #1352 from wolfpld/slomp/apple-systrace
System tracing (callstack sampling) for Apple devices
2026-05-05 19:05:41 +02:00
Marcos Slomp
6a214ed419 refactoring globals 2026-05-05 08:28:15 -07:00
Marcos Slomp
df20e8ad84 refactoring 2026-05-05 08:05:56 -07:00
Marcos Slomp
761d50e8f5 debug cleanup 2026-05-05 07:49:15 -07:00
Clément Grégoire
2997a78872 Fix #1243 compatibility with WinSDK < 10.0.26100
After investigating (downloading and installing) all publicly available SDKs at https://learn.microsoft.com/en-us/windows/apps/windows-sdk/downloads-archive I concluded the `TRACEHANDLE` deprecation started in `10.0.26100`.
This defines `PROCESSTRACE_HANDLE` and `CONTROLTRACE_ID` as done by the SDK when using older versions. Using `WDK_NTDDI_VERSION` (and not `NTDDI_VERSION` which may change based on `_WIN32_WINNT` or user input seems to be the most reliable way to do it. While it says "WDK" it's been part of the SDK in `shared\sdkddkver.h`. Note it doesn't work for MinGW because it updates half of its sdk files for some reason.
Tested with both 10.0.26100 and 10.0.22621.0 which is the last one I found without the new types.
Also changes CONTROLTRACE_ID to ULONG64 on mingw which is correct (type used by `TRACEHANDLE` too in mingw fe2763863a/mingw-w64-headers/include/evntrace.h (L60) )
2026-05-05 16:14:21 +02:00
Marcos Slomp
6b4ed90323 remove modern c++ 2026-05-04 21:43:27 -07:00
Marcos Slomp
ace8f18adb handle ARM64 PAC 2026-05-04 16:21:19 -07:00
Marcos Slomp
c877d0bcb4 TracySysTrace already manages the wprker thread lifetime... 2026-05-04 15:45:56 -07:00
Marcos Slomp
5a168f7ae4 initial prototype of system tracing for Apple devices 2026-05-04 15:29:24 -07:00