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

More JFR events support #20040

Merged
merged 1 commit into from
Sep 13, 2024
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
113 changes: 111 additions & 2 deletions runtime/vm/JFRChunkWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/
#include "JFRUtils.hpp"
#include "vm_internal.h"

#if defined(J9VM_OPT_JFR)

#include "JFRChunkWriter.hpp"
#include "JFRConstantPoolTypes.hpp"

void
VM_JFRChunkWriter::writeJFRHeader()
Expand Down Expand Up @@ -638,7 +640,7 @@ VM_JFRChunkWriter::writeStacktraceCheckpointEvent()
U_8 *
VM_JFRChunkWriter::writeJVMInformationEvent()
{
JVMInformationEntry *jvmInfo= &(((JFRConstantEvents *)(_vm->jfrState.constantEvents))->JVMInfoEntry);
JVMInformationEntry *jvmInfo= &(VM_JFRConstantPoolTypes::getJFRConstantEvents(_vm)->JVMInfoEntry);

/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));
Expand All @@ -647,7 +649,7 @@ VM_JFRChunkWriter::writeJVMInformationEvent()
_bufferWriter->writeLEB128(JVMInformationID);

/* write start time */
_bufferWriter->writeLEB128(jvmInfo->jvmStartTime);
_bufferWriter->writeLEB128(j9time_current_time_millis());
thallium marked this conversation as resolved.
Show resolved Hide resolved

/* write JVM name */
writeStringLiteral(jvmInfo->jvmName);
Expand Down Expand Up @@ -676,5 +678,112 @@ VM_JFRChunkWriter::writeJVMInformationEvent()
return dataStart;
}

U_8 *
VM_JFRChunkWriter::writePhysicalMemoryEvent()
{
/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));

_bufferWriter->writeLEB128(PhysicalMemoryID);

/* write start time */
_bufferWriter->writeLEB128(j9time_current_time_millis());

J9MemoryInfo memInfo = {0};
I_32 rc = j9sysinfo_get_memory_info(&memInfo);
if (0 == rc) {
/* write total size */
_bufferWriter->writeLEB128(memInfo.totalPhysical);
/* write used size */
_bufferWriter->writeLEB128(memInfo.totalPhysical - memInfo.availPhysical);
thallium marked this conversation as resolved.
Show resolved Hide resolved
} else {
thallium marked this conversation as resolved.
Show resolved Hide resolved
_buildResult = InternalVMError;
}
/* write size */
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);

return dataStart;
}

U_8 *
VM_JFRChunkWriter::writeCPUInformationEvent()
{
CPUInformationEntry *cpuInfo= &(VM_JFRConstantPoolTypes::getJFRConstantEvents(_vm)->CPUInfoEntry);

/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));

/* write event type */
_bufferWriter->writeLEB128(CPUInformationID);

/* write start time */
_bufferWriter->writeLEB128(j9time_current_time_millis());

/* write CPU type */
writeStringLiteral(cpuInfo->cpu);

/* write CPU description */
writeStringLiteral(cpuInfo->description);

/* write CPU sockets */
_bufferWriter->writeLEB128(cpuInfo->sockets);

/* write CPU cores */
_bufferWriter->writeLEB128(cpuInfo->cores);

/* write CPU hardware threads */
_bufferWriter->writeLEB128(cpuInfo->hwThreads);

/* write size */
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);

return dataStart;
}

U_8 *
VM_JFRChunkWriter::writeVirtualizationInformationEvent()
{
VirtualizationInformationEntry *virtualizationInfo= &(VM_JFRConstantPoolTypes::getJFRConstantEvents(_vm)->VirtualizationInfoEntry);

/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));

/* write event type */
_bufferWriter->writeLEB128(VirtualizationInformationID);

/* write start time */
_bufferWriter->writeLEB128(j9time_current_time_millis());

/* write virtualization name */
writeStringLiteral(virtualizationInfo->name);

/* write size */
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);

return dataStart;
}

U_8 *
VM_JFRChunkWriter::writeOSInformationEvent()
{
OSInformationEntry *osInfo = &(VM_JFRConstantPoolTypes::getJFRConstantEvents(_vm)->OSInfoEntry);

/* reserve size field */
U_8 *dataStart = _bufferWriter->getAndIncCursor(sizeof(U_32));

/* write event type */
_bufferWriter->writeLEB128(OSInformationID);

/* write start time */
_bufferWriter->writeLEB128(j9time_current_time_millis());

/* write OS version */
writeStringLiteral(osInfo->osVersion);

/* write size */
_bufferWriter->writeLEB128PaddedU32(dataStart, _bufferWriter->getCursor() - dataStart);

return dataStart;
}

#endif /* defined(J9VM_OPT_JFR) */
61 changes: 59 additions & 2 deletions runtime/vm/JFRChunkWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ enum MetadataTypeID {
ThreadEndID = 3,
ThreadSleepID = 4,
JVMInformationID = 86,
OSInformationID = 87,
VirtualizationInformationID = 88,
CPUInformationID = 92,
PhysicalMemoryID = 107,
ExecutionSampleID = 108,
ThreadID = 163,
ThreadGroupID = 164,
Expand Down Expand Up @@ -145,6 +149,10 @@ class VM_JFRChunkWriter {
static constexpr int THREAD_END_EVENT_SIZE = (4 * sizeof(U_64)) + sizeof(U_32);
static constexpr int THREAD_SLEEP_EVENT_SIZE = (7 * sizeof(U_64)) + sizeof(U_32);
static constexpr int JVM_INFORMATION_EVENT_SIZE = 3000;
static constexpr int PHYSICAL_MEMORY_EVENT_SIZE = (4 * sizeof(U_64)) + sizeof(U_32);
static constexpr int VIRTUALIZATION_INFORMATION_EVENT_SIZE = 50;
static constexpr int CPU_INFORMATION_EVENT_SIZE = 600;
static constexpr int OS_INFORMATION_EVENT_SIZE = 100;

static constexpr int METADATA_ID = 1;

Expand Down Expand Up @@ -249,6 +257,21 @@ class VM_JFRChunkWriter {
_constantPoolTypes.printTables();
}

if (FALSE == _vm->jfrState.isConstantEventsInitialized) {
omrthread_monitor_enter(_vm->jfrState.isConstantEventsInitializedMutex);
if (FALSE == _vm->jfrState.isConstantEventsInitialized) {
VM_JFRConstantPoolTypes::initializeJFRConstantEvents(_vm, _currentThread, &_buildResult);
if (isResultNotOKay()) {
VM_JFRConstantPoolTypes::freeJFRConstantEvents(_vm);
goto done;
}
/* Ensure that initialization is complete when the initialized variable is set to true */
VM_AtomicSupport::writeBarrier();
_vm->jfrState.isConstantEventsInitialized = TRUE;
}
omrthread_monitor_exit(_vm->jfrState.isConstantEventsInitializedMutex);
}

requiredBufferSize = calculateRequiredBufferSize();
if (isResultNotOKay()) {
goto done;
Expand Down Expand Up @@ -298,16 +321,34 @@ class VM_JFRChunkWriter {

pool_do(_constantPoolTypes.getThreadSleepTable(), &writeThreadSleepEvent, _bufferWriter);

writeJVMInformationEvent();
/* Only write constant events in first chunk */
if (0 == _vm->jfrState.jfrChunkCount) {
writeJVMInformationEvent();

writeCPUInformationEvent();

writeVirtualizationInformationEvent();

writeOSInformationEvent();
}

writePhysicalMemoryEvent();

writeJFRHeader();

if (isResultNotOKay()) {
Trc_VM_jfr_ErrorWritingChunk(_currentThread, _buildResult);
goto freeBuffer;
}

writeJFRChunkToFile();
thallium marked this conversation as resolved.
Show resolved Hide resolved

_vm->jfrState.jfrChunkCount += 1;

freeBuffer:
_bufferWriter = NULL;
j9mem_free_memory(buffer);

_vm->jfrState.jfrChunkCount += 1;
}
done:
return;
Expand Down Expand Up @@ -482,6 +523,14 @@ class VM_JFRChunkWriter {

U_8 *writeJVMInformationEvent();

U_8 *writePhysicalMemoryEvent();

U_8 *writeCPUInformationEvent();

U_8 *writeVirtualizationInformationEvent();

U_8 *writeOSInformationEvent();

UDATA
calculateRequiredBufferSize()
{
Expand Down Expand Up @@ -522,6 +571,14 @@ class VM_JFRChunkWriter {

requireBufferSize += JVM_INFORMATION_EVENT_SIZE;

requireBufferSize += OS_INFORMATION_EVENT_SIZE;

requireBufferSize += PHYSICAL_MEMORY_EVENT_SIZE;

requireBufferSize += VIRTUALIZATION_INFORMATION_EVENT_SIZE;

requireBufferSize += CPU_INFORMATION_EVENT_SIZE;

return requireBufferSize;
}

Expand Down
Loading