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