Path: blob/master/src/hotspot/share/services/runtimeService.cpp
41145 views
/*1* Copyright (c) 2003, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "logging/log.hpp"26#include "logging/logStream.hpp"27#include "runtime/vm_version.hpp"28#include "services/attachListener.hpp"29#include "services/management.hpp"30#include "services/runtimeService.hpp"31#include "utilities/dtrace.hpp"32#include "utilities/exceptions.hpp"33#include "utilities/macros.hpp"3435#if INCLUDE_MANAGEMENT36PerfCounter* RuntimeService::_sync_time_ticks = NULL;37PerfCounter* RuntimeService::_total_safepoints = NULL;38PerfCounter* RuntimeService::_safepoint_time_ticks = NULL;39PerfCounter* RuntimeService::_application_time_ticks = NULL;4041void RuntimeService::init() {42if (UsePerfData) {43EXCEPTION_MARK;4445_sync_time_ticks =46PerfDataManager::create_counter(SUN_RT, "safepointSyncTime",47PerfData::U_Ticks, CHECK);4849_total_safepoints =50PerfDataManager::create_counter(SUN_RT, "safepoints",51PerfData::U_Events, CHECK);5253_safepoint_time_ticks =54PerfDataManager::create_counter(SUN_RT, "safepointTime",55PerfData::U_Ticks, CHECK);5657_application_time_ticks =58PerfDataManager::create_counter(SUN_RT, "applicationTime",59PerfData::U_Ticks, CHECK);606162// create performance counters for jvm_version and its capabilities63PerfDataManager::create_constant(SUN_RT, "jvmVersion", PerfData::U_None,64(jlong) VM_Version::jvm_version(), CHECK);6566// The capabilities counter is a binary representation of the VM capabilities in string.67// This string respresentation simplifies the implementation of the client side68// to parse the value.69char capabilities[65];70size_t len = sizeof(capabilities);71memset((void*) capabilities, '0', len);72capabilities[len-1] = '\0';73capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0';74#if INCLUDE_SERVICES75capabilities[1] = '1';76#endif // INCLUDE_SERVICES77PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities",78capabilities, CHECK);79}80}8182void RuntimeService::record_safepoint_begin(jlong app_ticks) {83HS_PRIVATE_SAFEPOINT_BEGIN();84if (UsePerfData) {85_total_safepoints->inc();86_application_time_ticks->inc(app_ticks);87}88}8990void RuntimeService::record_safepoint_synchronized(jlong sync_ticks) {91if (UsePerfData) {92_sync_time_ticks->inc(sync_ticks);93}94}9596void RuntimeService::record_safepoint_end(jlong safepoint_ticks) {97HS_PRIVATE_SAFEPOINT_END();98if (UsePerfData) {99_safepoint_time_ticks->inc(safepoint_ticks);100}101}102103jlong RuntimeService::safepoint_sync_time_ms() {104return UsePerfData ?105Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1;106}107108jlong RuntimeService::safepoint_count() {109return UsePerfData ?110_total_safepoints->get_value() : -1;111}112jlong RuntimeService::safepoint_time_ms() {113return UsePerfData ?114Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1;115}116117jlong RuntimeService::application_time_ms() {118return UsePerfData ?119Management::ticks_to_ms(_application_time_ticks->get_value()) : -1;120}121122#endif // INCLUDE_MANAGEMENT123124125