Mercurial > hg > graal-jvmci-8
comparison src/share/vm/runtime/os.cpp @ 17839:5cf196cc5405
8026334: hs_err improvement: Print elapsed time in a humanly readable format
Reviewed-by: coleenp, dsamersoff
Contributed-by: masato.yoshida@oracle.com
author | dbuck |
---|---|
date | Sat, 05 Apr 2014 23:38:24 -0700 |
parents | 752ba2e5f6d0 |
children | 7384f6a12fc1 |
comparison
equal
deleted
inserted
replaced
17838:eb82175e7fbb | 17839:5cf196cc5405 |
---|---|
927 st->cr(); | 927 st->cr(); |
928 pd_print_cpu_info(st); | 928 pd_print_cpu_info(st); |
929 } | 929 } |
930 | 930 |
931 void os::print_date_and_time(outputStream *st) { | 931 void os::print_date_and_time(outputStream *st) { |
932 const int secs_per_day = 86400; | |
933 const int secs_per_hour = 3600; | |
934 const int secs_per_min = 60; | |
935 | |
932 time_t tloc; | 936 time_t tloc; |
933 (void)time(&tloc); | 937 (void)time(&tloc); |
934 st->print("time: %s", ctime(&tloc)); // ctime adds newline. | 938 st->print("time: %s", ctime(&tloc)); // ctime adds newline. |
935 | 939 |
936 double t = os::elapsedTime(); | 940 double t = os::elapsedTime(); |
937 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in | 941 // NOTE: It tends to crash after a SEGV if we want to printf("%f",...) in |
938 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int | 942 // Linux. Must be a bug in glibc ? Workaround is to round "t" to int |
939 // before printf. We lost some precision, but who cares? | 943 // before printf. We lost some precision, but who cares? |
940 st->print_cr("elapsed time: %d seconds", (int)t); | 944 int eltime = (int)t; // elapsed time in seconds |
945 | |
946 // print elapsed time in a human-readable format: | |
947 int eldays = eltime / secs_per_day; | |
948 int day_secs = eldays * secs_per_day; | |
949 int elhours = (eltime - day_secs) / secs_per_hour; | |
950 int hour_secs = elhours * secs_per_hour; | |
951 int elmins = (eltime - day_secs - hour_secs) / secs_per_min; | |
952 int minute_secs = elmins * secs_per_min; | |
953 int elsecs = (eltime - day_secs - hour_secs - minute_secs); | |
954 st->print_cr("elapsed time: %d seconds (%dd %dh %dm %ds)", eltime, eldays, elhours, elmins, elsecs); | |
941 } | 955 } |
942 | 956 |
943 // moved from debug.cpp (used to be find()) but still called from there | 957 // moved from debug.cpp (used to be find()) but still called from there |
944 // The verbose parameter is only set by the debug code in one case | 958 // The verbose parameter is only set by the debug code in one case |
945 void os::print_location(outputStream* st, intptr_t x, bool verbose) { | 959 void os::print_location(outputStream* st, intptr_t x, bool verbose) { |