< prev index next >

src/hotspot/os/bsd/os_perf_bsd.cpp

Print this page
rev 57095 : [mq]: use
rev 57096 : [mq]: trailing_semi


   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 #include "precompiled.hpp"
  25 #include "memory/allocation.inline.hpp"
  26 #include "memory/resourceArea.hpp"
  27 #include "runtime/os.hpp"
  28 #include "runtime/os_perf.hpp"

  29 #include CPU_HEADER(vm_version_ext)
  30 
  31 #ifdef __APPLE__
  32   #import <libproc.h>
  33   #include <sys/time.h>
  34   #include <sys/sysctl.h>
  35   #include <mach/mach.h>
  36   #include <mach/task_info.h>
  37   #include <sys/socket.h>
  38   #include <net/if.h>
  39   #include <net/if_dl.h>
  40   #include <net/route.h>
  41 #endif
  42 
  43 static const double NANOS_PER_SEC = 1000000000.0;
  44 
  45 class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
  46    friend class CPUPerformanceInterface;
  47  private:
  48   long _total_cpu_nanos;


  55   int  _active_processor_count;
  56 
  57   bool now_in_nanos(long* resultp) {
  58     timeval current_time;
  59     if (gettimeofday(&current_time, NULL) != 0) {
  60       // Error getting current time
  61       return false;
  62     }
  63     *resultp = current_time.tv_sec * NANOS_PER_SEC + 1000L * current_time.tv_usec;
  64     return true;
  65   }
  66 
  67   double normalize(double value) {
  68     return MIN2<double>(MAX2<double>(value, 0.0), 1.0);
  69   }
  70   int cpu_load(int which_logical_cpu, double* cpu_load);
  71   int context_switch_rate(double* rate);
  72   int cpu_load_total_process(double* cpu_load);
  73   int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
  74 
  75   CPUPerformance(const CPUPerformance& rhs); // no impl
  76   CPUPerformance& operator=(const CPUPerformance& rhs); // no impl
  77  public:
  78   CPUPerformance();
  79   bool initialize();
  80   ~CPUPerformance();
  81 };
  82 
  83 CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
  84   _total_cpu_nanos= 0;
  85   _total_csr_nanos= 0;
  86   _jvm_context_switches = 0;
  87   _jvm_user_nanos = 0;
  88   _jvm_system_nanos = 0;
  89   _used_ticks = 0;
  90   _total_ticks = 0;
  91   _active_processor_count = 0;
  92 }
  93 
  94 bool CPUPerformanceInterface::CPUPerformance::initialize() {
  95   return true;
  96 }


 247   return _impl->cpu_load(which_logical_cpu, cpu_load);
 248 }
 249 
 250 int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
 251   return _impl->cpu_load_total_process(cpu_load);
 252 }
 253 
 254 int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
 255   return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
 256 }
 257 
 258 int CPUPerformanceInterface::context_switch_rate(double* rate) const {
 259   return _impl->context_switch_rate(rate);
 260 }
 261 
 262 class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
 263   friend class SystemProcessInterface;
 264  private:
 265   SystemProcesses();
 266   bool initialize();
 267   SystemProcesses(const SystemProcesses& rhs); // no impl
 268   SystemProcesses& operator=(const SystemProcesses& rhs); // no impl
 269   ~SystemProcesses();
 270 
 271   //information about system processes
 272   int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
 273 };
 274 
 275 SystemProcessInterface::SystemProcesses::SystemProcesses() {
 276 }
 277 
 278 bool SystemProcessInterface::SystemProcesses::initialize() {
 279   return true;
 280 }
 281 
 282 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
 283 }
 284 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
 285   assert(system_processes != NULL, "system_processes pointer is NULL!");
 286   assert(no_of_sys_processes != NULL, "system_processes counter pointer is NULL!");
 287 #ifdef __APPLE__
 288   pid_t* pids = NULL;


 390       FREE_C_HEAP_ARRAY(char, cpu_desc);
 391       _cpu_info->set_cpu_description(NULL);
 392     }
 393     delete _cpu_info;
 394   }
 395 }
 396 
 397 int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
 398   if (NULL == _cpu_info) {
 399     return OS_ERR;
 400   }
 401 
 402   cpu_info = *_cpu_info; // shallow copy assignment
 403   return OS_OK;
 404 }
 405 
 406 class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> {
 407   friend class NetworkPerformanceInterface;
 408  private:
 409   NetworkPerformance();
 410   NetworkPerformance(const NetworkPerformance& rhs); // no impl
 411   NetworkPerformance& operator=(const NetworkPerformance& rhs); // no impl
 412   bool initialize();
 413   ~NetworkPerformance();
 414   int network_utilization(NetworkInterface** network_interfaces) const;
 415 };
 416 
 417 NetworkPerformanceInterface::NetworkPerformance::NetworkPerformance() {
 418 }
 419 
 420 bool NetworkPerformanceInterface::NetworkPerformance::initialize() {
 421   return true;
 422 }
 423 
 424 NetworkPerformanceInterface::NetworkPerformance::~NetworkPerformance() {
 425 }
 426 
 427 int NetworkPerformanceInterface::NetworkPerformance::network_utilization(NetworkInterface** network_interfaces) const {
 428   size_t len;
 429   int mib[] = {CTL_NET, PF_ROUTE, /* protocol number */ 0, /* address family */ 0, NET_RT_IFLIST2, /* NET_RT_FLAGS mask*/ 0};
 430   if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &len, NULL, 0) != 0) {
 431     return OS_ERR;




   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 #include "precompiled.hpp"
  25 #include "memory/allocation.inline.hpp"
  26 #include "memory/resourceArea.hpp"
  27 #include "runtime/os.hpp"
  28 #include "runtime/os_perf.hpp"
  29 #include "utilities/macros.hpp"
  30 #include CPU_HEADER(vm_version_ext)
  31 
  32 #ifdef __APPLE__
  33   #import <libproc.h>
  34   #include <sys/time.h>
  35   #include <sys/sysctl.h>
  36   #include <mach/mach.h>
  37   #include <mach/task_info.h>
  38   #include <sys/socket.h>
  39   #include <net/if.h>
  40   #include <net/if_dl.h>
  41   #include <net/route.h>
  42 #endif
  43 
  44 static const double NANOS_PER_SEC = 1000000000.0;
  45 
  46 class CPUPerformanceInterface::CPUPerformance : public CHeapObj<mtInternal> {
  47    friend class CPUPerformanceInterface;
  48  private:
  49   long _total_cpu_nanos;


  56   int  _active_processor_count;
  57 
  58   bool now_in_nanos(long* resultp) {
  59     timeval current_time;
  60     if (gettimeofday(&current_time, NULL) != 0) {
  61       // Error getting current time
  62       return false;
  63     }
  64     *resultp = current_time.tv_sec * NANOS_PER_SEC + 1000L * current_time.tv_usec;
  65     return true;
  66   }
  67 
  68   double normalize(double value) {
  69     return MIN2<double>(MAX2<double>(value, 0.0), 1.0);
  70   }
  71   int cpu_load(int which_logical_cpu, double* cpu_load);
  72   int context_switch_rate(double* rate);
  73   int cpu_load_total_process(double* cpu_load);
  74   int cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad);
  75 
  76   NONCOPYABLE(CPUPerformance);
  77 
  78  public:
  79   CPUPerformance();
  80   bool initialize();
  81   ~CPUPerformance();
  82 };
  83 
  84 CPUPerformanceInterface::CPUPerformance::CPUPerformance() {
  85   _total_cpu_nanos= 0;
  86   _total_csr_nanos= 0;
  87   _jvm_context_switches = 0;
  88   _jvm_user_nanos = 0;
  89   _jvm_system_nanos = 0;
  90   _used_ticks = 0;
  91   _total_ticks = 0;
  92   _active_processor_count = 0;
  93 }
  94 
  95 bool CPUPerformanceInterface::CPUPerformance::initialize() {
  96   return true;
  97 }


 248   return _impl->cpu_load(which_logical_cpu, cpu_load);
 249 }
 250 
 251 int CPUPerformanceInterface::cpu_load_total_process(double* cpu_load) const {
 252   return _impl->cpu_load_total_process(cpu_load);
 253 }
 254 
 255 int CPUPerformanceInterface::cpu_loads_process(double* pjvmUserLoad, double* pjvmKernelLoad, double* psystemTotalLoad) const {
 256   return _impl->cpu_loads_process(pjvmUserLoad, pjvmKernelLoad, psystemTotalLoad);
 257 }
 258 
 259 int CPUPerformanceInterface::context_switch_rate(double* rate) const {
 260   return _impl->context_switch_rate(rate);
 261 }
 262 
 263 class SystemProcessInterface::SystemProcesses : public CHeapObj<mtInternal> {
 264   friend class SystemProcessInterface;
 265  private:
 266   SystemProcesses();
 267   bool initialize();
 268   NONCOPYABLE(SystemProcesses);

 269   ~SystemProcesses();
 270 
 271   //information about system processes
 272   int system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const;
 273 };
 274 
 275 SystemProcessInterface::SystemProcesses::SystemProcesses() {
 276 }
 277 
 278 bool SystemProcessInterface::SystemProcesses::initialize() {
 279   return true;
 280 }
 281 
 282 SystemProcessInterface::SystemProcesses::~SystemProcesses() {
 283 }
 284 int SystemProcessInterface::SystemProcesses::system_processes(SystemProcess** system_processes, int* no_of_sys_processes) const {
 285   assert(system_processes != NULL, "system_processes pointer is NULL!");
 286   assert(no_of_sys_processes != NULL, "system_processes counter pointer is NULL!");
 287 #ifdef __APPLE__
 288   pid_t* pids = NULL;


 390       FREE_C_HEAP_ARRAY(char, cpu_desc);
 391       _cpu_info->set_cpu_description(NULL);
 392     }
 393     delete _cpu_info;
 394   }
 395 }
 396 
 397 int CPUInformationInterface::cpu_information(CPUInformation& cpu_info) {
 398   if (NULL == _cpu_info) {
 399     return OS_ERR;
 400   }
 401 
 402   cpu_info = *_cpu_info; // shallow copy assignment
 403   return OS_OK;
 404 }
 405 
 406 class NetworkPerformanceInterface::NetworkPerformance : public CHeapObj<mtInternal> {
 407   friend class NetworkPerformanceInterface;
 408  private:
 409   NetworkPerformance();
 410   NONCOPYABLE(NetworkPerformance);

 411   bool initialize();
 412   ~NetworkPerformance();
 413   int network_utilization(NetworkInterface** network_interfaces) const;
 414 };
 415 
 416 NetworkPerformanceInterface::NetworkPerformance::NetworkPerformance() {
 417 }
 418 
 419 bool NetworkPerformanceInterface::NetworkPerformance::initialize() {
 420   return true;
 421 }
 422 
 423 NetworkPerformanceInterface::NetworkPerformance::~NetworkPerformance() {
 424 }
 425 
 426 int NetworkPerformanceInterface::NetworkPerformance::network_utilization(NetworkInterface** network_interfaces) const {
 427   size_t len;
 428   int mib[] = {CTL_NET, PF_ROUTE, /* protocol number */ 0, /* address family */ 0, NET_RT_IFLIST2, /* NET_RT_FLAGS mask*/ 0};
 429   if (sysctl(mib, sizeof(mib) / sizeof(mib[0]), NULL, &len, NULL, 0) != 0) {
 430     return OS_ERR;


< prev index next >