Add elapsed_process_vtime

This commit is contained in:
Erik Österlund 2025-06-12 12:22:36 +02:00 committed by Jonas Norlinder
parent f9333a3603
commit 4eaa6e1f7e
3 changed files with 46 additions and 0 deletions

View File

@ -76,6 +76,7 @@
#include <sys/resource.h>
#include <sys/socket.h>
#include <spawn.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <sys/times.h>
#include <sys/types.h>
@ -1511,6 +1512,17 @@ jlong os::elapsed_frequency() {
bool os::supports_vtime() { return true; }
double os::elapsed_process_vtime() {
struct rusage usage;
int retval = getrusage(RUSAGE_SELF, &usage);
if (retval == 0) {
return usage.ru_utime.tv_sec + usage.ru_stime.tv_sec +
(usage.ru_utime.tv_usec + usage.ru_stime.tv_usec) / (1000.0 * 1000.0);
} else {
return -1;
}
}
// Return the real, user, and system times in seconds from an
// arbitrary fixed point in the past.
bool os::getTimesSecs(double* process_real_time,

View File

@ -1209,6 +1209,39 @@ double os::elapsedVTime() {
}
}
double os::elapsed_process_vtime() {
FILETIME create;
FILETIME exit;
FILETIME kernel;
FILETIME user;
if (GetProcessTimes(GetCurrentProcess(), &create, &exit, &kernel, &user) == 0) {
return -1;
}
SYSTEMTIME user_total;
if (FileTimeToSystemTime(&user, &user_total) == 0) {
return -1;
}
SYSTEMTIME kernel_total;
if (FileTimeToSystemTime(&kernel, &kernel_total) == 0) {
return -1;
}
double user_seconds =
double(user_total.wHour) * 3600.0 + double(user_total.wMinute) * 60.0 +
double(user_total.wSecond) + double(user_total.wMilliseconds) / 1000.0;
double kernel_seconds = double(kernel_total.wHour) * 3600.0 +
double(kernel_total.wMinute) * 60.0 +
double(kernel_total.wSecond) +
double(kernel_total.wMilliseconds) / 1000.0;
return user_seconds + kernel_seconds;
}
jlong os::javaTimeMillis() {
FILETIME wt;
GetSystemTimeAsFileTime(&wt);

View File

@ -299,6 +299,7 @@ class os: AllStatic {
// returns the elapsed virtual time for the current thread.
static bool supports_vtime();
static double elapsedVTime();
static double elapsed_process_vtime();
// Return current local time in a string (YYYY-MM-DD HH:MM:SS).
// It is MT safe, but not async-safe, as reading time zone