Skip to content

Commit 351f2b5

Browse files
jbachorikclaude
andcommitted
Remove dead getByTid and free attribute keys on shutdown
- Remove getByTid from OtelContexts and ContextApi (zero callers) - Free strdup'd _attribute_keys in ContextApi::shutdown() Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
1 parent 0a5f199 commit 351f2b5

File tree

5 files changed

+9
-49
lines changed

5 files changed

+9
-49
lines changed

ddprof-lib/src/main/cpp/context_api.cpp

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ void ContextApi::shutdown() {
5757
OtelContexts::shutdown();
5858
}
5959

60+
// Free registered attribute keys
61+
for (int i = 0; i < _attribute_key_count; i++) {
62+
free(_attribute_keys[i]);
63+
_attribute_keys[i] = nullptr;
64+
}
65+
_attribute_key_count = 0;
66+
6067
__atomic_store_n(&_initialized, false, __ATOMIC_RELEASE);
6168
}
6269

@@ -150,26 +157,6 @@ bool ContextApi::get(u64& span_id, u64& root_span_id) {
150157
}
151158
}
152159

153-
bool ContextApi::getByTid(int tid, u64& span_id, u64& root_span_id) {
154-
ContextStorageMode mode = __atomic_load_n(&_mode, __ATOMIC_ACQUIRE);
155-
156-
if (mode == CTX_STORAGE_OTEL) {
157-
// In TLS model, cross-thread reads use ProfiledThread's cached record pointer.
158-
// The caller (wallClock signal handler) has access to the target thread's
159-
// ProfiledThread, but this static API only receives a TID.
160-
// For now, fall through to OtelContexts::getByTid which returns false.
161-
u64 trace_high, trace_low;
162-
if (OtelContexts::getByTid(tid, trace_high, trace_low, span_id)) {
163-
root_span_id = trace_low;
164-
return true;
165-
}
166-
return false;
167-
} else {
168-
span_id = 0;
169-
root_span_id = 0;
170-
return false;
171-
}
172-
}
173160

174161
void ContextApi::clear() {
175162
ContextStorageMode mode = __atomic_load_n(&_mode, __ATOMIC_ACQUIRE);

ddprof-lib/src/main/cpp/context_api.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,6 @@ class ContextApi {
106106
*/
107107
static bool get(u64& span_id, u64& root_span_id);
108108

109-
/**
110-
* Read context for a specific thread by TID.
111-
*
112-
* Used by JVMTI wall-clock sampling where the sampling thread
113-
* needs to read another thread's context.
114-
*
115-
* @param tid Thread ID to read context for
116-
* @param span_id Output: the span ID
117-
* @param root_span_id Output: the root span ID
118-
* @return true if context was successfully read
119-
*/
120-
static bool getByTid(int tid, u64& span_id, u64& root_span_id);
121-
122109
/**
123110
* Clear context for the current thread.
124111
*/

ddprof-lib/src/main/cpp/otel_context.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ bool OtelContexts::get(u64& trace_id_high, u64& trace_id_low, u64& span_id) {
170170
return readRecord(thrd->getOtelContextRecord(), trace_id_high, trace_id_low, span_id);
171171
}
172172

173-
bool OtelContexts::getByTid(int tid, u64& trace_id_high, u64& trace_id_low, u64& span_id) {
174-
// Cross-thread read not supported via TID lookup in TLS model.
175-
// Callers should use ProfiledThread's cached record pointer directly.
176-
return false;
177-
}
178-
179173
bool OtelContexts::readRecord(OtelThreadContextRecord* record,
180174
u64& trace_id_high, u64& trace_id_low, u64& span_id) {
181175
if (record == nullptr) {

ddprof-lib/src/main/cpp/otel_context.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ class OtelContexts {
9393
*/
9494
static bool get(u64& trace_id_high, u64& trace_id_low, u64& span_id);
9595

96-
/**
97-
* Read context for a specific thread by TID.
98-
* Uses ProfiledThread's cached record pointer (signal-safe).
99-
*/
100-
static bool getByTid(int tid, u64& trace_id_high, u64& trace_id_low, u64& span_id);
101-
10296
/**
10397
* Write a single attribute into the current thread's OTEP record.
10498
* Appends (key_index, length, value) to attrs_data, re-publishes via detach/attach.

doc/architecture/OtelContextStorage.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ The system uses a feature-flagged approach where the storage mode is selected at
4545
│ ├─ initialize(args) → Select mode based on ctxstorage option │
4646
│ ├─ set(spanId, rootSpanId) → Route to appropriate storage │
4747
│ ├─ get(spanId, rootSpanId) → Read from appropriate storage │
48-
│ └─ getByTid(tid, ...) → Read by thread ID (OTEL mode)
48+
│ └─ clear() → Clear current thread's context
4949
│ │ │
5050
│ ├─────────────────────────┬─────────────────────────────────────┤
5151
│ ▼ ▼ │
@@ -185,7 +185,6 @@ public:
185185
static void set(u64 span_id, u64 root_span_id);
186186
static void setOtel(u64 trace_id_high, u64 trace_id_low, u64 span_id);
187187
static bool get(u64& span_id, u64& root_span_id);
188-
static bool getByTid(int tid, u64& span_id, u64& root_span_id);
189188
static void clear();
190189
};
191190
```
@@ -201,7 +200,6 @@ public:
201200
202201
static void set(u64 trace_id_high, u64 trace_id_low, u64 span_id);
203202
static bool get(u64& trace_id_high, u64& trace_id_low, u64& span_id);
204-
static bool getByTid(int tid, u64& trace_id_high, u64& trace_id_low, u64& span_id);
205203
static void clear();
206204
};
207205
```
@@ -270,4 +268,4 @@ ddprof-test/src/test/java/com/datadoghq/profiler/context/
270268

271269
2. **Custom Attributes**: Implemented — `attrs_data` supports variable-length key/value pairs per the OTEP specification. `ThreadContext.setContextAttribute()` writes to OTEP record in OTEL mode, falls back to `registerConstant` + `Context.tags[]` in profiler mode.
272270

273-
3. **Cross-thread reads via getByTid**: Currently limited since TLS cannot be accessed from another thread in-process. The cached record pointer in ProfiledThread provides the mechanism.
271+
3. **Cross-thread reads**: TLS cannot be accessed from another thread in-process. Signal handlers read their own thread's context via `ProfiledThread`'s cached record pointer.

0 commit comments

Comments
 (0)