# HG changeset patch # Parent 8a780857650f894b9bf7228b9b8fb5e698901509 # User tschatzl diff -r 8a780857650f src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp Fri Aug 05 13:13:43 2016 +0200 +++ b/src/os/linux/vm/os_linux.cpp Fri Aug 05 15:10:34 2016 +0200 @@ -799,6 +799,76 @@ return true; } +static bool parse_cpu_times(char* fname, double* user_time, double* system_time) { +#define BUF_LENGTH 10 * 1024 +#define UTIME_ENTRY (14 - 2 /* we skip until after the thread name */) + int fd = ::open(fname, O_RDONLY); + if (fd == -1) { + return false; + } + + char buf[BUF_LENGTH]; + // read in whole file data + int n = ::read(fd, buf, BUF_LENGTH); + if (n < 0) { + ::close(fd); + return false; + } + // assume that we read the whole file; safety NUL character + buf[n-1] = '\0'; + + char *token; + char *str = index(buf, ')') + 2; + char * saveptr; + + for (int i = 0; i < UTIME_ENTRY - 1; ++i, str = NULL) { + token = strtok_r(str, " ", &saveptr); + if (token == NULL) { + ::close(fd); + return false; + } + } + + token = strtok_r(str, " ", &saveptr); + unsigned long utime = atol(token); + token = strtok_r(str, " ", &saveptr); + unsigned long stime = atol(token); + + long clock_tics_per_sec = sysconf(_SC_CLK_TCK); + + *user_time = (double)utime / clock_tics_per_sec; + *system_time = (double)stime / clock_tics_per_sec; + + ::close(fd); + + return true; +#undef BUF_LENGTH +#undef UTIME_ENTRY +} + +bool os::get_process_cpu_times(double* user_time, double* system_time) { +#define BUF_LENGTH 1 * 1024 + // get name of the file we need to parse + char fname[BUF_LENGTH]; + snprintf(fname, BUF_LENGTH, "/proc/%d/stat", getpid()); + + return parse_cpu_times(fname, user_time, system_time); +#undef BUF_LENGTH +} + +bool os::get_thread_cpu_times(const Thread* t, double* user_time, double* system_time) { +#define BUF_LENGTH 1 * 1024 + if (t == NULL) { + return false; + } + // get name of the file we need to parse + char fname[BUF_LENGTH]; + snprintf(fname, BUF_LENGTH, "/proc/%d/task/%d/stat", getpid(), t->osthread()->thread_id()); + + return parse_cpu_times(fname, user_time, system_time); +#undef BUF_LENGTH +} + ///////////////////////////////////////////////////////////////////////////// // attach existing thread diff -r 8a780857650f src/share/vm/runtime/os.hpp --- a/src/share/vm/runtime/os.hpp Fri Aug 05 13:13:43 2016 +0200 +++ b/src/share/vm/runtime/os.hpp Fri Aug 05 15:10:34 2016 +0200 @@ -453,6 +453,9 @@ static void initialize_thread(Thread* thr); static void free_thread(OSThread* osthread); + static bool get_process_cpu_times(double* user_time, double* system_time); + static bool get_thread_cpu_times(const Thread* t, double* user_time, double* system_time); + // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit static intx current_thread_id(); static int current_process_id(); diff -r 8a780857650f src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Fri Aug 05 13:13:43 2016 +0200 +++ b/src/share/vm/runtime/thread.cpp Fri Aug 05 15:10:34 2016 +0200 @@ -810,6 +810,11 @@ } st->print("tid=" INTPTR_FORMAT " ", p2i(this)); ext().print_on(st); + double user_time; + double system_time; + if (os::get_thread_cpu_times(this, &user_time, &system_time)) { + st->print("user=%1.3f sys=%1.3f ", user_time, system_time); + } osthread()->print_on(st); } debug_only(if (WizardMode) print_owned_locks_on(st);) @@ -4101,6 +4106,14 @@ bool Threads::destroy_vm() { JavaThread* thread = JavaThread::current(); + if (UseNewCode) { + double user; + double sys; + os::get_process_cpu_times(&user, &sys); + tty->print_cr("VM time user=%1.3f sys=%1.3f", user, sys); + Threads::print_on(tty, false, false, false); + } + #ifdef ASSERT _vm_complete = false; #endif diff -r 8a780857650f src/share/vm/runtime/vm_operations.cpp --- a/src/share/vm/runtime/vm_operations.cpp Fri Aug 05 13:13:43 2016 +0200 +++ b/src/share/vm/runtime/vm_operations.cpp Fri Aug 05 15:10:34 2016 +0200 @@ -455,6 +455,14 @@ } void VM_Exit::doit() { + if (UseNewCode) { + double user; + double sys; + os::get_process_cpu_times(&user, &sys); + tty->print_cr("VM time user=%1.3f sys=%1.3f", user, sys); + Threads::print_on(tty, false, false, false); + } + CompileBroker::set_should_block(); // Wait for a short period for threads in native to block. Any thread