< prev index next >

src/hotspot/os/bsd/os_bsd.cpp

Print this page
rev 56978 : 8234397: add OS uptime information to os::print_os_info output


 152   return Bsd::available_memory();
 153 }
 154 
 155 // available here means free
 156 julong os::Bsd::available_memory() {
 157   uint64_t available = physical_memory() >> 2;
 158 #ifdef __APPLE__
 159   mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
 160   vm_statistics64_data_t vmstat;
 161   kern_return_t kerr = host_statistics64(mach_host_self(), HOST_VM_INFO64,
 162                                          (host_info64_t)&vmstat, &count);
 163   assert(kerr == KERN_SUCCESS,
 164          "host_statistics64 failed - check mach_host_self() and count");
 165   if (kerr == KERN_SUCCESS) {
 166     available = vmstat.free_count * os::vm_page_size();
 167   }
 168 #endif
 169   return available;
 170 }
 171 
















 172 julong os::physical_memory() {
 173   return Bsd::physical_memory();
 174 }
 175 
 176 // Return true if user is running as root.
 177 
 178 bool os::have_special_privileges() {
 179   static bool init = false;
 180   static bool privileges = false;
 181   if (!init) {
 182     privileges = (getuid() != geteuid()) || (getgid() != getegid());
 183     init = true;
 184   }
 185   return privileges;
 186 }
 187 
 188 
 189 
 190 // Cpu architecture string
 191 #if   defined(ZERO)


1552   }
1553 
1554   char release[100];
1555   size = sizeof(release);
1556   int mib_release[] = { CTL_KERN, KERN_OSRELEASE };
1557   if (sysctl(mib_release, 2, release, &size, NULL, 0) < 0) {
1558       // if error, leave blank
1559       strncpy(release, "", sizeof(release));
1560   }
1561   snprintf(buf, buflen, "%s %s", os, release);
1562 }
1563 
1564 void os::print_os_info_brief(outputStream* st) {
1565   os::Posix::print_uname_info(st);
1566 }
1567 
1568 void os::print_os_info(outputStream* st) {
1569   st->print("OS:");
1570 
1571   os::Posix::print_uname_info(st);


1572 
1573   os::Posix::print_rlimit_info(st);
1574 
1575   os::Posix::print_load_average(st);
1576 }
1577 
1578 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1579   // Nothing to do for now.
1580 }
1581 
1582 void os::get_summary_cpu_info(char* buf, size_t buflen) {
1583   unsigned int mhz;
1584   size_t size = sizeof(mhz);
1585   int mib[] = { CTL_HW, HW_CPU_FREQ };
1586   if (sysctl(mib, 2, &mhz, &size, NULL, 0) < 0) {
1587     mhz = 1;  // looks like an error but can be divided by
1588   } else {
1589     mhz /= 1000000;  // reported in millions
1590   }
1591 




 152   return Bsd::available_memory();
 153 }
 154 
 155 // available here means free
 156 julong os::Bsd::available_memory() {
 157   uint64_t available = physical_memory() >> 2;
 158 #ifdef __APPLE__
 159   mach_msg_type_number_t count = HOST_VM_INFO64_COUNT;
 160   vm_statistics64_data_t vmstat;
 161   kern_return_t kerr = host_statistics64(mach_host_self(), HOST_VM_INFO64,
 162                                          (host_info64_t)&vmstat, &count);
 163   assert(kerr == KERN_SUCCESS,
 164          "host_statistics64 failed - check mach_host_self() and count");
 165   if (kerr == KERN_SUCCESS) {
 166     available = vmstat.free_count * os::vm_page_size();
 167   }
 168 #endif
 169   return available;
 170 }
 171 
 172 // for more info see :
 173 // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/sysctl.3.html
 174 void os::Bsd::print_uptime_info(outputStream* st) {
 175   struct timeval boottime;
 176   size_t len = sizeof(boottime);
 177   int mib[2];
 178   mib[0] = CTL_KERN;
 179   mib[1] = KERN_BOOTTIME;
 180 
 181   if (sysctl(mib, 2, &boottime, &len, NULL, 0) >= 0) {
 182     time_t bootsec = boottime.tv_sec, currsec = time(NULL);
 183     double tdiff = difftime(currsec, bootsec);
 184     st->print_cr("OS uptime (in days): %.2lf", tdiff/(60.0*60.0*24.0));
 185   }
 186 }
 187 
 188 julong os::physical_memory() {
 189   return Bsd::physical_memory();
 190 }
 191 
 192 // Return true if user is running as root.
 193 
 194 bool os::have_special_privileges() {
 195   static bool init = false;
 196   static bool privileges = false;
 197   if (!init) {
 198     privileges = (getuid() != geteuid()) || (getgid() != getegid());
 199     init = true;
 200   }
 201   return privileges;
 202 }
 203 
 204 
 205 
 206 // Cpu architecture string
 207 #if   defined(ZERO)


1568   }
1569 
1570   char release[100];
1571   size = sizeof(release);
1572   int mib_release[] = { CTL_KERN, KERN_OSRELEASE };
1573   if (sysctl(mib_release, 2, release, &size, NULL, 0) < 0) {
1574       // if error, leave blank
1575       strncpy(release, "", sizeof(release));
1576   }
1577   snprintf(buf, buflen, "%s %s", os, release);
1578 }
1579 
1580 void os::print_os_info_brief(outputStream* st) {
1581   os::Posix::print_uname_info(st);
1582 }
1583 
1584 void os::print_os_info(outputStream* st) {
1585   st->print("OS:");
1586 
1587   os::Posix::print_uname_info(st);
1588 
1589   os::Bsd::print_uptime_info(st);
1590 
1591   os::Posix::print_rlimit_info(st);
1592 
1593   os::Posix::print_load_average(st);
1594 }
1595 
1596 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
1597   // Nothing to do for now.
1598 }
1599 
1600 void os::get_summary_cpu_info(char* buf, size_t buflen) {
1601   unsigned int mhz;
1602   size_t size = sizeof(mhz);
1603   int mib[] = { CTL_HW, HW_CPU_FREQ };
1604   if (sysctl(mib, 2, &mhz, &size, NULL, 0) < 0) {
1605     mhz = 1;  // looks like an error but can be divided by
1606   } else {
1607     mhz /= 1000000;  // reported in millions
1608   }
1609 


< prev index next >