8380773: Extend ContainerMemoryUsageEvent to include host memory usage

This commit is contained in:
Stefan Johansson 2026-02-24 15:52:59 +00:00
parent cc29010ae2
commit 2bb3c290cb
6 changed files with 22 additions and 0 deletions

View File

@ -410,6 +410,13 @@ JVM_ENTRY_NO_ENV(jlong, jfr_host_total_swap_memory(JNIEnv* env, jclass jvm))
return static_cast<jlong>(total_swap_space);
JVM_END
JVM_ENTRY_NO_ENV(jlong, jfr_host_memory_usage(JNIEnv* env, jclass jvm))
physical_memory_size_type memory_usage = 0;
// Return value ignored - defaulting to 0 on failure.
(void)os::Machine::used_memory(memory_usage);
return static_cast<jlong>(memory_usage);
JVM_END
JVM_ENTRY_NO_ENV(void, jfr_emit_data_loss(JNIEnv* env, jclass jvm, jlong bytes))
EventDataLoss::commit(bytes, min_jlong);
JVM_END

View File

@ -163,6 +163,8 @@ jlong JNICALL jfr_host_total_memory(JNIEnv* env, jclass jvm);
jlong JNICALL jfr_host_total_swap_memory(JNIEnv* env, jclass jvm);
jlong JNICALL jfr_host_memory_usage(JNIEnv* env, jclass jvm);
void JNICALL jfr_emit_data_loss(JNIEnv* env, jclass jvm, jlong bytes);
jlong JNICALL jfr_register_stack_filter(JNIEnv* env, jclass jvm, jobjectArray classes, jobjectArray methods);

View File

@ -101,6 +101,7 @@ JfrJniMethodRegistration::JfrJniMethodRegistration(JNIEnv* env) {
(char*)"isContainerized", (char*)"()Z", (void*) jfr_is_containerized,
(char*)"hostTotalMemory", (char*)"()J", (void*) jfr_host_total_memory,
(char*)"hostTotalSwapMemory", (char*)"()J", (void*) jfr_host_total_swap_memory,
(char*)"hostMemoryUsage", (char*)"()J", (void*) jfr_host_memory_usage,
(char*)"emitDataLoss", (char*)"(J)V", (void*)jfr_emit_data_loss,
(char*)"registerStackFilter", (char*)"([Ljava/lang/String;[Ljava/lang/String;)J", (void*)jfr_register_stack_filter,
(char*)"unregisterStackFilter", (char*)"(J)V", (void*)jfr_unregister_stack_filter,

View File

@ -50,4 +50,9 @@ public final class ContainerMemoryUsageEvent extends AbstractPeriodicEvent {
@Description("Amount of physical memory and swap space, in bytes, that is currently allocated in the current container")
@DataAmount
public long swapMemoryUsage;
@Label("Host Memory Usage")
@Description("Amount of physical memory, in bytes, that is currently allocated in the host system")
@DataAmount
public long hostMemoryUsage;
}

View File

@ -181,6 +181,7 @@ public final class JDKEvents {
event.memoryFailCount = containerMetrics.getMemoryFailCount();
event.memoryUsage = containerMetrics.getMemoryUsage();
event.swapMemoryUsage = containerMetrics.getMemoryAndSwapUsage();
event.hostMemoryUsage = JVM.hostMemoryUsage();
event.commit();
}
}

View File

@ -657,6 +657,12 @@ public final class JVM {
*/
public static native long hostTotalSwapMemory();
/**
* Returns the amount of memory used in the host system whether or not this
* JVM runs in a container.
*/
public static native long hostMemoryUsage();
/**
* Emit a jdk.DataLoss event for the specified amount of bytes.
*