Skip to content

Commit

Permalink
JFR ThreadContextSwitchRate fix-ups
Browse files Browse the repository at this point in the history
- explicitly initialize prevContextSwitches
- calculate switchRate with float

Related: eclipse-openj9#20725
Signed-off-by: Gengchen Tuo <[email protected]>
  • Loading branch information
thallium committed Jan 3, 2025
1 parent 4c82e0a commit 25adabf
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion runtime/vm/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ initializeJFR(J9JavaVM *vm, BOOLEAN lateInit)
vm->jfrState.prevSysCPUTime.timestamp = -1;
vm->jfrState.prevProcTimestamp = -1;
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 @@ -1020,7 +1021,7 @@ jfrThreadContextSwitchRate(J9VMThread *currentThread)
jfrEvent->switchRate = 0;
} else {
int64_t timeDelta = currentTime - jfrState->prevContextSwitchTimestamp;
jfrEvent->switchRate = ((double)(switches - jfrState->prevContextSwitches) / timeDelta) * 1e9;
jfrEvent->switchRate = ((float)(switches - jfrState->prevContextSwitches) / timeDelta) * 1e9f;
}
jfrState->prevContextSwitches = switches;
jfrState->prevContextSwitchTimestamp = currentTime;
Expand Down

0 comments on commit 25adabf

Please sign in to comment.