Sat, 05 Apr 2014 23:38:24 -0700
8026334: hs_err improvement: Print elapsed time in a humanly readable format
Reviewed-by: coleenp, dsamersoff
Contributed-by: masato.yoshida@oracle.com
src/share/vm/runtime/os.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/runtime/os.cpp Fri Apr 04 09:54:56 2014 -0700 1.2 +++ b/src/share/vm/runtime/os.cpp Sat Apr 05 23:38:24 2014 -0700 1.3 @@ -929,6 +929,10 @@ 1.4 } 1.5 1.6 void os::print_date_and_time(outputStream *st) { 1.7 + const int secs_per_day = 86400; 1.8 + const int secs_per_hour = 3600; 1.9 + const int secs_per_min = 60; 1.10 + 1.11 time_t tloc; 1.12 (void)time(&tloc); 1.13 st->print("time: %s", ctime(&tloc)); // ctime adds newline. 1.14 @@ -937,7 +941,17 @@ 1.15 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in 1.16 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int 1.17 // before printf. We lost some precision, but who cares? 1.18 - st->print_cr("elapsed time: %d seconds", (int)t); 1.19 + int eltime = (int)t; // elapsed time in seconds 1.20 + 1.21 + // print elapsed time in a human-readable format: 1.22 + int eldays = eltime / secs_per_day; 1.23 + int day_secs = eldays * secs_per_day; 1.24 + int elhours = (eltime - day_secs) / secs_per_hour; 1.25 + int hour_secs = elhours * secs_per_hour; 1.26 + int elmins = (eltime - day_secs - hour_secs) / secs_per_min; 1.27 + int minute_secs = elmins * secs_per_min; 1.28 + int elsecs = (eltime - day_secs - hour_secs - minute_secs); 1.29 + st->print_cr("elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs); 1.30 } 1.31 1.32 // moved from debug.cpp (used to be find()) but still called from there