Skip to content

Commit b2d5245

Browse files
committed
fix: remove useless fields (correlation_id from ExecutionEvent and _sample_id from MethodSample
1 parent bb79ff4 commit b2d5245

8 files changed

Lines changed: 28 additions & 22 deletions

File tree

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,10 @@ class ExecutionEvent : public Event {
5858
ExecutionMode _execution_mode;
5959
u64 _weight;
6060
u64 _call_trace_id;
61-
u64 _correlation_id;
62-
u64 _sample_id;
6361

6462
ExecutionEvent()
6563
: Event(), _thread_state(OSThreadState::RUNNABLE), _execution_mode(ExecutionMode::UNKNOWN),
66-
_weight(1), _call_trace_id(0), _correlation_id(0), _sample_id(0) {}
64+
_weight(1), _call_trace_id(0) {}
6765
};
6866

6967
class AllocEvent : public Event {

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,6 @@ void Recording::recordMethodSample(Buffer *buf, int tid, u64 call_trace_id,
18141814
buf->put8(static_cast<int>(event->_execution_mode));
18151815
buf->putVar64(event->_weight);
18161816
buf->putVar64(correlation_id);
1817-
buf->putVar64(event->_sample_id);
18181817
writeCurrentContext(buf);
18191818
writeEventSizePrefix(buf, start);
18201819
flushIfNeeded(buf);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ void JfrMetadata::initialize(
139139
<< field("mode", T_EXECUTION_MODE, "Execution Mode", F_CPOOL)
140140
<< field("weight", T_LONG, "Sample weight")
141141
<< field("correlationId", T_LONG, "Async Stack Trace Correlation ID")
142-
<< field("sampleId", T_LONG, "Sample ID")
143142
<< field("spanId", T_LONG, "Span ID")
144143
<< field("localRootSpanId", T_LONG, "Local Root Span ID") ||
145144
contextAttributes)

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ u64 Profiler::recordJVMTISample(u64 counter, int tid, jthread thread, jint event
653653
#endif // COUNTERS
654654
}
655655
if (!deferred) {
656-
setWallSampleIdIfNeeded(event_type, event);
657656
_jfr.recordEvent(lock_index, tid, call_trace_id, event_type, event);
658657
}
659658

@@ -673,7 +672,6 @@ void Profiler::recordDeferredSample(int tid, u64 call_trace_id, jint event_type,
673672
return;
674673
}
675674

676-
setWallSampleIdIfNeeded(event_type, event);
677675
_jfr.recordEvent(lock_index, tid, call_trace_id, event_type, event);
678676

679677
_locks[lock_index].unlock();
@@ -743,7 +741,6 @@ bool Profiler::recordSample(void *ucontext, u64 counter, int tid,
743741
}
744742
#endif // COUNTERS
745743
}
746-
setWallSampleIdIfNeeded(event_type, event);
747744
if (event_type == BCI_WALL) {
748745
static_cast<ExecutionEvent *>(event)->_call_trace_id = call_trace_id;
749746
}
@@ -757,7 +754,8 @@ bool Profiler::recordSample(void *ucontext, u64 counter, int tid,
757754
}
758755

759756
bool Profiler::recordSampleDelegated(void *ucontext, u64 weight, int tid,
760-
jint event_type, Event *event) {
757+
jint event_type, Event *event,
758+
u64 *recorded_correlation_id) {
761759
if (!VM::canRequestStackTrace()) {
762760
return false;
763761
}
@@ -790,12 +788,11 @@ bool Profiler::recordSampleDelegated(void *ucontext, u64 weight, int tid,
790788
return false;
791789
}
792790

793-
setWallSampleIdIfNeeded(event_type, event);
794-
if (event_type == BCI_WALL) {
795-
static_cast<ExecutionEvent *>(event)->_correlation_id = correlation_id;
796-
}
797791
bool recorded =
798792
_jfr.recordEventDelegated(lock_index, tid, correlation_id, event_type, event);
793+
if (recorded && recorded_correlation_id != nullptr) {
794+
*recorded_correlation_id = correlation_id;
795+
}
799796
_locks[lock_index].unlock();
800797
return recorded;
801798
}
@@ -901,7 +898,6 @@ void Profiler::recordExternalSample(u64 weight, int tid, int num_frames,
901898

902899
u64 call_trace_id =
903900
_call_trace_storage.put(num_frames, extended_frames, truncated, weight);
904-
setWallSampleIdIfNeeded(event_type, event);
905901
_jfr.recordEvent(lock_index, tid, call_trace_id, event_type, event);
906902

907903
_locks[lock_index].unlock();

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -396,18 +396,14 @@ class alignas(alignof(SpinLock)) Profiler {
396396
bool recordSample(void *ucontext, u64 weight, int tid, jint event_type,
397397
u64 call_trace_id, Event *event,
398398
u64 *recorded_call_trace_id = nullptr);
399-
void setWallSampleIdIfNeeded(jint event_type, Event *event) {
400-
if (event_type == BCI_WALL && _wall_precheck) {
401-
((ExecutionEvent *)event)->_sample_id = atomicIncRelaxed(_sample_seq);
402-
}
403-
}
404399
// Delegated sample path: stack-walking is performed by the HotSpot JFR
405400
// RequestStackTrace extension (the JVM emits the stack trace into its own
406401
// JFR recording). We only emit the CPU/wall sample event with no
407402
// stack-trace reference, tagged by the correlation ID we passed to
408403
// RequestStackTrace as user_data.
409404
bool recordSampleDelegated(void *ucontext, u64 weight, int tid,
410-
jint event_type, Event *event);
405+
jint event_type, Event *event,
406+
u64 *recorded_correlation_id = nullptr);
411407
u64 recordJVMTISample(u64 weight, int tid, jthread thread, jint event_type, Event *event, bool deferred);
412408
void recordDeferredSample(int tid, u64 call_trace_id, jint event_type, Event *event);
413409
void recordExternalSample(u64 weight, int tid, int num_frames,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -484,9 +484,10 @@ void WallClockJvmti::signalHandler(int signo, siginfo_t *siginfo,
484484
// the thread is currently inside JVM-internal (non-Java) code.
485485
// JVMTI-delegated samples carry a correlation_id, not a call_trace_id, so
486486
// unowned tail flushing remains limited to the ASGCT wall engine.
487+
u64 recorded_correlation_id = 0;
487488
bool recorded = Profiler::instance()->recordSampleDelegated(
488-
nullptr, last_sample, tid, BCI_WALL, &event);
489-
finishWallPrecheck(precheck, recorded, event._call_trace_id, event._correlation_id);
489+
nullptr, last_sample, tid, BCI_WALL, &event, &recorded_correlation_id);
490+
finishWallPrecheck(precheck, recorded, 0, recorded_correlation_id);
490491
Shims::instance().setSighandlerTid(-1);
491492
errno = saved_errno;
492493
}

ddprof-test/src/test/java/com/datadoghq/profiler/wallclock/SmokeWallTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public void test(@CStack String cstack) throws ExecutionException, InterruptedEx
4242
verifyCStackSettings();
4343

4444
IItemCollection events = verifyEvents("datadog.MethodSample");
45+
TaskBlockAssertions.assertMethodSampleSchemaHasCorrelationIdButNoSampleId(events);
4546

4647
for (IItemIterable cpuSamples : events) {
4748
IMemberAccessor<String, IItem> frameAccessor = JdkAttributes.STACK_TRACE_STRING.getAccessor(cpuSamples.getType());

ddprof-test/src/test/java/com/datadoghq/profiler/wallclock/TaskBlockAssertions.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ final class TaskBlockAssertions {
2929
attr("suppressedSampleCount", "suppressedSampleCount", "Suppressed Sample Count", NUMBER);
3030
private static final IAttribute<IQuantity> CORRELATION_ID =
3131
attr("correlationId", "correlationId", "Async Stack Trace Correlation ID", NUMBER);
32+
private static final IAttribute<IQuantity> METHOD_SAMPLE_ID =
33+
attr("sampleId", "sampleId", "Sample ID", NUMBER);
3234
private static final IAttribute<String> OBSERVED_BLOCKING_STATE =
3335
attr("observedBlockingState", "observedBlockingState", "Observed Blocking State", PLAIN_TEXT);
3436
private static final IAttribute<IQuantity> EPOCH_TASK_BLOCK_EMITTED =
@@ -105,6 +107,20 @@ static void assertContainsCorrelationId(IItemCollection taskBlockEvents) {
105107
assertTrue(correlationIds.size() > 0, "Expected at least one non-zero TaskBlock correlationId");
106108
}
107109

110+
static void assertMethodSampleSchemaHasCorrelationIdButNoSampleId(IItemCollection methodSampleEvents) {
111+
int checked = 0;
112+
for (IItemIterable iterable : methodSampleEvents) {
113+
checked++;
114+
assertTrue(
115+
CORRELATION_ID.getAccessor(iterable.getType()) != null,
116+
"MethodSample must expose correlationId");
117+
assertNull(
118+
METHOD_SAMPLE_ID.getAccessor(iterable.getType()),
119+
"MethodSample must not expose sampleId");
120+
}
121+
assertTrue(checked > 0, "Expected at least one MethodSample type to inspect");
122+
}
123+
108124
static void assertWallClockEpochDoesNotExposeTaskBlockCounters(IItemCollection epochEvents) {
109125
int checked = 0;
110126
for (IItemIterable iterable : epochEvents) {

0 commit comments

Comments
 (0)