Skip to content
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

JFR ThreadContextSwitchRate fix-ups #20881

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
18 changes: 14 additions & 4 deletions runtime/vm/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,7 @@ jint
initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)
{
PORT_ACCESS_FROM_JAVAVM(vm);
OMRPORT_ACCESS_FROM_J9PORT(PORTLIB);
keithc-ca marked this conversation as resolved.
Show resolved Hide resolved
jint rc = JNI_ERR;
J9HookInterface **vmHooks = getVMHookInterface(vm);
U_8 *buffer = NULL;
Expand Down Expand Up @@ -723,7 +724,14 @@ initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)

vm->jfrState.prevSysCPUTime.timestamp = -1;
vm->jfrState.prevProcTimestamp = -1;
vm->jfrState.prevContextSwitchTimestamp = -1;

if (0 == omrsysinfo_get_number_context_switches(&vm->jfrState.prevContextSwitches)) {
vm->jfrState.prevContextSwitchTimestamp = j9time_nano_time();
} else {
vm->jfrState.prevContextSwitchTimestamp = -1;
vm->jfrState.prevContextSwitches = 0;
}

if (omrthread_monitor_init_with_name(&vm->jfrBufferMutex, 0, "JFR global buffer mutex")) {
goto fail;
}
Expand Down Expand Up @@ -1017,11 +1025,13 @@ jfrThreadContextSwitchRate(J9VMThread *currentThread)

initializeEventFields(currentThread, (J9JFREvent *)jfrEvent, J9JFR_EVENT_TYPE_THREAD_CONTEXT_SWITCH_RATE);

if (-1 == jfrState->prevContextSwitchTimestamp) {
jfrEvent->switchRate = 0;
if ((-1 == jfrState->prevContextSwitchTimestamp)
|| (currentTime == jfrState->prevContextSwitchTimestamp)
) {
jfrEvent->switchRate = 0.0f;
} else {
int64_t timeDelta = currentTime - jfrState->prevContextSwitchTimestamp;
jfrEvent->switchRate = ((double)(switches - jfrState->prevContextSwitches) / timeDelta) * 1e9;
jfrEvent->switchRate = (switches - jfrState->prevContextSwitches) * 1e9f / timeDelta;
keithc-ca marked this conversation as resolved.
Show resolved Hide resolved
}
jfrState->prevContextSwitches = switches;
jfrState->prevContextSwitchTimestamp = currentTime;
Expand Down