Skip to content

Add profiler counters for time spent in stack unwinding #195

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ddprof-lib/src/main/cpp/counters.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@
X(AGCT_NOT_JAVA, "agct_not_java") \
X(AGCT_NATIVE_NO_JAVA_CONTEXT, "agct_native_no_java_context") \
X(AGCT_BLOCKED_IN_VM, "agct_blocked_in_vm") \
X(SKIPPED_WALLCLOCK_UNWINDS, "skipped_wallclock_unwinds")
X(SKIPPED_WALLCLOCK_UNWINDS, "skipped_wallclock_unwinds") \
X(UNWINDING_TIME_ASYNC, "unwinding_ticks_async") \
X(UNWINDING_TIME_JVMTI, "unwinding_ticks_jvmti")
#define X_ENUM(a, b) a,
typedef enum CounterId : int {
DD_COUNTER_TABLE(X_ENUM) DD_NUM_COUNTERS
Expand Down
16 changes: 16 additions & 0 deletions ddprof-lib/src/main/cpp/profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "stackWalker.h"
#include "symbols.h"
#include "thread.h"
#include "tsc.h"
#include "vmStructs.h"
#include "wallClock.h"
#include <algorithm>
Expand Down Expand Up @@ -600,6 +601,7 @@ u32 Profiler::recordJVMTISample(u64 counter, int tid, jthread thread, jint event
}
u32 call_trace_id = 0;
if (!_omit_stacktraces) {
u64 startTime = TSC::ticks();
ASGCT_CallFrame *frames = _calltrace_buffer[lock_index]->_asgct_frames;
jvmtiFrameInfo *jvmti_frames = _calltrace_buffer[lock_index]->_jvmti_frames;

Expand All @@ -619,6 +621,10 @@ u32 Profiler::recordJVMTISample(u64 counter, int tid, jthread thread, jint event
}

call_trace_id = _call_trace_storage.put(num_frames, frames, false, counter);
u64 duration = TSC::ticks() - startTime;
if (duration > 0) {
Counters::increment(UNWINDING_TIME_JVMTI, duration); // increment the JVMTI specific counter
}
}
if (!deferred) {
_jfr.recordEvent(lock_index, tid, call_trace_id, event_type, event);
Expand Down Expand Up @@ -670,6 +676,7 @@ void Profiler::recordSample(void *ucontext, u64 counter, int tid,
// record a null stacktrace we can skip the unwind if we've got a
// call_trace_id determined to be reusable at a higher level
if (!_omit_stacktraces && call_trace_id == 0) {
u64 startTime = TSC::ticks();
ASGCT_CallFrame *frames = _calltrace_buffer[lock_index]->_asgct_frames;

int num_frames = 0;
Expand Down Expand Up @@ -716,6 +723,10 @@ void Profiler::recordSample(void *ucontext, u64 counter, int tid,
if (thread != nullptr) {
thread->recordCallTraceId(call_trace_id);
}
u64 duration = TSC::ticks() - startTime;
if (duration > 0) {
Counters::increment(UNWINDING_TIME_ASYNC, duration); // increment the async specific counter
}
}
_jfr.recordEvent(lock_index, tid, call_trace_id, event_type, event);

Expand Down Expand Up @@ -1360,6 +1371,11 @@ Error Profiler::dump(const char *path, const int length) {

_thread_info.clearAll(thread_ids);
_thread_info.reportCounters();

// reset unwinding counters
Counters::set(UNWINDING_TIME_ASYNC, 0);
Counters::set(UNWINDING_TIME_JVMTI, 0);

return err;
}

Expand Down
1 change: 0 additions & 1 deletion ddprof-lib/src/main/cpp/stackFrame_x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ void StackFrame::ret() {

bool StackFrame::unwindStub(instruction_t *entry, const char *name,
uintptr_t &pc, uintptr_t &sp, uintptr_t &fp) {

instruction_t *ip = (instruction_t *)pc;
if (ip == entry || *ip == 0xc3 || strncmp(name, "itable", 6) == 0 ||
strncmp(name, "vtable", 6) == 0 ||
Expand Down
1 change: 0 additions & 1 deletion ddprof-lib/src/main/cpp/stackWalker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ int StackWalker::walkFP(void *ucontext, const void **callchain, int max_depth,
sp = fp + (FRAME_PC_SLOT + 1) * sizeof(void *);
fp = *(uintptr_t *)fp;
}

return depth;
}

Expand Down
Loading