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