src/share/vm/jfr/periodic/jfrOSInterface.cpp

Wed, 16 Jan 2019 13:38:19 -0500

author
stooke
date
Wed, 16 Jan 2019 13:38:19 -0500
changeset 9878
8689c69d5c19
parent 9858
b985cbb00e68
permissions
-rw-r--r--

8216578: Remove unused/obsolete method in JFR code
Reviewed-by: mgronlun, mikael

apetushkov@9858 1 /*
stooke@9878 2 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
apetushkov@9858 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
apetushkov@9858 4 *
apetushkov@9858 5 * This code is free software; you can redistribute it and/or modify it
apetushkov@9858 6 * under the terms of the GNU General Public License version 2 only, as
apetushkov@9858 7 * published by the Free Software Foundation.
apetushkov@9858 8 *
apetushkov@9858 9 * This code is distributed in the hope that it will be useful, but WITHOUT
apetushkov@9858 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
apetushkov@9858 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
apetushkov@9858 12 * version 2 for more details (a copy is included in the LICENSE file that
apetushkov@9858 13 * accompanied this code).
apetushkov@9858 14 *
apetushkov@9858 15 * You should have received a copy of the GNU General Public License version
apetushkov@9858 16 * 2 along with this work; if not, write to the Free Software Foundation,
apetushkov@9858 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
apetushkov@9858 18 *
apetushkov@9858 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
apetushkov@9858 20 * or visit www.oracle.com if you need additional information or have any
apetushkov@9858 21 * questions.
apetushkov@9858 22 *
apetushkov@9858 23 */
apetushkov@9858 24
apetushkov@9858 25 #include "precompiled.hpp"
apetushkov@9858 26 #include "jfr/jfrEvents.hpp"
apetushkov@9858 27 #include "jfr/periodic/jfrNetworkUtilization.hpp"
apetushkov@9858 28 #include "jfr/periodic/jfrOSInterface.hpp"
apetushkov@9858 29 #include "memory/allocation.inline.hpp"
apetushkov@9858 30 #include "memory/resourceArea.hpp"
apetushkov@9858 31 #include "runtime/os.hpp"
apetushkov@9858 32 #include "runtime/os_perf.hpp"
apetushkov@9858 33 #include "utilities/ostream.hpp"
apetushkov@9858 34
apetushkov@9858 35 #include <stdlib.h> // for environment variables
apetushkov@9858 36 #ifdef __APPLE__
apetushkov@9858 37 #include <crt_externs.h>
apetushkov@9858 38 #define environ (*_NSGetEnviron())
apetushkov@9858 39 #endif
apetushkov@9858 40
apetushkov@9858 41 #ifndef environ
apetushkov@9858 42 extern char** environ;
apetushkov@9858 43 #endif
apetushkov@9858 44
apetushkov@9858 45 static JfrOSInterface* _instance = NULL;
apetushkov@9858 46
apetushkov@9858 47 JfrOSInterface& JfrOSInterface::instance() {
apetushkov@9858 48 return *_instance;
apetushkov@9858 49 }
apetushkov@9858 50
apetushkov@9858 51 JfrOSInterface* JfrOSInterface::create() {
apetushkov@9858 52 assert(_instance == NULL, "invariant");
apetushkov@9858 53 _instance = new JfrOSInterface();
apetushkov@9858 54 return _instance;
apetushkov@9858 55 }
apetushkov@9858 56
apetushkov@9858 57 void JfrOSInterface::destroy() {
apetushkov@9858 58 JfrNetworkUtilization::destroy();
apetushkov@9858 59 if (_instance != NULL) {
apetushkov@9858 60 delete _instance;
apetushkov@9858 61 _instance = NULL;
apetushkov@9858 62 }
apetushkov@9858 63 }
apetushkov@9858 64
apetushkov@9858 65 class JfrOSInterface::JfrOSInterfaceImpl : public JfrCHeapObj {
apetushkov@9858 66 friend class JfrOSInterface;
apetushkov@9858 67 private:
apetushkov@9858 68 CPUInformationInterface* _cpu_info_interface;
apetushkov@9858 69 CPUPerformanceInterface* _cpu_perf_interface;
apetushkov@9858 70 SystemProcessInterface* _system_process_interface;
apetushkov@9858 71 NetworkPerformanceInterface* _network_performance_interface;
apetushkov@9858 72
apetushkov@9858 73 JfrOSInterfaceImpl();
apetushkov@9858 74 bool initialize();
apetushkov@9858 75 ~JfrOSInterfaceImpl();
apetushkov@9858 76
apetushkov@9858 77 // cpu info
apetushkov@9858 78 int cpu_information(CPUInformation& cpu_info);
apetushkov@9858 79 int cpu_load(int which_logical_cpu, double* cpu_load);
apetushkov@9858 80 int context_switch_rate(double* rate);
apetushkov@9858 81 int cpu_load_total_process(double* cpu_load);
apetushkov@9858 82 int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotal);
apetushkov@9858 83
apetushkov@9858 84 // os information
apetushkov@9858 85 int os_version(char** os_version) const;
apetushkov@9858 86
apetushkov@9858 87 // environment information
apetushkov@9858 88 void generate_environment_variables_events();
apetushkov@9858 89
apetushkov@9858 90 // system processes information
apetushkov@9858 91 int system_processes(SystemProcess** system_processes, int* no_of_sys_processes);
apetushkov@9858 92
apetushkov@9858 93 int network_utilization(NetworkInterface** network_interfaces) const;
apetushkov@9858 94 };
apetushkov@9858 95
apetushkov@9858 96 JfrOSInterface::JfrOSInterfaceImpl::JfrOSInterfaceImpl() : _cpu_info_interface(NULL),
apetushkov@9858 97 _cpu_perf_interface(NULL),
apetushkov@9858 98 _system_process_interface(NULL) {}
apetushkov@9858 99
apetushkov@9858 100 bool JfrOSInterface::JfrOSInterfaceImpl::initialize() {
apetushkov@9858 101 _cpu_info_interface = new CPUInformationInterface();
apetushkov@9858 102 if (!(_cpu_info_interface != NULL && _cpu_info_interface->initialize())) {
apetushkov@9858 103 return false;
apetushkov@9858 104 }
apetushkov@9858 105 _cpu_perf_interface = new CPUPerformanceInterface();
apetushkov@9858 106 if (!(_cpu_perf_interface != NULL && _cpu_perf_interface->initialize())) {
apetushkov@9858 107 return false;
apetushkov@9858 108 }
apetushkov@9858 109 _system_process_interface = new SystemProcessInterface();
apetushkov@9858 110 if (!(_system_process_interface != NULL && _system_process_interface->initialize())) {
apetushkov@9858 111 return false;
apetushkov@9858 112 }
apetushkov@9858 113 _network_performance_interface = new NetworkPerformanceInterface();
apetushkov@9858 114 return _network_performance_interface != NULL && _network_performance_interface->initialize();
apetushkov@9858 115 }
apetushkov@9858 116
apetushkov@9858 117 JfrOSInterface::JfrOSInterfaceImpl::~JfrOSInterfaceImpl(void) {
apetushkov@9858 118 if (_cpu_info_interface != NULL) {
apetushkov@9858 119 delete _cpu_info_interface;
apetushkov@9858 120 _cpu_info_interface = NULL;
apetushkov@9858 121 }
apetushkov@9858 122 if (_cpu_perf_interface != NULL) {
apetushkov@9858 123 delete _cpu_perf_interface;
apetushkov@9858 124 _cpu_perf_interface = NULL;
apetushkov@9858 125 }
apetushkov@9858 126 if (_system_process_interface != NULL) {
apetushkov@9858 127 delete _system_process_interface;
apetushkov@9858 128 _system_process_interface = NULL;
apetushkov@9858 129 }
apetushkov@9858 130 if (_network_performance_interface != NULL) {
apetushkov@9858 131 delete _network_performance_interface;
apetushkov@9858 132 _network_performance_interface = NULL;
apetushkov@9858 133 }
apetushkov@9858 134 }
apetushkov@9858 135
apetushkov@9858 136 int JfrOSInterface::JfrOSInterfaceImpl::cpu_load(int which_logical_cpu, double* cpu_load) {
apetushkov@9858 137 return _cpu_perf_interface->cpu_load(which_logical_cpu, cpu_load);
apetushkov@9858 138 }
apetushkov@9858 139
apetushkov@9858 140 int JfrOSInterface::JfrOSInterfaceImpl::context_switch_rate(double* rate) {
apetushkov@9858 141 return _cpu_perf_interface->context_switch_rate(rate);
apetushkov@9858 142 }
apetushkov@9858 143
apetushkov@9858 144 int JfrOSInterface::JfrOSInterfaceImpl::cpu_load_total_process(double* cpu_load) {
apetushkov@9858 145 return _cpu_perf_interface->cpu_load_total_process(cpu_load);
apetushkov@9858 146 }
apetushkov@9858 147
apetushkov@9858 148 int JfrOSInterface::JfrOSInterfaceImpl::cpu_loads_process(double* pjvmUserLoad,
apetushkov@9858 149 double* pjvmKernelLoad,
apetushkov@9858 150 double* psystemTotal) {
apetushkov@9858 151 return _cpu_perf_interface->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotal);
apetushkov@9858 152 }
apetushkov@9858 153
apetushkov@9858 154 int JfrOSInterface::JfrOSInterfaceImpl::cpu_information(CPUInformation& cpu_info) {
apetushkov@9858 155 return _cpu_info_interface->cpu_information(cpu_info);
apetushkov@9858 156 }
apetushkov@9858 157
apetushkov@9858 158 int JfrOSInterface::JfrOSInterfaceImpl::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) {
apetushkov@9858 159 assert(system_processes != NULL, "system_processes pointer is NULL!");
apetushkov@9858 160 assert(no_of_sys_processes != NULL, "no_of_sys_processes pointer is NULL!");
apetushkov@9858 161 return _system_process_interface->system_processes(system_processes, no_of_sys_processes);
apetushkov@9858 162 }
apetushkov@9858 163
apetushkov@9858 164 int JfrOSInterface::JfrOSInterfaceImpl::network_utilization(NetworkInterface** network_interfaces) const {
apetushkov@9858 165 return _network_performance_interface->network_utilization(network_interfaces);
apetushkov@9858 166 }
apetushkov@9858 167
apetushkov@9858 168 // assigned char* is RESOURCE_HEAP_ALLOCATED
apetushkov@9858 169 // caller need to ensure proper ResourceMark placement.
apetushkov@9858 170 int JfrOSInterface::JfrOSInterfaceImpl::os_version(char** os_version) const {
apetushkov@9858 171 assert(os_version != NULL, "os_version pointer is NULL!");
apetushkov@9858 172 stringStream os_ver_info;
apetushkov@9858 173 os::print_os_info_brief(&os_ver_info);
apetushkov@9858 174 *os_version = os_ver_info.as_string();
apetushkov@9858 175 return OS_OK;
apetushkov@9858 176 }
apetushkov@9858 177
apetushkov@9858 178 JfrOSInterface::JfrOSInterface() {
apetushkov@9858 179 _impl = NULL;
apetushkov@9858 180 }
apetushkov@9858 181
apetushkov@9858 182 bool JfrOSInterface::initialize() {
apetushkov@9858 183 _impl = new JfrOSInterface::JfrOSInterfaceImpl();
apetushkov@9858 184 return _impl != NULL && _impl->initialize();
apetushkov@9858 185 }
apetushkov@9858 186
apetushkov@9858 187 JfrOSInterface::~JfrOSInterface() {
apetushkov@9858 188 if (_impl != NULL) {
apetushkov@9858 189 delete _impl;
apetushkov@9858 190 _impl = NULL;
apetushkov@9858 191 }
apetushkov@9858 192 }
apetushkov@9858 193
apetushkov@9858 194 int JfrOSInterface::cpu_information(CPUInformation& cpu_info) {
apetushkov@9858 195 return instance()._impl->cpu_information(cpu_info);
apetushkov@9858 196 }
apetushkov@9858 197
apetushkov@9858 198 int JfrOSInterface::cpu_load(int which_logical_cpu, double* cpu_load) {
apetushkov@9858 199 return instance()._impl->cpu_load(which_logical_cpu, cpu_load);
apetushkov@9858 200 }
apetushkov@9858 201
apetushkov@9858 202 int JfrOSInterface::context_switch_rate(double* rate) {
apetushkov@9858 203 return instance()._impl->context_switch_rate(rate);
apetushkov@9858 204 }
apetushkov@9858 205
apetushkov@9858 206 int JfrOSInterface::cpu_load_total_process(double* cpu_load) {
apetushkov@9858 207 return instance()._impl->cpu_load_total_process(cpu_load);
apetushkov@9858 208 }
apetushkov@9858 209
apetushkov@9858 210 int JfrOSInterface::cpu_loads_process(double* jvm_user_load, double* jvm_kernel_load, double* system_total_load){
apetushkov@9858 211 return instance()._impl->cpu_loads_process(jvm_user_load, jvm_kernel_load, system_total_load);
apetushkov@9858 212 }
apetushkov@9858 213
apetushkov@9858 214 int JfrOSInterface::os_version(char** os_version) {
apetushkov@9858 215 return instance()._impl->os_version(os_version);
apetushkov@9858 216 }
apetushkov@9858 217
apetushkov@9858 218 int JfrOSInterface::generate_initial_environment_variable_events() {
apetushkov@9858 219 if (environ == NULL) {
apetushkov@9858 220 return OS_ERR;
apetushkov@9858 221 }
apetushkov@9858 222
apetushkov@9858 223 if (EventInitialEnvironmentVariable::is_enabled()) {
apetushkov@9858 224 // One time stamp for all events, so they can be grouped together
apetushkov@9858 225 JfrTicks time_stamp = JfrTicks::now();
apetushkov@9858 226 for (char** p = environ; *p != NULL; p++) {
apetushkov@9858 227 char* variable = *p;
apetushkov@9858 228 char* equal_sign = strchr(variable, '=');
apetushkov@9858 229 if (equal_sign != NULL) {
apetushkov@9858 230 // Extract key/value
apetushkov@9858 231 ResourceMark rm;
apetushkov@9858 232 ptrdiff_t key_length = equal_sign - variable;
apetushkov@9858 233 char* key = NEW_RESOURCE_ARRAY(char, key_length + 1);
apetushkov@9858 234 char* value = equal_sign + 1;
apetushkov@9858 235 strncpy(key, variable, key_length);
apetushkov@9858 236 key[key_length] = '\0';
apetushkov@9858 237 EventInitialEnvironmentVariable event(UNTIMED);
apetushkov@9858 238 event.set_endtime(time_stamp);
apetushkov@9858 239 event.set_key(key);
apetushkov@9858 240 event.set_value(value);
apetushkov@9858 241 event.commit();
apetushkov@9858 242 }
apetushkov@9858 243 }
apetushkov@9858 244 }
apetushkov@9858 245 return OS_OK;
apetushkov@9858 246 }
apetushkov@9858 247
apetushkov@9858 248 int JfrOSInterface::system_processes(SystemProcess** sys_processes, int* no_of_sys_processes) {
apetushkov@9858 249 return instance()._impl->system_processes(sys_processes, no_of_sys_processes);
apetushkov@9858 250 }
apetushkov@9858 251
apetushkov@9858 252 int JfrOSInterface::network_utilization(NetworkInterface** network_interfaces) {
apetushkov@9858 253 return instance()._impl->network_utilization(network_interfaces);
apetushkov@9858 254 }

mercurial