Repository navigation
chore(profiling): record memalloc truncation stats and walk time - #22367
vlad-scherbich wants to merge 4 commits into
Conversation
Codeowners resolved asResolved from the full PR diff against |
Dependency direction analysis
|
❌ ErrorsYour PR has failed checks. Please review the issues below and take necessary action before merging. 🚦 2 Pipeline jobs failed
ℹ️ InfoNo other issues found (see more)🧪 All tests passed Useful? React with 👍 / 👎 This comment will be updated automatically if new data arrives.🔗 Commit SHA: 58b63e0 | Docs | View more details | Give us feedback! |
BenchmarksBenchmark execution time: 2026-12-04 16:23:10 Comparing candidate commit 58b63e0 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 574 metrics, 10 unstable metrics, 1 flaky benchmarks without significant changes.
|
e74939e to
b927be9
Compare
16c7f8a to
a6a327d
Compare
There was a problem hiding this comment.
🟡 Changes recommended
The change still emits an unregistered frames.dropped metric, and the overhead of added allocation-path clock reads has not been benchmarked.
2 open issues
What changed in this PR
Adds memory-profiler diagnostics on top of #22207’s omitted-frame count fix, without changing stack or lock collectors.
Changes:
- Records allocation/heap truncation statistics and stack-walk time in profile metadata.
- Hands statistics to Python under the upload lock and emits telemetry after flushes.
- Adds native and Python coverage for statistics and reporting failures.
| File | Description |
|---|---|
tests/profiling/test_scheduler.py |
Tests telemetry emission and failure handling. |
tests/profiling/collector/test_memalloc.py |
Checks truncation metadata and walk time. |
ddtrace/profiling/scheduler.py |
Reports frame statistics after flushing. |
ddtrace/profiling/collector/_memalloc_tb.cpp |
Measures allocation stack-walk time. |
ddtrace/internal/datadog/profiling/ddup/_ddup.pyx |
Exposes native statistics to Python. |
ddtrace/internal/datadog/profiling/ddup/_ddup.pyi |
Declares the statistics API. |
ddtrace/internal/datadog/profiling/dd_wrapper/test/test_frame_truncation.cpp |
Tests counters, buckets, handoff, and interning failure. |
ddtrace/internal/datadog/profiling/dd_wrapper/test/CMakeLists.txt |
Registers the native test. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/uploader_builder.cpp |
Snapshots statistics before serialization. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/sample.cpp |
Supplies per-sample truncation statistics. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/profiler_stats.cpp |
Aggregates and serializes statistics. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/profiler_state.cpp |
Clears pending statistics after fork. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/profile.cpp |
Records statistics during collection. |
ddtrace/internal/datadog/profiling/dd_wrapper/src/ddup_interface.cpp |
Transfers statistics under the upload lock. |
ddtrace/internal/datadog/profiling/dd_wrapper/include/sample.hpp |
Adds sample classification and timing state. |
ddtrace/internal/datadog/profiling/dd_wrapper/include/profiler_stats.hpp |
Defines counters and depth buckets. |
ddtrace/internal/datadog/profiling/dd_wrapper/include/profiler_state.hpp |
Stores pending upload statistics. |
ddtrace/internal/datadog/profiling/dd_wrapper/include/profile.hpp |
Adds per-sample statistics to collection. |
ddtrace/internal/datadog/profiling/dd_wrapper/include/ddup_interface.hpp |
Declares the native statistics handoff. |
Review effort: Balanced
Memory samples always showed "<1 frame omitted>" because the memalloc walk stopped at DD_PROFILING_MAX_FRAMES. Keep walking (pointer reads only, up to the existing 1024-frame cap) and report the real count.
b927be9 to
ee39e0a
Compare
Record per-profile frame_truncation counters and memalloc_walk_ns for alloc/heap samples, hand them off under the upload lock, and emit frames.* plus memalloc.walk_ns instrumentation telemetry after each flush. Stack and lock collectors are unchanged.
take_frame_stats already returns frames_dropped; report it as the frames.dropped count metric alongside the other per-collector counters.
a6a327d to
5ed0031
Compare
Intake (dd-go #25879) registers frames.samples_truncated, not frames.dropped; keep frames_dropped in profile metadata only.
Codex Review Summary: ✅ CompletedThis 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: 58b63e090d
ℹ️ About Codex in GitHub
Codex has been enabled to automatically 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 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
More details
Frame statistics are handed off under the upload lock, and telemetry reporting failures are isolated from profile uploads. Runtime overhead and external metric registrations remain unvalidated.
🤖 Bits Code Review · Commit 58b63e0
…22207) ## Description Memory samples always showed `<1 frame omitted>` because the memalloc stack walk stopped at `DD_PROFILING_MAX_FRAMES`. It now keeps walking (pointer reads only, up to the existing 1024 walked-frame cap) and reports the real omitted-frame count on the sample label. No stack content, default, or limit changes. ## Testing Local: `pytest tests/profiling/collector/test_memalloc.py::test_memory_collector_reports_true_omitted_frame_count` Pins: omitted-frame label equals measured depth − `max_nframe` (not always `1`). ## Risks Memalloc samples walk past the frame limit with pointer reads only (≤1024 walked frames). ## Additional Notes First PR in the max-depth stack (on `main`). Follow-ups: truncation stats (#22367), Sample reserve (#22206), `DD_PROFILING_MEMORY_MAX_FRAMES` (#22208). https://datadoghq.atlassian.net/browse/PROF-16353 ## Pre-review checklist Before submitting your PR for review, please make sure the following have been done/checked. - [ ] The changes have been tested in real services in staging - [ ] The PR does not result in new crashes Co-authored-by: vlad.scherbich <vlad.scherbich@datadoghq.com>

Description
On top of the omitted-frame count fix (#22207), this PR records memalloc alloc/heap truncation stats (
frame_truncationdepth buckets, dropped frames, max depth) andmemalloc_walk_nsin profile internal metadata, hands them off under the upload lock viaddup.take_frame_stats, and emits profiler telemetryframes.*(includingframes.samples_truncated) plusmemalloc.walk_nsafter each flush.If only this PR merges onto the fix base: customers already see true omitted counts; what newly ships is metadata + instrumentation telemetry. Stack and lock collectors stay unchanged.
Testing
Local:
pytest tests/profiling/collector/test_memalloc.py::test_memory_collector_reports_true_omitted_frame_count tests/profiling/test_scheduler.py::test_flush_reports_frame_stats_to_telemetry tests/profiling/test_scheduler.py::test_flush_survives_frame_stats_failuretest_frame_truncation):./ddtrace/internal/datadog/profiling/build_standalone.sh -- RelWithDebInfo stack_testPins: alloc/heap
frame_truncation+memalloc_walk_ns > 0; gtest depth buckets; scheduler emitsframes.*/memalloc.walk_nsand flush still uploads when take/report fails.Risks
Two monotonic clock reads per memalloc sample.
ddup_take_frame_statsruns under the upload lock. Stats can be taken after a failed serialize, so telemetry may cover a window that did not ship.Additional Notes
Base: #22207. This PR: observe (metadata + telemetry) only.
dd-go companion (FPD registry): https://github.com/ddoghq/dd-go/pull/25879 — registers
frames.samples/frames.samples_truncated/frames.stack_depth/frames.max_depth/memalloc.walk_ns. Intake usesframes.samples_truncated(noframes.droppedregistry entry).changelog/no-changelog— internal metadata/telemetry; customer-facing reno is on the fix PR.https://datadoghq.atlassian.net/browse/PROF-16353
Pre-review checklist
Before submitting your PR for review, please make sure the following have
been done/checked.