Commit Graph

22 Commits

Author SHA1 Message Date
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
d352907e5d Drop the magic monitor globals. 2026-08-31 01:12:37 +02:00
Bartosz Taudul
4e520cfc18 Add the external target API. 2026-08-31 01:12:34 +02:00
Bartosz Taudul
ac9ea9dde7 Stop fetching vendor dependencies for the monitor build. 2026-08-30 21:25:08 +02:00
Bartosz Taudul
38b19d2be6 Constrain the monitor build to Linux x86_64 and aarch64. 2026-08-30 21:25:07 +02:00
Bartosz Taudul
7f7bd69195 Remove TRACY_DELAYED_INIT option.
Delayed init was introduced 2019-02-19 in ef5e30056 and was lazy init at
that time, matching the name.

This changed 2020-05-19 in 4eb78f5c8, when auto-init was added, making
delayed init not delayed anymore.

While the option is still needed to make manual lifetime work, and it has
to be enabled on apple, there's no reason anymore to expose it to users.
2026-08-18 00:26:24 +02:00
Bartosz Taudul
2755166543 Flush stdout before perf preflight, so it's printed before stderr. 2026-04-24 21:10:11 +02:00
Bartosz Taudul
cbfa625fb9 Harden tracy-monitor startup and shutdown paths.
- Loop startup waitpid on EINTR; kill and reap the child on fatal error
  or when interrupted, instead of leaking a ptrace-stopped process.
- Treat PTRACE_DETACH failure as fatal -- otherwise the child is stuck
  stopped forever.
- Zero-initialize procName so the memcpy into ___tracy_magic_process_name
  does not copy uninitialized stack past the NUL.
- Forward SIGINT to the child from the signal handler when in forked
  mode, so Ctrl-C during a blocking waitpid unblocks cleanly.
- Preflight perf_event_open on the target before StartupProfiler so
  permission failures surface with actionable guidance instead of
  silently producing no samples.
- Also handle SIGHUP and SIGQUIT.
2026-04-24 21:07:41 +02:00
Bartosz Taudul
5877db5411 Move NO_ISA_EXTENSIONS option to config.cmake. 2026-03-31 23:15:14 +02:00
Bartosz Taudul
a0b3a71212 Add monitor utility. 2026-03-31 02:06:01 +02:00