1 | /* |
2 | * Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "classfile/classLoader.hpp" |
27 | #include "logging/log.hpp" |
28 | #include "logging/logStream.hpp" |
29 | #include "runtime/vm_version.hpp" |
30 | #include "services/attachListener.hpp" |
31 | #include "services/management.hpp" |
32 | #include "services/runtimeService.hpp" |
33 | #include "utilities/dtrace.hpp" |
34 | #include "utilities/exceptions.hpp" |
35 | #include "utilities/macros.hpp" |
36 | |
37 | #if INCLUDE_MANAGEMENT |
38 | PerfCounter* RuntimeService::_sync_time_ticks = NULL; |
39 | PerfCounter* RuntimeService::_total_safepoints = NULL; |
40 | PerfCounter* RuntimeService::_safepoint_time_ticks = NULL; |
41 | PerfCounter* RuntimeService::_application_time_ticks = NULL; |
42 | |
43 | void RuntimeService::init() { |
44 | if (UsePerfData) { |
45 | EXCEPTION_MARK; |
46 | |
47 | _sync_time_ticks = |
48 | PerfDataManager::create_counter(SUN_RT, "safepointSyncTime" , |
49 | PerfData::U_Ticks, CHECK); |
50 | |
51 | _total_safepoints = |
52 | PerfDataManager::create_counter(SUN_RT, "safepoints" , |
53 | PerfData::U_Events, CHECK); |
54 | |
55 | _safepoint_time_ticks = |
56 | PerfDataManager::create_counter(SUN_RT, "safepointTime" , |
57 | PerfData::U_Ticks, CHECK); |
58 | |
59 | _application_time_ticks = |
60 | PerfDataManager::create_counter(SUN_RT, "applicationTime" , |
61 | PerfData::U_Ticks, CHECK); |
62 | |
63 | |
64 | // create performance counters for jvm_version and its capabilities |
65 | PerfDataManager::create_constant(SUN_RT, "jvmVersion" , PerfData::U_None, |
66 | (jlong) VM_Version::jvm_version(), CHECK); |
67 | |
68 | // The capabilities counter is a binary representation of the VM capabilities in string. |
69 | // This string respresentation simplifies the implementation of the client side |
70 | // to parse the value. |
71 | char capabilities[65]; |
72 | size_t len = sizeof(capabilities); |
73 | memset((void*) capabilities, '0', len); |
74 | capabilities[len-1] = '\0'; |
75 | capabilities[0] = AttachListener::is_attach_supported() ? '1' : '0'; |
76 | #if INCLUDE_SERVICES |
77 | capabilities[1] = '1'; |
78 | #endif // INCLUDE_SERVICES |
79 | PerfDataManager::create_string_constant(SUN_RT, "jvmCapabilities" , |
80 | capabilities, CHECK); |
81 | } |
82 | } |
83 | |
84 | void RuntimeService::record_safepoint_begin(jlong app_ticks) { |
85 | HS_PRIVATE_SAFEPOINT_BEGIN(); |
86 | if (UsePerfData) { |
87 | _total_safepoints->inc(); |
88 | _application_time_ticks->inc(app_ticks); |
89 | } |
90 | } |
91 | |
92 | void RuntimeService::record_safepoint_synchronized(jlong sync_ticks) { |
93 | if (UsePerfData) { |
94 | _sync_time_ticks->inc(sync_ticks); |
95 | } |
96 | } |
97 | |
98 | void RuntimeService::record_safepoint_end(jlong safepoint_ticks) { |
99 | HS_PRIVATE_SAFEPOINT_END(); |
100 | if (UsePerfData) { |
101 | _safepoint_time_ticks->inc(safepoint_ticks); |
102 | } |
103 | } |
104 | |
105 | jlong RuntimeService::safepoint_sync_time_ms() { |
106 | return UsePerfData ? |
107 | Management::ticks_to_ms(_sync_time_ticks->get_value()) : -1; |
108 | } |
109 | |
110 | jlong RuntimeService::safepoint_count() { |
111 | return UsePerfData ? |
112 | _total_safepoints->get_value() : -1; |
113 | } |
114 | jlong RuntimeService::safepoint_time_ms() { |
115 | return UsePerfData ? |
116 | Management::ticks_to_ms(_safepoint_time_ticks->get_value()) : -1; |
117 | } |
118 | |
119 | jlong RuntimeService::application_time_ms() { |
120 | return UsePerfData ? |
121 | Management::ticks_to_ms(_application_time_ticks->get_value()) : -1; |
122 | } |
123 | |
124 | #endif // INCLUDE_MANAGEMENT |
125 | |