8222720: Provide extended VMWare/vSphere virtualization related info in the hs_error file on linux/windows x86_64
Reviewed-by: dholmes, rehn
This commit is contained in:
parent
5bdacf11bd
commit
4745d994cc
@ -32,6 +32,7 @@
|
||||
#include "runtime/java.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "runtime/stubCodeGenerator.hpp"
|
||||
#include "utilities/virtualizationSupport.hpp"
|
||||
#include "vm_version_x86.hpp"
|
||||
|
||||
|
||||
@ -1581,6 +1582,7 @@ void VM_Version::print_platform_virtualization_info(outputStream* st) {
|
||||
st->print_cr("KVM virtualization detected");
|
||||
} else if (vrt == VMWare) {
|
||||
st->print_cr("VMWare virtualization detected");
|
||||
VirtualizationSupport::print_virtualization_info(st);
|
||||
} else if (vrt == HyperV) {
|
||||
st->print_cr("HyperV virtualization detected");
|
||||
}
|
||||
@ -1684,6 +1686,8 @@ void VM_Version::check_virtualizations() {
|
||||
|
||||
if (strncmp("VMwareVMware", signature, 12) == 0) {
|
||||
Abstract_VM_Version::_detected_virtualization = VMWare;
|
||||
// check for extended metrics from guestlib
|
||||
VirtualizationSupport::initialize();
|
||||
}
|
||||
|
||||
if (strncmp("Microsoft Hv", signature, 12) == 0) {
|
||||
|
@ -591,6 +591,7 @@ class os: AllStatic {
|
||||
// Loads .dll/.so and
|
||||
// in case of error it checks if .dll/.so was built for the
|
||||
// same architecture as HotSpot is running on
|
||||
// in case of an error NULL is returned and an error message is stored in ebuf
|
||||
static void* dll_load(const char *name, char *ebuf, int ebuflen);
|
||||
|
||||
// lookup symbol in a shared library
|
||||
|
102
src/hotspot/share/utilities/virtualizationSupport.cpp
Normal file
102
src/hotspot/share/utilities/virtualizationSupport.cpp
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "precompiled.hpp"
|
||||
#include "runtime/os.hpp"
|
||||
#include "utilities/virtualizationSupport.hpp"
|
||||
|
||||
static void *dlHandle = NULL;
|
||||
|
||||
static GuestLib_StatGet_t GuestLib_StatGet = NULL;
|
||||
static GuestLib_StatFree_t GuestLib_StatFree = NULL;
|
||||
|
||||
static bool has_host_information = false;
|
||||
static bool has_resource_information = false;
|
||||
|
||||
// host + resource information; avoid the session and other special info vectors
|
||||
static char host_information[300];
|
||||
static char extended_resource_info_at_startup[600];
|
||||
|
||||
void VirtualizationSupport::initialize() {
|
||||
// open vmguestlib and bind SDK functions
|
||||
char ebuf[1024];
|
||||
dlHandle = os::dll_load("vmGuestLib", ebuf, sizeof ebuf);
|
||||
|
||||
#ifdef LINUX
|
||||
if (dlHandle == NULL) {
|
||||
// the open-vm-tools have a different guest lib name
|
||||
// on some distros e.g. SLES12 the open-vm-tools are the default,
|
||||
// so use the different libname as a fallback
|
||||
dlHandle = os::dll_load("/usr/lib64/libguestlib.so.0", ebuf, sizeof ebuf);
|
||||
}
|
||||
#endif
|
||||
if (dlHandle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
GuestLib_StatGet = CAST_TO_FN_PTR(GuestLib_StatGet_t, os::dll_lookup(dlHandle, "VMGuestLib_StatGet"));
|
||||
GuestLib_StatFree = CAST_TO_FN_PTR(GuestLib_StatFree_t, os::dll_lookup(dlHandle, "VMGuestLib_StatFree"));
|
||||
|
||||
if (GuestLib_StatGet != NULL && GuestLib_StatFree != NULL) {
|
||||
char* result_info = NULL;
|
||||
size_t result_size = 0;
|
||||
VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
|
||||
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
|
||||
has_resource_information = true;
|
||||
snprintf(extended_resource_info_at_startup, sizeof(extended_resource_info_at_startup), "%s", result_info);
|
||||
GuestLib_StatFree(result_info, result_size);
|
||||
}
|
||||
sg_error = GuestLib_StatGet("text", "host", &result_info, &result_size);
|
||||
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
|
||||
has_host_information = true;
|
||||
snprintf(host_information, sizeof(host_information), "%s", result_info);
|
||||
GuestLib_StatFree(result_info, result_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void VirtualizationSupport::print_virtualization_info(outputStream* st) {
|
||||
if (has_host_information) {
|
||||
st->print_cr("vSphere host information:");
|
||||
st->print_cr("%s", host_information);
|
||||
}
|
||||
// resource info at startup
|
||||
if (has_resource_information) {
|
||||
st->print_cr("vSphere resource information collected at VM startup:");
|
||||
st->print_cr("%s", extended_resource_info_at_startup);
|
||||
}
|
||||
// current resource info
|
||||
if (GuestLib_StatGet != NULL && GuestLib_StatFree != NULL) {
|
||||
char* result_info = NULL;
|
||||
size_t result_size = 0;
|
||||
VMGuestLibError sg_error = GuestLib_StatGet("text", "resources", &result_info, &result_size);
|
||||
if (sg_error == VMGUESTLIB_ERROR_SUCCESS) {
|
||||
st->print_cr("vSphere resource information available now:");
|
||||
st->print_cr("%s", result_info);
|
||||
GuestLib_StatFree(result_info, result_size);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
56
src/hotspot/share/utilities/virtualizationSupport.hpp
Normal file
56
src/hotspot/share/utilities/virtualizationSupport.hpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 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
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_UTILITIES_VIRTUALIZATIONSUPPORT_HPP
|
||||
#define SHARE_UTILITIES_VIRTUALIZATIONSUPPORT_HPP
|
||||
|
||||
#include "utilities/ostream.hpp"
|
||||
|
||||
typedef enum {
|
||||
VMGUESTLIB_ERROR_SUCCESS = 0, // no error occured
|
||||
VMGUESTLIB_ERROR_OTHER,
|
||||
VMGUESTLIB_ERROR_NOT_RUNNING_IN_VM,
|
||||
VMGUESTLIB_ERROR_NOT_ENABLED,
|
||||
VMGUESTLIB_ERROR_NOT_AVAILABLE,
|
||||
VMGUESTLIB_ERROR_NO_INFO,
|
||||
VMGUESTLIB_ERROR_MEMORY,
|
||||
VMGUESTLIB_ERROR_BUFFER_TOO_SMALL,
|
||||
VMGUESTLIB_ERROR_INVALID_HANDLE,
|
||||
VMGUESTLIB_ERROR_INVALID_ARG,
|
||||
VMGUESTLIB_ERROR_UNSUPPORTED_VERSION
|
||||
} VMGuestLibError;
|
||||
|
||||
// new SDK functions from VMWare SDK 6.0; need VMware Tools version 9.10 installed
|
||||
typedef VMGuestLibError (*GuestLib_StatGet_t)(const char*, const char*, char**, size_t*);
|
||||
typedef VMGuestLibError (*GuestLib_StatFree_t)(char*, size_t);
|
||||
|
||||
class VirtualizationSupport {
|
||||
public:
|
||||
static void initialize();
|
||||
static void print_virtualization_info(outputStream* st);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user