8223438: add VirtualizationInformation JFR event

Reviewed-by: clanger, egahlin
This commit is contained in:
Matthias Baesken 2019-05-16 09:21:49 +02:00
parent 4e38fe2957
commit c39088c391
11 changed files with 153 additions and 5 deletions

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018, SAP SE. All rights reserved.
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -382,6 +382,50 @@ void VM_Version::initialize() {
if (FLAG_IS_DEFAULT(UseUnalignedAccesses)) {
FLAG_SET_DEFAULT(UseUnalignedAccesses, true);
}
check_virtualizations();
}
void VM_Version::check_virtualizations() {
#if defined(_AIX)
int rc = 0;
perfstat_partition_total_t pinfo;
rc = perfstat_partition_total(NULL, &pinfo, sizeof(perfstat_partition_total_t), 1);
if (rc == 1) {
Abstract_VM_Version::_detected_virtualization = PowerVM;
}
#else
const char* info_file = "/proc/ppc64/lparcfg";
// system_type=...qemu indicates PowerKVM
// e.g. system_type=IBM pSeries (emulated by qemu)
char line[500];
FILE* fp = fopen(info_file, "r");
if (fp == NULL) {
return;
}
const char* system_type="system_type="; // in case this line contains qemu, it is KVM
const char* num_lpars="NumLpars="; // in case of non-KVM : if this line is found it is PowerVM
bool num_lpars_found = false;
while (fgets(line, sizeof(line), fp) != NULL) {
if (strncmp(line, system_type, strlen(system_type)) == 0) {
if (strstr(line, "qemu") != 0) {
Abstract_VM_Version::_detected_virtualization = PowerKVM;
fclose(fp);
return;
}
}
if (strncmp(line, num_lpars, strlen(num_lpars)) == 0) {
num_lpars_found = true;
}
}
if (num_lpars_found) {
Abstract_VM_Version::_detected_virtualization = PowerVM;
} else {
Abstract_VM_Version::_detected_virtualization = PowerFullPartitionMode;
}
fclose(fp);
#endif
}
void VM_Version::print_platform_virtualization_info(outputStream* st) {

View File

@ -1,6 +1,6 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2018 SAP SE. All rights reserved.
* Copyright (c) 2012, 2019 SAP SE. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -87,6 +87,7 @@ protected:
public:
// Initialization
static void initialize();
static void check_virtualizations();
// Override Abstract_VM_Version implementation
static void print_platform_virtualization_info(outputStream*);

View File

@ -615,6 +615,10 @@
<Field type="string" name="osVersion" label="OS Version" />
</Event>
<Event name="VirtualizationInformation" category="Operating System" label="Virtualization Information" period="endChunk">
<Field type="string" name="name" label="Name" />
</Event>
<Event name="InitialSystemProperty" category="Java Virtual Machine" label="Initial System Property" description="System Property at JVM start" period="endChunk">
<Field type="string" name="key" label="Key" />
<Field type="string" name="value" label="Value" />

View File

@ -215,6 +215,27 @@ int JfrOSInterface::os_version(char** os_version) {
return instance()._impl->os_version(os_version);
}
const char* JfrOSInterface::virtualization_name() {
VirtualizationType vrt = VM_Version::get_detected_virtualization();
if (vrt == XenHVM) {
return "Xen hardware-assisted virtualization";
} else if (vrt == KVM) {
return "KVM virtualization";
} else if (vrt == VMWare) {
return "VMWare virtualization";
} else if (vrt == HyperV) {
return "HyperV virtualization";
} else if (vrt == PowerVM) {
return "PowerVM virtualization";
} else if (vrt == PowerKVM) {
return "Power KVM virtualization";
} else if (vrt == PowerFullPartitionMode) {
return "Power full partition";
}
return "No virtualization detected";
}
int JfrOSInterface::generate_initial_environment_variable_events() {
if (environ == NULL) {
return OS_ERR;

View File

@ -52,6 +52,7 @@ class JfrOSInterface: public JfrCHeapObj {
static int cpu_load_total_process(double* cpu_load);
static int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
static int os_version(char** os_version);
static const char* virtualization_name();
static int generate_initial_environment_variable_events();
static int system_processes(SystemProcess** system_processes, int* no_of_sys_processes);
static int network_utilization(NetworkInterface** network_interfaces);

View File

@ -95,6 +95,12 @@ TRACE_REQUEST_FUNC(OSInformation) {
event.commit();
}
TRACE_REQUEST_FUNC(VirtualizationInformation) {
EventVirtualizationInformation event;
event.set_name(JfrOSInterface::virtualization_name());
event.commit();
}
TRACE_REQUEST_FUNC(ModuleRequire) {
JfrModuleEvent::generate_module_dependency_events();
}

View File

@ -34,7 +34,10 @@ typedef enum {
XenHVM,
KVM,
VMWare,
HyperV
HyperV,
PowerVM, // on AIX or Linux ppc64(le)
PowerFullPartitionMode, // on Linux ppc64(le)
PowerKVM
} VirtualizationType;
// VM_Version provides information about the VM.

View File

@ -513,6 +513,11 @@
<setting name="period">beginChunk</setting>
</event>
<event name="jdk.VirtualizationInformation">
<setting name="enabled">true</setting>
<setting name="period">beginChunk</setting>
</event>
<event name="jdk.CPUInformation">
<setting name="enabled">true</setting>
<setting name="period">beginChunk</setting>

View File

@ -513,6 +513,11 @@
<setting name="period">beginChunk</setting>
</event>
<event name="jdk.VirtualizationInformation">
<setting name="enabled">true</setting>
<setting name="period">beginChunk</setting>
</event>
<event name="jdk.CPUInformation">
<setting name="enabled">true</setting>
<setting name="period">beginChunk</setting>

View File

@ -0,0 +1,57 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package jdk.jfr.event.os;
import java.util.List;
import jdk.jfr.Recording;
import jdk.jfr.consumer.RecordedEvent;
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
/**
* @test
* @key jfr
* @requires vm.hasJFR
* @library /test/lib
* @run main/othervm jdk.jfr.event.os.TestVirtualizationInfo
*/
public class TestVirtualizationInfo {
private final static String EVENT_NAME = EventNames.VirtualizationInformation;
public static void main(String[] args) throws Throwable {
Recording recording = new Recording();
recording.enable(EVENT_NAME);
recording.start();
recording.stop();
List<RecordedEvent> events = Events.fromRecording(recording);
Events.hasEvents(events);
for (RecordedEvent event : events) {
System.out.println("Event: " + event);
Events.assertField(event, "name").notEmpty();
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -154,6 +154,7 @@ public class EventNames {
// OS
public final static String OSInformation = PREFIX + "OSInformation";
public final static String VirtualizationInformation = PREFIX + "VirtualizationInformation";
public final static String CPUInformation = PREFIX + "CPUInformation";
public final static String CPULoad = PREFIX + "CPULoad";
public final static String ThreadCPULoad = PREFIX + "ThreadCPULoad";