Add survivors label to GC timeline samples [PROF-14573]#3861
Draft
realFlowControl wants to merge 2 commits intomasterfrom
Draft
Add survivors label to GC timeline samples [PROF-14573]#3861realFlowControl wants to merge 2 commits intomasterfrom
realFlowControl wants to merge 2 commits intomasterfrom
Conversation
After every GC tick, walk EG(objects_store) and attach a `survivors` label to the existing [gc] sample listing the top 10 live classes by instance count (e.g. `\DateTime 24, \ImmutableDateTime 59, ...`). Watching that label across consecutive GC events surfaces object leaks without needing a full heap profiler. C side adds a one-line accessor for &EG(objects_store); all walking, aggregation, sorting and formatting stay in Rust. Skips emission when fewer than 32 objects are tracked. Includes a prof-correctness test that asserts known counts of two namespaced classes appear in the survivors label. PROF-14573 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
6744d2b to
2f4908d
Compare
|
✨ Fix all issues with BitsAI or with Cursor
|
Benchmarks [ profiler ]Benchmark execution time: 2026-05-08 09:48:51 Comparing candidate commit 249b582 in PR branch Found 1 performance improvements and 0 performance regressions! Performance is the same for 27 metrics, 8 unstable metrics. scenario:php-profiler-timeline-memory-with-profiler
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Surfaces a lightweight per-GC heap snapshot that lets users spot object leaks in the existing GC timeline events, without building a full heap-live profiler.
After every GC tick recorded by the profiler, walks
EG(objects_store)and attaches a singlesurvivorslabel to the existing[gc]timeline sample listing the top 10 live classes by instance count:Watching the label across successive GC events in the timeline view surfaces the leak fingerprint: a class whose count climbs run-over-run.
How it works
&EG(objects_store). Everything else (iteration, aggregation, top-N selection, formatting) is Rust.*const zend_class_entry(cheap pointer key, no string work during the walk); class name is resolved once per kept entry.(count desc, class_name asc)for deterministic output.Closure, generators, engine types) are included — they can leak too.EG(objects_store).top < 32(heap too small to be interesting).Test coverage
gc_survivors.{php,json}that instantiates known counts of two namespaced classes (Bench\\AlphaThing× 200,Bench\\BetaThing× 100), forces a GC, and asserts both appear in thesurvivorslabel in the expected order..github/workflows/prof_correctness.yml.Reviewer checklist
Plan
PROF-14573 — Show survivors after GC
Goal
After every GC tick recorded by the profiler, attach a single `survivors` label
to the existing GC timeline sample listing the top 10 classes (by live-object
instance count) at that moment. Lets users spot object leaks by watching the
counts climb across successive GC events in the timeline.
Design
`[gc]` timeline sample.
buckets where `IS_OBJ_VALID` is false. Aggregate by `zend_class_entry*`.
also leak.
Implementation
Tiny C accessor — `profiling/src/php_ffi.{h,c}`
Bindgen already exposes `zend_objects_store` (struct with `object_buckets`,
`top`, `size`, `free_list_head`) so all the iteration stays in Rust. We only
need one trivial helper to expand the `EG(objects_store)` macro:
```c
zend_objects_store *ddog_php_prof_objects_store(void) {
return &EG(objects_store);
}
```
Rust — `profiling/src/timeline.rs` (`mod gc_survivors`)
`pub(super) fn collect_top_n() -> Option`:
check (`(ptr as usize) & 1 == 0`); inlined Rust-side, no FFI.
Class name extraction reuses `zai_str_from_zstr` (the canonical
`zend_string` -> bytes helper used elsewhere in `bindings/mod.rs`).
GC sample wiring — `profiling/src/profiling/mod.rs`
survivors string and attach it as a `survivors` label when `Some`.
Caller — `ddog_php_prof_gc_collect_cycles`
After `prev()`, before passing to `collect_garbage_collection`:
```rust
let survivors = gc_survivors::collect_top_n();
profiler.collect_garbage_collection(now, duration, reason, collected, runs, survivors);
```
Tests
Rust unit tests (`gc_survivors` module)
Prof-correctness test — `profiling/tests/correctness/gc_survivors.{php,json}`
PHP script:
in a global so they survive GC.
JSON expectations:
asserting both class names appear with their expected counts in the
expected order.
CI wiring — `.github/workflows/prof_correctness.yml`
Out of scope
🤖 Generated with Claude Code