Repository navigation
Conversation
…me safety Fixes: mutex acquisition from the pthread TLS destructor (retireThreadByTid lock-free path), TidIndex use-after-free for in-flight lock-free readers in ~ThreadFilter, capacityExhausted() hint/gate contract, and context-window state update races.
…cker state fixes Timer loops re-read recordingEpoch() each tick instead of caching it; stop() keeps the pthread_t when pthread_join fails; flushUnownedBlockedTail resets only on valid payloads; owned-run admission preserves unflushed unowned-blocked weight; test-only exitBlockedRun overload gated behind UNIT_TEST; epoch publish ordering tightened. Adds lazyBackfill timer-path coverage and positive-path fuzz assertions for owned-block suppression.
…k engine teardown
…aProfilerTestSupport to test sources The registry-activity accessor now returns false in release builds; the hooks live on JavaProfiler (DEBUG-gated natives) instead of a public support class shipped in the main jar.
…haos threads stopProfiler() no longer wipes trace context unconditionally; the force-wall-start-failure toggle is disarmed in @AfterEach; wall-precheck counter reads use getOrDefault to avoid NPEs; the parked-worker spin loop yields; the churn antagonist checks join results and reuses one interruptor thread.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3f77b7836b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
More details
The completed static review identified no reportable defects in deferred thread retirement, wall-clock restart handling, or blocked-time accounting. Runtime behavior was not tested.
🤖 Bits Code Review · Commit 3f77b78
CI Test ResultsRun: #45696054128 | Commit:
Status Overview
Legend: ✅ passed | ❌ failed | ⚪ skipped | 🚫 cancelled Summary: Total: 108 | Passed: 108 | Failed: 0 Updated: 2026-11-25 21:21:23 UTC |
Preserve reusable exact-ID roots and retained context across rotations and recording/context restarts. Keep ordinary sample weight one while accounting for timer work and wake lateness with monotonic deadlines. Add fixed-size phase diagnostics and bounded shutdown/drain regressions without weakening the one-second collapsing oracle.
Scan-Build Report
Bug Summary
Filter Results by FileReports
|
|||||||||||||||||||||||||||||||||||||||||||||||||
Reliability & Chaos Results✅ All reliability & chaos checks passed Pipeline: https://gitlab.ddbuild.io/DataDog/java-profiler/-/pipelines/156586968 |
Keep unified reservoir accounting and original-context tails. Retain up to four original-window weight segments and serialize deferred observations at their original epoch timestamps, committing successful writes separately. Settle prior sampling statistics before changing pass counts and publish population boundaries before dispatch. Consumers must scale by the sample timestamp epoch. Unchanged-pool mid-pass send failures can still leave coalesced straddling units at the prior success ratio; that disclosed limitation needs a dedicated follow-up. Lazy sidecar backing is bounded at 256 KiB. Add scale-aware, wire and retry regressions.
Keep the existing reservoir budgets, pass floors and per-thread assertions. Publish unique-thread coverage and wait for it within the existing 20-second timeout instead of assuming a fixed number of random draws covers the pool. On timeout, report observed passes, coverage and every missing tid before the fatal assertion, including rejected tids. Add deterministic completion and fatal-diagnostic regressions without changing the production sampler.
Preserve retained context and epoch tails when skipping clean owned-run clears. Reconcile shared lazy backing and retain root accounting and generation-checked exits. Import allocation and Java-8 spin-hint regressions.
Keep TaskBlock admission and sampled-generation handshakes on the retained wall-clock transaction path. Preserve unowned trace provenance and epoch weights across context changes in filtered and unfiltered stackful sampling. Retain bootstrap test isolation, bounded sidecar allocation, tooling guards, and the published TaskBlock review corrections. Keep generations monotonic on ordinary slot reuse so stale owner tokens cannot clear a replacement run.
Skip only pushes without a same-repository open PR head at the pushed SHA. Exercise the workflow shell with hermetic event, head, pagination and error regressions.
60fac3c to
e5c07be
Compare
# Conflicts: # ddprof-test/src/test/java/com/datadoghq/profiler/wallclock/UnownedWallTailContextTransitionTest.java
# Conflicts: # ddprof-lib/src/main/cpp/wallClockBlockTracker.cpp
|
Why is this bundling several unrelated stuff into a PR that is supposed to fix review-findings of #663? The agent config stuff should go separately, at least. |
This looks like the merge from main pulled all the changes, but the base branch didn't get those changes? |
|
Review findings Reviewed range: Coverage gap: the Sphinx correctness reviewer did not complete, so that lens is missing from this result. A separate correctness pass is running, and I will post its findings in a follow-up comment. 1. (Low) The two Pi adapters duplicate the toplevel lookup ( Both adapters now contain the same block: 2. (Nit)
|
|
Correctness pass (follow-up) This is the follow-up to the earlier review comment. It covers the same range, 1. (High) Epoch close can drop in-flight samples of every type ( At the base,
The header documents exclusive writers on purpose ( 2. (High) This pass's suppressions are credited to the epoch it closes (
When outcomes change often, for example under thread churn, this repeats every pass and biases the upscaling weights. Suggestion: read the counter before the send loop, or take this pass's timer-side suppressions out before the early close. 3. (Low) A failed On a non-zero result, 4. (Low) With 5. (Low) The loop takes the first empty segment even when a later segment already holds the same 6. (Low) Dump holds the sampling-epoch mutex for the whole copy ( The mutex is taken before 7. (Low) The 20-log retention is removed ("retention is managed by the caller"), but no caller manages it, so the directory grows without limit. The file name is now 8. (Low) The hook's retry advice cannot succeed ( When |
There was a problem hiding this comment.
The two most critical concurrency issues are: (1) the exclusive recorder lock in flightRecorder.cpp epoch closure drops concurrent CPU and allocation samples by blocking OptionalSharedLockGuard acquisitions; and (2) the epoch mutex in profiler.cpp is held across the entire dictionary rotation and cleanup path, which can stall wall sampling for up to ~500 ms per dictionary drain.
🤖 Bits Code Review · Commit 65ed68e
| } | ||
| bool FlightRecorder::wallClockEpoch(int lock_index, WallClockEpochEvent *event) { | ||
| DEBUG_ASSERT_NOT_IN_SIGNAL(); | ||
| ExclusiveLockGuard locker(&_rec_lock); |
There was a problem hiding this comment.
Preserve concurrent sampling while publishing wall epochs
Epoch closure can run immediately after signal dispatch. Its new exclusive recorder lock makes concurrent sample writers fail their OptionalSharedLockGuard and discard observations, including on other recording stripes. The lock covers map allocation and possible file I/O, while wall-epoch statistics still count the dispatched selections, causing sample loss and underweighting. Publication and pruning both need non-dropping shared lifetime protection with separately serialized epoch-map access.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| // Send results are known only now. Close prior statistics first. | ||
| // Units already coalesced across an unchanged-pool success-ratio change | ||
| // cannot be split retroactively. | ||
| if (!pool_changed && outcomes_changed) closeSamplingEpoch(pass_start); |
There was a problem hiding this comment.
Attribute current-pass suppressions to the new epoch
With an unchanged population, a pass can suppress an owned run while another signal send fails. Closing the preceding epoch here drains suppressions already accumulated during the current pass into that preceding epoch; the new epoch then receives zero. This misattributes the diagnostic suppression count. Keep current-pass suppressions separate until the preceding epoch is closed.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| // Normal-thread order: epoch mutex -> all recording stripes -> _rec_lock. | ||
| // rotateDictsAndRun excludes signal writers before settlement and sealing. | ||
| // Dictionary readers drain separately through RefCountGuard. | ||
| auto epoch_lock = BaseWallClock::samplingEpochLock(); |
There was a problem hiding this comment.
Exclude dictionary maintenance from the epoch-mutex scope
The epoch mutex now blocks the wall timer throughout dictionary rotation and subsequent cleanup, beyond the pre-existing stripe-locked JFR operation. A delayed JNI dictionary accessor can make rotation drain readers for roughly 500 ms per dictionary, introducing additional sampling gaps. Acquire the epoch mutex after dictionary rotation but before recording stripes, and release it after sealing, before cleanup; this requires restructuring the helper while preserving lock order.
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
| for (auto& segment : cell->segments) { | ||
| u64 weight = segment.weight.load(std::memory_order_acquire); | ||
| if (weight == 0 || segment.epoch_start.load(std::memory_order_acquire) == epoch_start) { | ||
| segment.epoch_start.store(epoch_start, std::memory_order_release); | ||
| segment.weight.store(weight + 1, std::memory_order_release); | ||
| block->unowned_blocked_pending_weight.fetch_add(1, std::memory_order_release); | ||
| return true; | ||
| } | ||
| } | ||
| return false; |
There was a problem hiding this comment.
Prefer a matching epoch segment over an empty entry
A partial tail flush can empty an earlier segment while leaving a later segment for the current epoch pending. This loop then selects the empty entry before finding that matching epoch, creating duplicate segments. This wastes the four-entry provenance capacity and causes premature fallback to ordinary sampling and extra deferred events. Prefer an existing matching epoch before allocating an empty segment.
| for (auto& segment : cell->segments) { | |
| u64 weight = segment.weight.load(std::memory_order_acquire); | |
| if (weight == 0 || segment.epoch_start.load(std::memory_order_acquire) == epoch_start) { | |
| segment.epoch_start.store(epoch_start, std::memory_order_release); | |
| segment.weight.store(weight + 1, std::memory_order_release); | |
| block->unowned_blocked_pending_weight.fetch_add(1, std::memory_order_release); | |
| return true; | |
| } | |
| } | |
| return false; | |
| size_t selected = kMaxWeightSegments; | |
| for (size_t i = 0; i < kMaxWeightSegments; ++i) { | |
| auto& segment = cell->segments[i]; | |
| u64 weight = segment.weight.load(std::memory_order_acquire); | |
| if (weight != 0 && segment.epoch_start.load(std::memory_order_acquire) == epoch_start) { | |
| selected = i; | |
| break; | |
| } | |
| if (weight == 0 && selected == kMaxWeightSegments) selected = i; | |
| } | |
| if (selected == kMaxWeightSegments) return false; | |
| auto& segment = cell->segments[selected]; | |
| u64 weight = segment.weight.load(std::memory_order_acquire); | |
| segment.epoch_start.store(epoch_start, std::memory_order_release); | |
| segment.weight.store(weight + 1, std::memory_order_release); | |
| block->unowned_blocked_pending_weight.fetch_add(1, std::memory_order_release); | |
| return true; |
React: 👍 useful · 👎 wrong · 😕 unclear · 👀 right, but not acting on it
What each reaction means
- 👍 Useful: correct, and you're fixing it or will.
- 👎 Wrong: the finding is incorrect, for example the bug can't happen or the code was misread.
- 😕 Unclear: you can't tell what it means or why it matters.
- 👀 Right, not acting: correct, but intended, out of scope for this PR, a known risk, or too minor.
🤖 Bits Code Review · Open Bits AI session
Memory overhead check: ✅ within budgetProfiler
✅ Not budgeted (too noisy on shared runners)
|
What does this PR do?:
Keeps the stack, tracing context and per-epoch weight attached to retained unowned wall-clock tails until a write succeeds, so tails survive call-trace rotation and JFR dumps with their original provenance. Also folds in the follow-ups to #663's review: owner-TLS context-window membership, lock-free thread retirement, timer-join retry, and DEBUG-only test seams.
Motivation:
In filtered precheck mode an unowned blocked thread records about one sample in ten and keeps the rest as pending weight against a cached trace. Before this change the cached trace could be rotated away, the tail was written with the current context instead of the original one, and it was scaled by the epoch in force at flush time rather than at observation time.
Additional Notes:
Human review: mandatory. The change touches signal-reachable sampling, lock ordering (epoch mutex → recording stripes →
_rec_lock) and JFR epoch metadata.Accepted costs (reviewer acknowledgment required):
Recording::_wall_epochsuntil a dump or a rare prune (floor 4096 entries, about 400 KiB, charged towallclock). The prune visits each stripe once as a barrier, never holding all of them.wall_block_tracker.stop().start()retries the join and is refused while it keeps failing.DDPROF_WALL_TIMER_DIAGNOSTICS(PROF-16795), the.picheckout-root fix (PROF-16721), and build/agent tooling changes (PROF-16796, PROF-16797).-O0workaround:WallClockBlockTracker::unownedContextCell()masks the slot asu32. Clang 14 at-O0on aarch64 lowers the signed masked subscript to a sign-extending byte load, so chunk offsets 128–255 indexed cells −128..−1 (caught by UBSan).UpperHalfChunkOffsetsUseTheirOwnCellfails without it. The comment states when to drop it (clang 15+ floor).mainthrough feat(wall): support unfiltered suppression and protect crash bootstrap (PROF-12146) #663: call-trace storage is now recording-scoped, so pending tails are dropped when storage is released at stop.CallTraceStorage::allocateTables()keepsmain's exception-free allocation._collector_set_buffergets the same load factor and, like the other collections, allocates its buckets on first use.How to test the change?:
./.claude/commands/build-and-summarize :ddprof-lib:gtestDebug(block tracker, wall epochs, thread filter, call-trace storage)../.claude/commands/build-and-summarize :ddprof-test:testDebug -Ptests='com.datadoghq.profiler.wallclock.*'and-Ptests='*Lifecycle*'.For Datadog employees:
credentials of any kind, I've requested a security review (run the
dd:platform-security-reviewskill, or file a request via the PSEC review form).
bewairealso runs automatically on every PR.Unsure? Have a question? Request a review!