Commit Graph

10981 Commits

Author SHA1 Message Date
Bartosz Taudul
fab65fae88 Agent guidance. 2026-09-06 01:07:47 +02:00
Bartosz Taudul
2dfe5c5c75 Save tracy-update output through a temporary file. 2026-09-06 01:07:46 +02:00
Bartosz Taudul
927ca83894 Save tracy-merge output through a temporary file. 2026-09-06 01:07:46 +02:00
Bartosz Taudul
51160bcc28 Save GUI traces through a temporary file. 2026-09-06 01:07:46 +02:00
Bartosz Taudul
e848076dfa Add a file writer that replaces its target only on completion.
The data is written to <fn>.tmp in the same directory as the target
and moved to <fn> on Commit(); a failed or interrupted write leaves
the previous file untouched, with an orphaned .tmp.
2026-09-06 01:07:46 +02:00
Bartosz Taudul
6aa41759d0 Flush the output file in FileWrite::Finish.
The final compressed block was left in the stdio buffer until the
destructor closed the file, so a caller that inspected the file after
Finish() saw a truncated trace.
2026-09-06 01:07:46 +02:00
Bartosz Taudul
4cbec36af6 Remove undefined source list variables from the capture build. 2026-09-06 01:07:46 +02:00
Bartosz Taudul
db6a46cf3e Extract shared capture-side tool code into TracyUtil. 2026-09-06 01:07:46 +02:00
Bartosz Taudul
ebf5ebd9bd Replace the output file safely in tracy-capture.
The old pre-flight truncated the output at startup with -f, so an
interrupted capture lost the trace, and the probe fopen followed a
symlink. The existing file is now moved to FILE~ for the duration of
the capture and restored if the trace cannot be written.
2026-09-06 01:07:45 +02:00
Bartosz Taudul
cf3407bbe3 Fix empty rate sample list read in the connection popup. 2026-09-06 01:07:45 +02:00
Bartosz Taudul
89f12318a1 Fix empty rate sample list read in the daemon stats. 2026-09-06 01:07:45 +02:00
Bartosz Taudul
fa4336dd26 Fix empty rate sample list read in the progress line.
HasData() flips when the connection is established, but the rate
list is only filled by the worker periodic stats update, whose first
entry arrives ~200ms later, so the first render could read an empty
list.
2026-09-06 01:07:45 +02:00
Bartosz Taudul
89132aed2a Merge pull request #1466 from akx/macos-level
Use CMAKE_OSX_DEPLOYMENT_TARGET 15.0 by default
2026-09-02 14:23:33 +02:00
Aarni Koskela
76c310eade Use CMAKE_OSX_DEPLOYMENT_TARGET 15.0 by default
As it is, the CI-built macOS binaries refuse to work on
macOS Sequoia because it defaults to the runner machine's level.

This sets a lower-than-default default for the target.
2026-09-02 10:39:36 +03: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
70e4170e26 Cache the downloaded pandoc binary. 2026-08-31 18:54:55 +02:00
Bartosz Taudul
c6f1cb7585 Generate markdown manual at build time. 2026-08-31 18:54:55 +02:00
Bartosz Taudul
00e152b97a Allow embedding files from the build directory. 2026-08-31 18:54:53 +02:00
Olivier Fouré
17a4080713 Documented the TracyPort macro in the manual. 2026-08-31 09:58:26 +02:00
Bartosz Taudul
c756e7418e Fix android build. 2026-08-31 02:48:20 +02:00
Bartosz Taudul
71f0c992f7 Build monitor on CI. 2026-08-31 02:48:16 +02:00
Bartosz Taudul
06f4e13012 Document tracy-monitor in the user manual. 2026-08-31 01:58:38 +02:00
Bartosz Taudul
a66cc184e8 Annotate the file sections. 2026-08-31 01:58:37 +02:00
Bartosz Taudul
c9abfce098 Add a TRACY_ON_DEMAND build option. 2026-08-31 01:58:37 +02:00
Bartosz Taudul
a15e08f135 Rewrite the usage text. 2026-08-31 01:58:37 +02:00
Bartosz Taudul
fdff78584a 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.
2026-08-31 01:12:41 +02:00
Bartosz Taudul
893439772f Reject client configurations that cannot work.
TRACY_NO_CALLSTACK, TRACY_NO_SYSTEM_TRACING, TRACY_NO_SAMPLING and
TRACY_SAMPLING_PROFILER_MANUAL_START either fail to build (the external
target API lives in the callstack code) or silently produce an empty
capture (no sampling event fails, so IsSystemTracingFailed stays false).
The first three are #error'd at compile time; the TRACY_NO_SYS_TRACE /
TRACY_NO_SAMPLING environment variables are refused at startup.
2026-08-31 01:12:41 +02:00
Bartosz Taudul
6d794801c6 Verify the exec stop in launch mode.
A caught signal (the handlers are inherited by the child) delivered
between PTRACE_TRACEME and exec first produces a signal-delivery stop;
without handling it, the setup would run on the still pre-exec child and
capture the monitor's own image as the target's. Re-inject the caught
signal and wait again until the exec stop is reached. Job-control stops
are the exception - re-injecting SIGSTOP/SIGTSTP re-stops the child, and
PTRACE_CONT rejects a stop carrying the 0x80 job-control bit - so resume
those without a signal instead.
2026-08-31 01:12:41 +02:00
Bartosz Taudul
b36c8f2fc5 Refuse to start without tracefs.
The client's system tracing cannot start without a tracefs (or debugfs)
mount - the tracepoint ids live under it - so starting anyway would
capture no samples.
2026-08-31 01:12:41 +02:00
Bartosz Taudul
2f2d8a7ba9 Fail when system tracing fails to start.
IsSystemTracingFailed reports a SysTraceStart that the preflight could
not predict (the target exiting between the checks, the kernel rejecting
the event setup); starting anyway would capture no samples.
2026-08-31 01:12:41 +02:00
Bartosz Taudul
d498829518 Verify the client is listening after startup.
Polling IsDataPortListening is the only reliable check: probing the port
itself cannot distinguish the client's listener from another process
holding it.
2026-08-31 01:12:40 +02:00
Bartosz Taudul
e87b7c873e Reserve the client listen port.
When TRACY_PORT is not pinned the client probes 8086..8105 at startup.
Reserve the first free port up front and hand the already-bound socket
to the client via SetReservedListenSocket, so the reservation is atomic
and the reported port matches what the client listens on. A pinned
TRACY_PORT is validated like --port, since the client pins to any
nonzero value with no fallback.
2026-08-31 01:12:40 +02:00
Bartosz Taudul
6109ab27b5 Add sample rate and port options. 2026-08-31 01:12:40 +02:00
Bartosz Taudul
7357b9fa52 Attach by process name.
The name is matched against /proc/<pid>/comm, which the kernel truncates
to 15 characters. Several matches are listed so the user can pick one
with -p; a match is only accepted if /proc/<pid>/exe is readable, which
excludes zombies (they keep a comm but have no executable to map) and
inaccessible processes.
2026-08-31 01:12:40 +02:00
Bartosz Taudul
46f2489f92 Report the active data sources at startup. 2026-08-31 01:12:40 +02:00
Bartosz Taudul
ac970771ee Preflight the exact sample event.
The old preflight opened one generic event, which said little about
whether the client's actual setup would work. PreflightSamplingEvent now
opens the client's exact external event shape (the per-CPU pid-filtered
CPU_CLOCK callstack event of SysTraceStart), verifies the ring mmap
works, and probes the hardware PMU counters informationally. On
EACCES/EPERM retry user-space only - both event and callchain, since the
callchain part still requires perf_allow_kernel - and report kernel
frames as unavailable; any other error is fatal, as the client's
identical shape would fail the same way.
2026-08-31 01:12:40 +02:00
Bartosz Taudul
d87cbed7eb Probe system-wide tracepoints and RAPL. 2026-08-31 01:12:40 +02:00
Bartosz Taudul
252a3dae43 Treat zombie targets as dead.
kill(pid, 0) succeeds for zombies, so a SIGKILLed attach target whose
parent had not reaped it yet kept the monitor polling indefinitely - in
attach mode the monitor cannot reap it. Liveness now also reads the
/proc state and treats Z as dead.
2026-08-31 01:12:40 +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
Bartosz Taudul
37410933db Always deliver the sample IP.
Add PERF_SAMPLE_IP to the callstack sample: for code compiled without
frame pointers the kernel delivers no user stack, and such samples were
dropped entirely. When the callchain count is zero, synthesize a
one-frame trace holding just the leaf IP.
2026-08-31 01:12:39 +02:00
Bartosz Taudul
afe1ec5faf Factor the sample event open into OpenSampleEvent.
The seven sampling event setups repeated the same open/mmap/retry
sequence. On a refused open the retry now stays user-space only
(exclude_kernel and exclude_callchain_kernel both still require
perf_allow_kernel), and a failed open no longer breaks out of the whole
event loop.
2026-08-31 01:12:39 +02:00
Bartosz Taudul
d440f5e055 Report whether the data port is listening. 2026-08-31 01:12:39 +02:00
Bartosz Taudul
ae70255b4e Adopt a pre-bound listen socket. 2026-08-31 01:12:39 +02:00
Bartosz Taudul
b887def929 Record and expose system tracing startup failure. 2026-08-31 01:12:38 +02:00
Bartosz Taudul
7aee673792 Use the target executable time for external captures.
The worker must key source and symbol transfers on the target's
executable, not the monitor's own binary; the exe mtime was read
straight from /proc/<pid>/exe by InitExternalTarget (the readlink'd path
is namespace-dependent and carries a " (deleted)" suffix). For an
external target the time may be unavailable, so drop the assert on a
nonzero exectime.
2026-08-31 01:12:38 +02:00
Bartosz Taudul
81f3c71ef3 Transfer machine code for external targets.
For an external target the symbol code query addresses are VMAs in the
target's address space, not pointers in the monitor's, so read them out
with ReadExternalTargetMemory. Kernel code (the top bit marks it) is
shared by the monitor and its target alike, so the kernel path applies
in both modes.
2026-08-31 01:12:38 +02:00