1 /* 2 * Copyright (c) 2012, 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 #ifndef SHARE_RUNTIME_OS_PERF_HPP 26 #define SHARE_RUNTIME_OS_PERF_HPP 27 28 #include "memory/allocation.hpp" 29 #include "utilities/macros.hpp" 30 31 #define FUNCTIONALITY_NOT_IMPLEMENTED -8 32 33 class EnvironmentVariable : public CHeapObj<mtInternal> { 34 public: 35 char* _key; 36 char* _value; 37 38 EnvironmentVariable() { 39 _key = NULL; 40 _value = NULL; 41 } 42 43 ~EnvironmentVariable() { 44 FREE_C_HEAP_ARRAY(char, _key); 45 FREE_C_HEAP_ARRAY(char, _value); 46 } 47 48 EnvironmentVariable(char* key, char* value) { 49 _key = key; 50 _value = value; 51 } 52 53 }; 54 55 56 class CPUInformation : public CHeapObj<mtInternal> { 57 private: 58 int _no_of_sockets; 59 int _no_of_cores; 60 int _no_of_hw_threads; 61 const char* _description; 62 const char* _name; 63 64 public: 65 CPUInformation() { 66 _no_of_sockets = 0; 67 _no_of_cores = 0; 68 _no_of_hw_threads = 0; 69 _description = NULL; 70 _name = NULL; 71 } 72 73 int number_of_sockets(void) const { 74 return _no_of_sockets; 75 } 76 77 void set_number_of_sockets(int no_of_sockets) { 78 _no_of_sockets = no_of_sockets; 79 } 80 81 int number_of_cores(void) const { 82 return _no_of_cores; 83 } 84 85 void set_number_of_cores(int no_of_cores) { 86 _no_of_cores = no_of_cores; 87 } 88 89 int number_of_hardware_threads(void) const { 90 return _no_of_hw_threads; 91 } 92 93 void set_number_of_hardware_threads(int no_of_hw_threads) { 94 _no_of_hw_threads = no_of_hw_threads; 95 } 96 97 const char* cpu_name(void) const { 98 return _name; 99 } 100 101 void set_cpu_name(const char* cpu_name) { 102 _name = cpu_name; 103 } 104 105 const char* cpu_description(void) const { 106 return _description; 107 } 108 109 void set_cpu_description(const char* cpu_description) { 110 _description = cpu_description; 111 } 112 }; 113 114 class SystemProcess : public CHeapObj<mtInternal> { 115 private: 116 int _pid; 117 char* _name; 118 char* _path; 119 char* _command_line; 120 SystemProcess* _next; 121 122 public: 123 SystemProcess() { 124 _pid = 0; 125 _name = NULL; 126 _path = NULL; 127 _command_line = NULL; 128 _next = NULL; 129 } 130 131 SystemProcess(int pid, char* name, char* path, char* command_line, SystemProcess* next) { 132 _pid = pid; 133 _name = name; 134 _path = path; 135 _command_line = command_line; 136 _next = next; 137 } 138 139 void set_next(SystemProcess* sys_process) { 140 _next = sys_process; 141 } 142 143 SystemProcess* next(void) const { 144 return _next; 145 } 146 147 int pid(void) const { 148 return _pid; 149 } 150 151 void set_pid(int pid) { 152 _pid = pid; 153 } 154 155 const char* name(void) const { 156 return _name; 157 } 158 159 void set_name(char* name) { 160 _name = name; 161 } 162 163 const char* path(void) const { 164 return _path; 165 } 166 167 void set_path(char* path) { 168 _path = path; 169 } 170 171 const char* command_line(void) const { 172 return _command_line; 173 } 174 175 void set_command_line(char* command_line) { 176 _command_line = command_line; 177 } 178 179 virtual ~SystemProcess(void) { 180 FREE_C_HEAP_ARRAY(char, _name); 181 FREE_C_HEAP_ARRAY(char, _path); 182 FREE_C_HEAP_ARRAY(char, _command_line); 183 } 184 }; 185 186 class NetworkInterface : public ResourceObj { 187 private: 188 char* _name; 189 uint64_t _bytes_in; 190 uint64_t _bytes_out; 191 NetworkInterface* _next; 192 193 NONCOPYABLE(NetworkInterface); 194 195 public: 196 NetworkInterface(const char* name, uint64_t bytes_in, uint64_t bytes_out, NetworkInterface* next) : 197 _name(NULL), 198 _bytes_in(bytes_in), 199 _bytes_out(bytes_out), 200 _next(next) { 201 assert(name != NULL, "invariant"); 202 const size_t length = strlen(name); 203 assert(allocated_on_res_area(), "invariant"); 204 _name = NEW_RESOURCE_ARRAY(char, length + 1); 205 strncpy(_name, name, length + 1); 206 assert(strncmp(_name, name, length) == 0, "invariant"); 207 } 208 209 NetworkInterface* next() const { 210 return _next; 211 } 212 213 const char* get_name() const { 214 return _name; 215 } 216 217 uint64_t get_bytes_out() const { 218 return _bytes_out; 219 } 220 221 uint64_t get_bytes_in() const { 222 return _bytes_in; 223 } 224 }; 225 226 class CPUInformationInterface : public CHeapObj<mtInternal> { 227 private: 228 CPUInformation* _cpu_info; 229 public: 230 CPUInformationInterface(); 231 bool initialize(); 232 ~CPUInformationInterface(); 233 int cpu_information(CPUInformation& cpu_info); 234 }; 235 236 class CPUPerformanceInterface : public CHeapObj<mtInternal> { 237 private: 238 class CPUPerformance; 239 CPUPerformance* _impl; 240 public: 241 CPUPerformanceInterface(); 242 ~CPUPerformanceInterface(); 243 bool initialize(); 244 245 int cpu_load(int which_logical_cpu, double* const cpu_load) const; 246 int context_switch_rate(double* const rate) const; 247 int cpu_load_total_process(double* const cpu_load) const; 248 int cpu_loads_process(double* const pjvmUserLoad, 249 double* const pjvmKernelLoad, 250 double* const psystemTotalLoad) const; 251 }; 252 253 class SystemProcessInterface : public CHeapObj<mtInternal> { 254 private: 255 class SystemProcesses; 256 SystemProcesses* _impl; 257 public: 258 SystemProcessInterface(); 259 ~SystemProcessInterface(); 260 bool initialize(); 261 262 // information about system processes 263 int system_processes(SystemProcess** system_procs, int* const no_of_sys_processes) const; 264 }; 265 266 class NetworkPerformanceInterface : public CHeapObj<mtInternal> { 267 private: 268 class NetworkPerformance; 269 NetworkPerformance* _impl; 270 NONCOPYABLE(NetworkPerformanceInterface); 271 272 public: 273 NetworkPerformanceInterface(); 274 bool initialize(); 275 ~NetworkPerformanceInterface(); 276 int network_utilization(NetworkInterface** network_interfaces) const; 277 }; 278 279 #endif // SHARE_RUNTIME_OS_PERF_HPP