From d9f0c24dd01b2f2a9a5ccc2fc45e93064d4ba0c1 Mon Sep 17 00:00:00 2001 From: Douglas Wilson Date: Wed, 15 Nov 2017 11:40:54 -0500 Subject: rts: Fix gc timing We were accumulating the gc times of the previous gc. `stats.gc.{cpu,elappsed}_ns` were being accumulated into `stats.gc_{cpu,elapsed}_ns` before they were set. There is also a change in that heap profiling will no longer cause gc events to be emitted. Reviewers: bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie GHC Trac Issues: #14257, #14445 Differential Revision: https://phabricator.haskell.org/D4184 --- rts/Stats.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'rts/Stats.c') diff --git a/rts/Stats.c b/rts/Stats.c index 6a5f80130e..8f7865bfc0 100644 --- a/rts/Stats.c +++ b/rts/Stats.c @@ -310,6 +310,26 @@ stat_endGC (Capability *cap, gc_thread *gct, stats.gc.par_max_copied_bytes = par_max_copied * sizeof(W_); stats.gc.par_balanced_copied_bytes = par_balanced_copied * sizeof(W_); + bool stats_enabled = + RtsFlags.GcFlags.giveStats != NO_GC_STATS || + rtsConfig.gcDoneHook != NULL; + + if (stats_enabled + || RtsFlags.ProfFlags.doHeapProfile) // heap profiling needs GC_tot_time + { + // We only update the times when stats are explicitly enabled since + // getProcessTimes (e.g. requiring a system call) can be expensive on + // some platforms. + Time current_cpu, current_elapsed; + getProcessTimes(¤t_cpu, ¤t_elapsed); + stats.cpu_ns = current_cpu - start_init_cpu; + stats.elapsed_ns = current_elapsed - start_init_elapsed; + + stats.gc.sync_elapsed_ns = + gct->gc_start_elapsed - gct->gc_sync_start_elapsed; + stats.gc.elapsed_ns = current_elapsed - gct->gc_start_elapsed; + stats.gc.cpu_ns = current_cpu - gct->gc_start_cpu; + } // ------------------------------------------------- // Update the cumulative stats @@ -354,23 +374,8 @@ stat_endGC (Capability *cap, gc_thread *gct, // ------------------------------------------------- // Do the more expensive bits only when stats are enabled. - if (RtsFlags.GcFlags.giveStats != NO_GC_STATS || - rtsConfig.gcDoneHook != NULL || - RtsFlags.ProfFlags.doHeapProfile) // heap profiling needs GC_tot_time + if (stats_enabled) { - // We only update the times when stats are explicitly enabled since - // getProcessTimes (e.g. requiring a system call) can be expensive on - // some platforms. - Time current_cpu, current_elapsed; - getProcessTimes(¤t_cpu, ¤t_elapsed); - stats.cpu_ns = current_cpu - start_init_cpu; - stats.elapsed_ns = current_elapsed - start_init_elapsed; - - stats.gc.sync_elapsed_ns = - gct->gc_start_elapsed - gct->gc_sync_start_elapsed; - stats.gc.elapsed_ns = current_elapsed - gct->gc_start_elapsed; - stats.gc.cpu_ns = current_cpu - gct->gc_start_cpu; - // ------------------------------------------------- // Emit events to the event log -- cgit v1.2.1