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_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 class EnvironmentVariable : public CHeapObj<mtInternal> { 35 public: 36 char* _key; 37 char* _value; 38 39 EnvironmentVariable() { 40 _key = NULL; 41 _value = NULL; 42 } 43 44 ~EnvironmentVariable() { 45 if (_key != NULL) { 46 FREE_C_HEAP_ARRAY(char, _key, mtInternal); 47 } 48 if (_value != NULL) { 49 FREE_C_HEAP_ARRAY(char, _value, mtInternal); //guangyu.zgy add one more argument 50 } 51 } 52 53 EnvironmentVariable(char* key, char* value) { 54 _key = key; 55 _value = value; 56 } 57 58 }; 59 60 61 class CPUInformation : public CHeapObj<mtInternal> { 62 private: 63 int _no_of_sockets; 64 int _no_of_cores; 65 int _no_of_hw_threads; 66 const char* _description; 67 const char* _name; 68 69 public: 70 CPUInformation() { 71 _no_of_sockets = 0; 72 _no_of_cores = 0; 73 _no_of_hw_threads = 0; 74 _description = NULL; 75 _name = NULL; 76 } 77 78 int number_of_sockets(void) const { 79 return _no_of_sockets; 80 } 81 82 void set_number_of_sockets(int no_of_sockets) { 83 _no_of_sockets = no_of_sockets; 84 } 85 86 int number_of_cores(void) const { 87 return _no_of_cores; 88 } 89 90 void set_number_of_cores(int no_of_cores) { 91 _no_of_cores = no_of_cores; 92 } 93 94 int number_of_hardware_threads(void) const { 95 return _no_of_hw_threads; 96 } 97 98 void set_number_of_hardware_threads(int no_of_hw_threads) { 99 _no_of_hw_threads = no_of_hw_threads; 100 } 101 102 const char* cpu_name(void) const { 103 return _name; 104 } 105 106 void set_cpu_name(const char* cpu_name) { 107 _name = cpu_name; 108 } 109 110 const char* cpu_description(void) const { 111 return _description; 112 } 113 114 void set_cpu_description(const char* cpu_description) { 115 _description = cpu_description; 116 } 117 }; 118 119 class SystemProcess : public CHeapObj<mtInternal> { 120 private: 121 int _pid; 122 char* _name; 123 char* _path; 124 char* _command_line; 125 SystemProcess* _next; 126 127 public: 128 SystemProcess() { 129 _pid = 0; 130 _name = NULL; 131 _path = NULL; 132 _command_line = NULL; 133 _next = NULL; 134 } 135 136 SystemProcess(int pid, char* name, char* path, char* command_line, SystemProcess* next) { 137 _pid = pid; 138 _name = name; 139 _path = path; 140 _command_line = command_line; 141 _next = next; 142 } 143 144 void set_next(SystemProcess* sys_process) { 145 _next = sys_process; 146 } 147 148 SystemProcess* next(void) const { 149 return _next; 150 } 151 152 int pid(void) const { 153 return _pid; 154 } 155 156 void set_pid(int pid) { 157 _pid = pid; 158 } 159 160 const char* name(void) const { 161 return _name; 162 } 163 164 void set_name(char* name) { 165 _name = name; 166 } 167 168 const char* path(void) const { 169 return _path; 170 } 171 172 void set_path(char* path) { 173 _path = path; 174 } 175 176 const char* command_line(void) const { 177 return _command_line; 178 } 179 180 void set_command_line(char* command_line) { 181 _command_line = command_line; 182 } 183 184 virtual ~SystemProcess(void) { 185 if (_name != NULL) { 186 FREE_C_HEAP_ARRAY(char, _name, mtInternal); 187 } 188 if (_path != NULL) { 189 FREE_C_HEAP_ARRAY(char, _path, mtInternal); 190 } 191 if (_command_line != NULL) { 192 FREE_C_HEAP_ARRAY(char, _command_line, mtInternal); 193 } 194 } 195 }; 196 197 class CPUInformationInterface : public CHeapObj<mtInternal> { 198 private: 199 CPUInformation* _cpu_info; 200 public: 201 CPUInformationInterface(); 202 bool initialize(); 203 ~CPUInformationInterface(); 204 int cpu_information(CPUInformation& cpu_info); 205 }; 206 207 class CPUPerformanceInterface : public CHeapObj<mtInternal> { 208 private: 209 class CPUPerformance; 210 CPUPerformance* _impl; 211 public: 212 CPUPerformanceInterface(); 213 ~CPUPerformanceInterface(); 214 bool initialize(); 215 216 int cpu_load(int which_logical_cpu, double* const cpu_load) const; 217 int context_switch_rate(double* const rate) const; 218 int cpu_load_total_process(double* const cpu_load) const; 219 int cpu_loads_process(double* const pjvmUserLoad, 220 double* const pjvmKernelLoad, 221 double* const psystemTotalLoad) const; 222 }; 223 224 class SystemProcessInterface : public CHeapObj<mtInternal> { 225 private: 226 class SystemProcesses; 227 SystemProcesses* _impl; 228 public: 229 SystemProcessInterface(); 230 ~SystemProcessInterface(); 231 bool initialize(); 232 233 // information about system processes 234 int system_processes(SystemProcess** system_procs, int* const no_of_sys_processes) const; 235 }; 236 237 #endif // SHARE_VM_RUNTIME_OS_PERF_HPP