Repository navigation
fix(profiling): respect frame limits during native stack collection - #19073
gh-worker-dd-mergequeue-cf854d[bot] merged 28 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against No remaining files require a CODEOWNERS review. |
Circular import analysis
|
b4d7e00 to
890dd4e
Compare
🎉 All green!🧪 All tests passed 🔗 Commit SHA: 75d3783 | Docs | View more details | Give us feedback! |
890dd4e to
891f2f9
Compare
891f2f9 to
32b532a
Compare
32b532a to
ecdbdab
Compare
## Description Aligns profiling frame-limit configuration with the backend's [600-location limit](https://datadoghq.atlassian.net/wiki/spaces/PROF/pages/5307007274/Profiling+Libraries+Frame+Truncation+Behaviors). - raises the native exporter cap from 512 to 599 captured frames - reserves the 600th backend location for the synthetic `<N frames omitted>` indicator on truncated stacks - clamps `DD_PROFILING_MAX_FRAMES` to 599 in `ddtrace.internal.settings.profiling` - preserves configured values from 513 through 599 instead of reducing them to 512 in the native exporter - ensures collectors receive the same effective configured limit JIRA: [PROF-14213](https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWFmMTNkMDg2MmJjNDVlZTlkN2JlNGZkMjg3ZWZiYzEiLCJwIjoiaiJ9) ## Testing - Added configuration tests covering the default, values below the maximum captured-frame limit, the exact 599-frame limit, and values at or above the 600-location backend limit. - Ran `TestMaxFramesConfig` on Python 3.9, all 6 tests passed. The editable install also rebuilt the native extension successfully. - Completed a clean Python 3.14 native build for the initial change. - Ran `scripts/lint checks`, targeted formatting, spelling, and `git diff --check`. Broad lint checks reported only existing repository warnings. ## Risks Configurations between 513 and 599 can now retain more frames than before. This matches the backend contract but can slightly increase per-sample work for users who explicitly configure values in that range. Values of 600 and above are now clamped to 599 at configuration load instead of reaching individual collectors unchanged. This leaves one location for the omitted-frame indicator so truncated samples remain within the backend's 600-location cap. ## Additional Notes This PR is the base of stacked #19073 and #19085, which propagate the limit into Echion and bound task-aware stack collection. [PROF-14213]: https://datadoghq.atlassian.net/browse/PROF-14213?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiaiJ9 Co-authored-by: taegyun.kim <taegyun.kim@datadoghq.com>
67ae55e to
c0a7c8f
Compare
c0a7c8f to
dd6bece
Compare
…-propagate-max-frames # Conflicts: # ddtrace/internal/datadog/profiling/stack/src/echion/threads.cc
…-propagate-max-frames
Dependency direction analysis
|
56fd6a4 to
b8284b1
Compare
|
I checked your tests — they're pretty comprehensive, but for a change this size I don't think they covered all edge cases. Two of the five new Python tests would still pass if the unwind change were reverted. Specifically:
|
|
@vlad-scherbich Thanks for flagging these. I addressed the substantive coverage gaps in
The exact-limit test and setter/getter test remain intentionally focused on separate contracts: avoiding a false marker at exact fill, and preserving zero/default plus large-value configuration. Validation: all 23 Python 3.12 standalone native CTests passed, standard targeted profiling had 5 passed and 1 skipped, gevent targeted profiling had 6 passed, and full lint passed. |
KowalskiThomas
left a comment
There was a problem hiding this comment.
Overall LGTM; just one minor concern on release notes.
|
Thank you both for reviews |
Description
DD_PROFILING_MAX_FRAMESlimits the number of frames reported in profiles, but the native Echion sampler previously walked plain Python thread stacks up to its 2,048-frame safety ceiling. With the default 64-frame limit, this could collect and materialize many frames that the exporter immediately discarded.This PR propagates
StackCollector.nframesinto the native sampler and stops plain thread stack collection at that limit. It:set_max_frames()entry point, preserving per-collector overrides and the existing zero/default behaviorUnwindResultwith explicitUnknown,NotTruncated, orTruncatedstatus, and usesUnwindResult::Unknown()for unknown initializationmark_truncated()only after finding another reportable Python frame, avoiding false markers for terminal C/interpreter framesUnknown, while enabled detection can also remain unknown after a read failure, cycle, or exhausted probe budgetResult<UnwindResult>andThreadInfo::unwind()to abort the sample before task/greenlet discovery or renderingAsyncio-loop threads retain the existing 2,048-frame discovery depth because task stitching needs deeper physical frames to find the event-loop boundary and determine overlap. Greenlet logical stacks also retain their existing 2,048-frame discovery depth so this PR does not change parent-segment stitching. The configured reporting limit still applies to rendered profiles. Follow-up #19085 changes asyncio materialization separately.
Merged the latest
origin/mainat33e9b69e96.Testing
scripts/run-testsin its local CI execution mode because the Docker host filesystem was full.scripts/lint checks, C/C++ formatting, Reno lint, andgit diff --check origin/mainpassed. Existing repository-wide lint warnings remain.frames_added == 2andTruncationStatus::Truncated; all 23 standalone native CTests passed.nframes=1while retaining exporter headroom; it still requires at least three recursive_fibframes, proving greenlet discovery retains its existing depth.408cb68fc3a99557dff4cf595fed9f8321dc0ea2in the isolated Python 3.13 Rapid Test Driveprof-14213-max-frames-v4. The service reachedready, its core CPU, memory, and wait workload checks returned HTTP 200, and the profiling backend received Python, native, and eBPF profiles.CPU performance
Measured with dd-trace-doe at commit
b68974823dacb76ef7728f64bbdc0acab79e1fc9. The experiment compared this PR with benchmark baseline8e80a8b4e27d8009521ddac3a51c06329b175000, which was the exactmainmerge base when the experiment ran. It used Python 3.13, Flaskgthread, four workers, 40 closed-loop clients, one-second sleeps inside generated stacks, tracing disabled, profiling enabled, and 60-second runs. Each version and stack depth was repeated three times.The table reports the mean of DoE's top-level CPU metric,
cpu / load_wall * 100, wherecpuincludes measured-load and shutdown/flush CPU:All 18 runs completed with zero request errors and produced 180 profile payloads. DoE classifies three repetitions as low confidence, so these results demonstrate the expected depth-dependent direction and magnitude rather than a general production-overhead claim. Per-run CPU ranges were 11.9-12.3% versus 11.0-11.6% at depth 64, 16.3-16.9% versus 10.9-12.1% at depth 256, and 32.1-34.0% versus 12.6-13.7% at depth 768.
CI follow-up
UncheckedtoUnknown, which covers both skipped detection and detection that could not reach a conclusion.Result<void>return value in the remaining thread-unwind fuzz harness, fixing clang-tidy'snodiscarddiagnostic.scripts/lint checks, and the six native sampling-cycle/unwind tests.scripts/docs/build.shpassed Reno lint and the warnings-as-errors HTML build usingREADTHEDOCS=1. The local Sphinx spelling stage was skipped because the machine lacks its dictionary setup; repository-wide codespell checks passed.Risks
Plain thread stacks stop unwinding at the configured limit. The omitted-frame count is deliberately conservative: an early-truncation marker records at least one deeper reportable Python frame, rather than walking and counting the entire omitted portion.
Asyncio discovery retains its existing safety ceiling. An unreadable initial C frame now aborts the sample rather than continuing without a physical stack. No public API changes.
Additional Notes
releasenotes/notes/profiling-propagate-max-frames-f7a718abdfb99c4c.yaml: "Stack collection now honors configured frame limits, reducing profiler CPU and memory overhead for deep Python call stacks."