Reduce sampling attribute copies using shared references#11007
Reduce sampling attribute copies using shared references#11007
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughIntroduces reference counting to ctrace_attributes, adding a ref_count field and a new ctr_attributes_acquire API. The create/destroy logic now manages refcounts. Plugins update attribute handling to acquire references instead of deep-copying, removing copy helpers and adjusting resource and instrumentation scope attribute flows. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Attr as ctrace_attributes
participant API as ctr_attributes_*()
Caller->>API: ctr_attributes_create()
activate API
API->>Attr: allocate + init (ref_count=1)
API-->>Caller: Attr*
deactivate API
Caller->>API: ctr_attributes_acquire(Attr*)
activate API
API->>Attr: ref_count++
API-->>Caller: same Attr*
deactivate API
Caller->>API: ctr_attributes_destroy(Attr*)
activate API
API->>Attr: if (ref_count>1) ref_count-- and return
API->>Attr: if (ref_count==1) free
deactivate API
sequenceDiagram
autonumber
actor Sampler
participant Span as Span/Context
participant Res as Resource
participant Scope as InstrumentationScope
participant API as ctr_attributes_acquire
Sampler->>Span: get resource_attrs / scope_attrs
alt attrs present
Sampler->>API: acquire(resource_attrs)
API-->>Sampler: Attr*
Sampler->>Res: set_attributes(Attr*)
Sampler->>API: acquire(scope_attrs)
API-->>Sampler: Attr*
Sampler->>Scope: create(..., Attr*)
else no attrs
Sampler->>Res: set_attributes(NULL)
Sampler->>Scope: create(..., NULL)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
ctrace_attributesso attribute lists can be shared safelyTesting
cmake --build build --target ctraces-static/usr/bin/cc ... -o /tmp/sampling_tail.o -c plugins/processor_sampling/sampling_tail.chttps://chatgpt.com/codex/tasks/task_e_68d46a9e0c3c8327ae947a2b45d8c40a
Summary by CodeRabbit