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   NetworkInterface(); // no impl
194   NetworkInterface(const NetworkInterface& rhs); // no impl
195   NetworkInterface& operator=(const NetworkInterface& rhs); // no impl
196  public:
197   NetworkInterface(const char* name, uint64_t bytes_in, uint64_t bytes_out, NetworkInterface* next) :
198   _name(NULL),
199   _bytes_in(bytes_in),
200   _bytes_out(bytes_out),
201   _next(next) {
202     assert(name != NULL, "invariant");
203     const size_t length = strlen(name);
204     assert(allocated_on_res_area(), "invariant");
205     _name = NEW_RESOURCE_ARRAY(char, length + 1);
206     strncpy(_name, name, length + 1);
207     assert(strncmp(_name, name, length) == 0, "invariant");
208   }
209 
210   NetworkInterface* next() const {
211     return _next;
212   }
213 
214   const char* get_name() const {
215     return _name;
216   }
217 
218   uint64_t get_bytes_out() const {
219     return _bytes_out;
220   }
221 
222   uint64_t get_bytes_in() const {
223     return _bytes_in;
224   }
225 };
226 
227 class CPUInformationInterface : public CHeapObj<mtInternal> {
228  private:
229   CPUInformation* _cpu_info;
230  public:
231   CPUInformationInterface();
232   bool initialize();
233   ~CPUInformationInterface();
234   int cpu_information(CPUInformation& cpu_info);
235 };
236 
237 class CPUPerformanceInterface : public CHeapObj<mtInternal> {
238  private:
239   class CPUPerformance;
240   CPUPerformance* _impl;
241  public:
242   CPUPerformanceInterface();
243   ~CPUPerformanceInterface();
244   bool initialize();
245 
246   int cpu_load(int which_logical_cpu, double* const cpu_load) const;
247   int context_switch_rate(double* const rate) const;
248   int cpu_load_total_process(double* const cpu_load) const;
249   int cpu_loads_process(double* const pjvmUserLoad,
250                         double* const pjvmKernelLoad,
251                         double* const psystemTotalLoad) const;
252 };
253 
254 class SystemProcessInterface : public CHeapObj<mtInternal> {
255  private:
256    class SystemProcesses;
257    SystemProcesses* _impl;
258  public:
259    SystemProcessInterface();
260    ~SystemProcessInterface();
261    bool initialize();
262 
263   // information about system processes
264   int system_processes(SystemProcess** system_procs, int* const no_of_sys_processes) const;
265 };
266 
267 class NetworkPerformanceInterface : public CHeapObj<mtInternal> {
268  private:
269   class NetworkPerformance;
270   NetworkPerformance* _impl;
271   NetworkPerformanceInterface(const NetworkPerformanceInterface& rhs); // no impl
272   NetworkPerformanceInterface& operator=(const NetworkPerformanceInterface& rhs); // no impl
273  public:
274   NetworkPerformanceInterface();
275   bool initialize();
276   ~NetworkPerformanceInterface();
277   int network_utilization(NetworkInterface** network_interfaces) const;
278 };
279 
280 #endif // SHARE_RUNTIME_OS_PERF_HPP
--- EOF ---