diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2020-04-16 22:05:17 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2020-04-16 22:07:05 +0300 |
commit | ac81df303d29aa83cdc146f3433647360eb4deff (patch) | |
tree | 3d75bdf29dd8bda3a28399d643ff75b0a74a04e9 /alloc.c | |
parent | b193ce6d48edd03c152228979dec5612a71d7a81 (diff) | |
download | bdwgc-ac81df303d29aa83cdc146f3433647360eb4deff.tar.gz |
Take nanoseconds into account when updating full_gc_total_time
The fraction of time spent during GC is accumulated and
full_gc_total_time is incremented whenever the fraction exceeds
a millisecond.
* alloc.c [!NO_CLOCK] (full_gc_total_ns_frac): New static variable.
* alloc.c [!NO_CLOCK] (GC_try_to_collect_inner): Declare ns_frac_diff
local variable; update full_gc_total_ns_frac value; increment
full_gc_total_time on full_gc_total_ns_frac overflow.
Diffstat (limited to 'alloc.c')
-rw-r--r-- | alloc.c | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -70,6 +70,7 @@ word GC_gc_no = 0; #ifndef NO_CLOCK static unsigned long full_gc_total_time = 0; /* in ms, may wrap */ + static unsigned full_gc_total_ns_frac = 0; /* fraction of 1 ms */ static GC_bool measure_performance = FALSE; /* Do performance measurements if set to true (e.g., */ /* accumulation of the total time of full collections). */ @@ -590,15 +591,23 @@ GC_INNER GC_bool GC_try_to_collect_inner(GC_stop_func stop_func) # ifndef NO_CLOCK if (start_time_valid) { CLOCK_TYPE current_time; - unsigned long time_diff; + unsigned long time_diff, ns_frac_diff; GET_TIME(current_time); time_diff = MS_TIME_DIFF(current_time, start_time); - if (measure_performance) + ns_frac_diff = NS_FRAC_TIME_DIFF(current_time, start_time); + if (measure_performance) { full_gc_total_time += time_diff; /* may wrap */ + full_gc_total_ns_frac += (unsigned)ns_frac_diff; + if (full_gc_total_ns_frac >= 1000000U) { + /* Overflow of the nanoseconds part. */ + full_gc_total_ns_frac -= 1000000U; + full_gc_total_time++; + } + } if (GC_print_stats) - GC_log_printf("Complete collection took %lu ms %lu ns\n", time_diff, - NS_FRAC_TIME_DIFF(current_time, start_time)); + GC_log_printf("Complete collection took %lu ms %lu ns\n", + time_diff, ns_frac_diff); } # endif if (GC_on_collection_event) |