src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/os/linux/vm/os_linux.cpp	Thu Jul 16 15:07:36 2015
--- new/src/os/linux/vm/os_linux.cpp	Thu Jul 16 15:07:34 2015

*** 2041,2075 **** --- 2041,2131 ---- // distribution information and the system-release file seems to be an old // standard that has been replaced by the lsb-release and os-release files. // Searching for the debian_version file is the last resort. It contains // an informative string like "6.0.6" or "wheezy/sid". Because of this // "Debian " is printed before the contents of the debian_version file. void os::Linux::print_distro_info(outputStream* st) { if (!_print_ascii_file("/etc/oracle-release", st) && !_print_ascii_file("/etc/mandriva-release", st) && !_print_ascii_file("/etc/mandrake-release", st) && !_print_ascii_file("/etc/sun-release", st) && !_print_ascii_file("/etc/redhat-release", st) && !_print_ascii_file("/etc/lsb-release", st) && !_print_ascii_file("/etc/SuSE-release", st) && !_print_ascii_file("/etc/turbolinux-release", st) && !_print_ascii_file("/etc/gentoo-release", st) && !_print_ascii_file("/etc/ltib-release", st) && !_print_ascii_file("/etc/angstrom-version", st) && !_print_ascii_file("/etc/system-release", st) && !_print_ascii_file("/etc/os-release", st)) { + const char* distro_files[] = { + "/etc/oracle-release", + "/etc/mandriva-release", + "/etc/mandrake-release", + "/etc/sun-release", + "/etc/redhat-release", + "/etc/lsb-release", + "/etc/SuSE-release", + "/etc/turbolinux-release", + "/etc/gentoo-release", + "/etc/ltib-release", + "/etc/angstrom-version", + "/etc/system-release", + "/etc/os-release", + NULL }; + + void os::Linux::print_distro_info(outputStream* st) { + for (int i = 0;; i++) { + const char* file = distro_files[i]; + if (file == NULL) break; + // If file prints, we found it. + if (_print_ascii_file(file, st)) return; + } if (file_exists("/etc/debian_version")) { st->print("Debian "); _print_ascii_file("/etc/debian_version", st); } else { st->print("Linux"); } } st->cr(); } + static void parse_os_info(char* distro, size_t length, const char* file) { + FILE* fp = fopen(file, "r"); + if (fp != NULL) { + char buf[257]; + // get last line of the file. + while (!feof(fp)) { + fgets(buf, sizeof(buf), fp); + } + // Edit out ubuntu things + if (strstr(buf, "DISTRIB_DESCRIPTION=") != NULL) { + char* ptr = strstr(buf, "\""); + if (ptr != NULL) { + ptr++; // go beyond first " + char* nl = strchr(ptr, '\"'); + if (nl != NULL) *nl = '\0'; + strncpy(distro, ptr, length); + fclose(fp); + return; + } + } else { + // if not Ubuntu, print out whole line minus \n + char* nl = strchr(buf, '\n'); + if (nl != NULL) *nl = '\0'; + strncpy(distro, buf, length); + fclose(fp); + return; + } + } + } + + void os::get_summary_os_info(char* buf, size_t buflen) { + for (int i = 0;; i++) { + const char* file = distro_files[i]; + if (file == NULL) break; + if (file_exists(file)) { + parse_os_info(buf, buflen, file); + return; + } + } + // special case for debian + if (file_exists("/etc/debian_version")) { + strncpy(buf, "Debian ", buflen); + parse_os_info(&buf[7], buflen-7, "/etc/debian_version"); + } else { + strncpy(buf, "Linux", buflen); + } + } + void os::Linux::print_libversion_info(outputStream* st) { // libc, pthread st->print("libc:"); st->print("%s ", os::Linux::glibc_version()); st->print("%s ", os::Linux::libpthread_version());
*** 2148,2157 **** --- 2204,2254 ---- st->print_cr(" <Not Available>"); } } } + const char* search_string = IA32_ONLY("model name") AMD64_ONLY("model name") + IA64_ONLY("") SPARC_ONLY("cpu") + ARM32_ONLY("Processor") PPC_ONLY("Processor") AARCH64_ONLY("Processor"); + + // Parses the cpuinfo file for string representing the model name. + void os::get_summary_cpu_info(char* cpuinfo, size_t length) { + FILE* fp = fopen("/proc/cpuinfo", "r"); + if (fp != NULL) { + while (!feof(fp)) { + char buf[257]; + if (fgets(buf, sizeof(buf), fp)) { + char* start = strstr(buf, search_string); + if (start != NULL) { + char *ptr = start + strlen(search_string); + char *end = buf + strlen(buf); + while (ptr != end) { + // skip whitespace and colon for the rest of the name. + if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') { + break; + } + ptr++; + } + if (ptr != end) { + // reasonable string, get rid of newline and keep the rest + char* nl = strchr(buf, '\n'); + if (nl != NULL) *nl = '\0'; + strncpy(cpuinfo, ptr, length); + fclose(fp); + return; + } + } + } + } + } + // cpuinfo not found or parsing failed, just print generic string. The entire + // /proc/cpuinfo file will be printed later in the file (or enough of it for x86) + strncpy(cpuinfo, IA32_ONLY("x86 IA32") AMD64_ONLY("x86 IA64") + IA64_ONLY("IA64") SPARC_ONLY("sparcv9") + ARM32_ONLY("arm32") PPC_ONLY("PPC64") AARCH64_ONLY("AARCH64"), length); + } + void os::print_siginfo(outputStream* st, void* siginfo) { const siginfo_t* si = (const siginfo_t*)siginfo; os::Posix::print_siginfo_brief(st, si); #if INCLUDE_CDS

src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File