summaryrefslogtreecommitdiff
path: root/rts/Stats.c
diff options
context:
space:
mode:
Diffstat (limited to 'rts/Stats.c')
-rw-r--r--rts/Stats.c37
1 files changed, 21 insertions, 16 deletions
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(&current_cpu, &current_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(&current_cpu, &current_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