Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8240295: hs_err elapsed time in seconds is not accurate enough
Reviewed-by: dholmes, sspitsyn
  • Loading branch information
Kevin Walls committed Mar 9, 2020
1 parent 3ff8eff commit a11912ca0650e11c4b457c5e638d8a77d22e6659
Showing with 3 additions and 4 deletions.
  1. +3 −4 src/hotspot/share/runtime/os.cpp
@@ -1016,10 +1016,9 @@ void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
}

double t = os::elapsedTime();
// NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in
// Linux. Must be a bug in glibc ? Workaround is to round "t" to int
// before printf. We lost some precision, but who cares?
// NOTE: a crash using printf("%f",...) on Linux was historically noted here.
int eltime = (int)t; // elapsed time in seconds
int eltimeFraction = (int) ((t - eltime) * 1000000);

// print elapsed time in a human-readable format:
int eldays = eltime / secs_per_day;
@@ -1029,7 +1028,7 @@ void os::print_date_and_time(outputStream *st, char* buf, size_t buflen) {
int elmins = (eltime - day_secs - hour_secs) / secs_per_min;
int minute_secs = elmins * secs_per_min;
int elsecs = (eltime - day_secs - hour_secs - minute_secs);
st->print_cr(" elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs);
st->print_cr(" elapsed time: %d.%06d seconds (%dd %dh %dm %ds)", eltime, eltimeFraction, eldays, elhours, elmins, elsecs);
}


0 comments on commit a11912c

Please sign in to comment.