Skip to content

Commit db6bfe4

Browse files
committed
Follow new naming in GHC.Stats. Fixes #29.
GHC commit 24e6594cc7890babe69b8ba122d171affabad2d1 changed a lot of the stats names. Until now, EKG stuck to the old names, which can be very confusing; especially since some names were clearly misleading and have been renamed in GHC consequentially. This commit changes all names to the new names. For base < 4.10, we translate the old API to their new equivalents (multiplying to get nanoseconds as needed). The added comment documents this translation. The change has been tested on Stackage versions: * lts-14.27 (GHC 8.6.5) * nightly-2018-11-08 (GHC 8.6.1) * lts-12.17 (GHC 8.4.4) * lts-9.21 (ghc-8.0.2) -- this is base 4.9 This change may break some users that rely on the old names, so a new major release should be made.
1 parent f3e7d15 commit db6bfe4

File tree

1 file changed

+114
-110
lines changed

1 file changed

+114
-110
lines changed

Diff for: System/Metrics.hs

+114-110
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,10 @@ createDistribution name store = do
332332
-- function.
333333

334334
#if MIN_VERSION_base(4,10,0)
335-
-- | Convert nanoseconds to milliseconds.
336-
nsToMs :: Int64 -> Int64
337-
nsToMs s = round (realToFrac s / (1000000.0 :: Double))
338335
#else
339-
-- | Convert seconds to milliseconds.
340-
sToMs :: Double -> Int64
341-
sToMs s = round (s * 1000.0)
336+
-- | Convert seconds to nanoseconds.
337+
sToNs :: Double -> Int64
338+
sToNs s = round (s * 1000000000.0)
342339
#endif
343340

344341
-- | Register a number of metrics related to garbage collector
@@ -355,121 +352,128 @@ sToMs s = round (s * 1000.0)
355352
-- The runtime overhead of @-T@ is very small so it's safe to always
356353
-- leave it enabled.
357354
--
358-
-- Registered counters:
359-
--
360-
-- [@rts.gc.bytes_allocated@] Total number of bytes allocated
361-
--
362-
-- [@rts.gc.num_gcs@] Number of garbage collections performed
363-
--
364-
-- [@rts.gc.num_bytes_usage_samples@] Number of byte usage samples taken
365-
--
366-
-- [@rts.gc.cumulative_bytes_used@] Sum of all byte usage samples, can be
367-
-- used with @numByteUsageSamples@ to calculate averages with
368-
-- arbitrary weighting (if you are sampling this record multiple
369-
-- times).
370-
--
371-
-- [@rts.gc.bytes_copied@] Number of bytes copied during GC
372-
--
373-
-- [@rts.gc.init_cpu_ms@] CPU time used by the init phase, in
374-
-- milliseconds. GHC 8.6+ only.
375-
--
376-
-- [@rts.gc.init_wall_ms@] Wall clock time spent running the init
377-
-- phase, in milliseconds. GHC 8.6+ only.
378-
--
379-
-- [@rts.gc.mutator_cpu_ms@] CPU time spent running mutator threads,
380-
-- in milliseconds. This does not include any profiling overhead or
381-
-- initialization.
382-
--
383-
-- [@rts.gc.mutator_wall_ms@] Wall clock time spent running mutator
384-
-- threads, in milliseconds. This does not include initialization.
385-
--
386-
-- [@rts.gc.gc_cpu_ms@] CPU time spent running GC, in milliseconds.
387-
--
388-
-- [@rts.gc.gc_wall_ms@] Wall clock time spent running GC, in
389-
-- milliseconds.
390-
--
391-
-- [@rts.gc.cpu_ms@] Total CPU time elapsed since program start, in
392-
-- milliseconds.
393-
--
394-
-- [@rts.gc.wall_ms@] Total wall clock time elapsed since start, in
395-
-- milliseconds.
396-
--
397-
-- Registered gauges:
398-
--
399-
-- [@rts.gc.max_bytes_used@] Maximum number of live bytes seen so far
400-
--
401-
-- [@rts.gc.current_bytes_used@] Current number of live bytes
402-
--
403-
-- [@rts.gc.current_bytes_slop@] Current number of bytes lost to slop
404-
--
405-
-- [@rts.gc.max_bytes_slop@] Maximum number of bytes lost to slop at any one time so far
406-
--
407-
-- [@rts.gc.peak_megabytes_allocated@] Maximum number of megabytes allocated
408-
--
409-
-- [@rts.gc.par_tot_bytes_copied@] Number of bytes copied during GC, minus
410-
-- space held by mutable lists held by the capabilities. Can be used
411-
-- with 'parMaxBytesCopied' to determine how well parallel GC utilized
412-
-- all cores.
413-
--
414-
-- [@rts.gc.par_avg_bytes_copied@] Deprecated alias for
415-
-- @par_tot_bytes_copied@.
416-
--
417-
-- [@rts.gc.par_max_bytes_copied@] Sum of number of bytes copied each GC by
418-
-- the most active GC thread each GC. The ratio of
419-
-- @par_tot_bytes_copied@ divided by @par_max_bytes_copied@ approaches
420-
-- 1 for a maximally sequential run and approaches the number of
421-
-- threads (set by the RTS flag @-N@) for a maximally parallel run.
355+
-- Registered counters (see also "GHC.Stats"):
356+
--
357+
-- > [@rts.gcs@] - Total number of GCs
358+
-- > [@rts.major_gcs@] - Total number of major (oldest generation) GCs
359+
-- > [@rts.allocated_bytes@] - Total bytes allocated
360+
-- > [@rts.max_live_bytes@] - Maximum live data (including large objects + compact regions) in the heap. Updated after a major GC.
361+
-- > [@rts.max_large_objects_bytes@] - Maximum live data in large objects
362+
-- > [@rts.max_compact_bytes@] - Maximum live data in compact regions
363+
-- > [@rts.max_slop_bytes@] - Maximum slop
364+
-- > [@rts.max_mem_in_use_bytes@] - Maximum memory in use by the RTS
365+
-- > [@rts.cumulative_live_bytes@] - Sum of live bytes across all major GCs. Divided by major_gcs gives the average live data over the lifetime of the program.
366+
-- > [@rts.copied_bytes@] - Sum of copied_bytes across all GCs
367+
-- > [@rts.par_copied_bytes@] - Sum of copied_bytes across all parallel GCs
368+
-- > [@rts.cumulative_par_max_copied_bytes@] - Sum of par_max_copied_bytes across all parallel GCs. Deprecated.
369+
-- > [@rts.cumulative_par_balanced_copied_bytes@] - Sum of par_balanced_copied bytes across all parallel GCs
370+
-- > [@rts.init_cpu_ns@] - Total CPU time used by the init phase @since 4.12.0.0
371+
-- > [@rts.init_elapsed_ns@] - Total elapsed time used by the init phase @since 4.12.0.0
372+
-- > [@rts.mutator_cpu_ns@] - Total CPU time used by the mutator
373+
-- > [@rts.mutator_elapsed_ns@] - Total elapsed time used by the mutator
374+
-- > [@rts.gc_cpu_ns@] - Total CPU time used by the GC
375+
-- > [@rts.gc_elapsed_ns@] - Total elapsed time used by the GC
376+
-- > [@rts.cpu_ns@] - Total CPU time (at the previous GC)
377+
-- > [@rts.elapsed_ns@] - Total elapsed time (at the previous GC)
378+
-- > [@rts.gc.gen@] - The generation number of this GC
379+
-- > [@rts.gc.threads@] - Number of threads used in this GC
380+
-- > [@rts.gc.allocated_bytes@] - Number of bytes allocated since the previous GC
381+
-- > [@rts.gc.live_bytes@] - Total amount of live data in the heap (incliudes large + compact data). Updated after every GC. Data in uncollected generations (in minor GCs) are considered live.
382+
-- > [@rts.gc.large_objects_bytes@] - Total amount of live data in large objects
383+
-- > [@rts.gc.compact_bytes@] - Total amount of live data in compact regions
384+
-- > [@rts.gc.slop_bytes@] - Total amount of slop (wasted memory)
385+
-- > [@rts.gc.mem_in_use_bytes@] - Total amount of memory in use by the RTS
386+
-- > [@rts.gc.copied_bytes@] - Total amount of data copied during this GC
387+
-- > [@rts.gc.par_max_copied_bytes@] - In parallel GC, the max amount of data copied by any one thread. Deprecated.
388+
-- > [@rts.gc.sync_elapsed_ns@] - The time elapsed during synchronisation before GC
389+
-- > [@rts.gc.cpu_ns@] - The CPU time used during GC itself
390+
-- > [@rts.gc.elapsed_ns@] - The time elapsed during GC itself
422391
registerGcMetrics :: Store -> IO ()
423392
registerGcMetrics store =
424393
registerGroup
425394
#if MIN_VERSION_base(4,10,0)
426395
(M.fromList
427-
[ ("rts.gc.bytes_allocated" , Counter . fromIntegral . Stats.allocated_bytes)
428-
, ("rts.gc.num_gcs" , Counter . fromIntegral . Stats.gcs)
429-
, ("rts.gc.num_bytes_usage_samples" , Counter . fromIntegral . Stats.major_gcs)
430-
, ("rts.gc.cumulative_bytes_used" , Counter . fromIntegral . Stats.cumulative_live_bytes)
431-
, ("rts.gc.bytes_copied" , Counter . fromIntegral . Stats.copied_bytes)
396+
-- We order them the same way as they are in GHC.Stats for easy comparison.
397+
[ ("rts.gcs" , Counter . fromIntegral . Stats.gcs)
398+
, ("rts.major_gcs" , Counter . fromIntegral . Stats.major_gcs)
399+
, ("rts.allocated_bytes" , Counter . fromIntegral . Stats.allocated_bytes)
400+
, ("rts.max_live_bytes" , Gauge . fromIntegral . Stats.max_live_bytes)
401+
, ("rts.max_large_objects_bytes" , Gauge . fromIntegral . Stats.max_large_objects_bytes)
402+
, ("rts.max_compact_bytes" , Gauge . fromIntegral . Stats.max_compact_bytes)
403+
, ("rts.max_slop_bytes" , Gauge . fromIntegral . Stats.max_slop_bytes)
404+
, ("rts.max_mem_in_use_bytes" , Gauge . fromIntegral . Stats.max_mem_in_use_bytes)
405+
, ("rts.cumulative_live_bytes" , Counter . fromIntegral . Stats.cumulative_live_bytes)
406+
, ("rts.copied_bytes" , Counter . fromIntegral . Stats.copied_bytes)
407+
, ("rts.par_copied_bytes" , Gauge . fromIntegral . Stats.par_copied_bytes)
408+
, ("rts.cumulative_par_max_copied_bytes" , Gauge . fromIntegral . Stats.cumulative_par_max_copied_bytes)
409+
#if MIN_VERSION_base(4,11,0)
410+
, ("rts.cumulative_par_balanced_copied_bytes" , Gauge . fromIntegral . Stats.cumulative_par_balanced_copied_bytes)
411+
#endif
432412
#if MIN_VERSION_base(4,12,0)
433-
, ("rts.gc.init_cpu_ms" , Counter . nsToMs . Stats.init_cpu_ns)
434-
, ("rts.gc.init_wall_ms" , Counter . nsToMs . Stats.init_elapsed_ns)
413+
, ("rts.init_cpu_ns" , Counter . Stats.init_cpu_ns)
414+
, ("rts.init_elapsed_ns" , Counter . Stats.init_elapsed_ns)
415+
#endif
416+
, ("rts.mutator_cpu_ns" , Counter . Stats.mutator_cpu_ns)
417+
, ("rts.mutator_elapsed_ns" , Counter . Stats.mutator_elapsed_ns)
418+
, ("rts.gc_cpu_ns" , Counter . Stats.gc_cpu_ns)
419+
, ("rts.gc_elapsed_ns" , Counter . Stats.gc_elapsed_ns)
420+
, ("rts.cpu_ns" , Counter . Stats.cpu_ns)
421+
, ("rts.elapsed_ns" , Counter . Stats.elapsed_ns)
422+
-- GCDetails
423+
, ("rts.gc.gen" , Gauge . fromIntegral . Stats.gcdetails_gen . Stats.gc)
424+
, ("rts.gc.threads" , Gauge . fromIntegral . Stats.gcdetails_threads . Stats.gc)
425+
, ("rts.gc.allocated_bytes" , Gauge . fromIntegral . Stats.gcdetails_allocated_bytes . Stats.gc)
426+
, ("rts.gc.live_bytes" , Gauge . fromIntegral . Stats.gcdetails_live_bytes . Stats.gc)
427+
, ("rts.gc.large_objects_bytes" , Gauge . fromIntegral . Stats.gcdetails_large_objects_bytes . Stats.gc)
428+
, ("rts.gc.compact_bytes" , Gauge . fromIntegral . Stats.gcdetails_compact_bytes . Stats.gc)
429+
, ("rts.gc.slop_bytes" , Gauge . fromIntegral . Stats.gcdetails_slop_bytes . Stats.gc)
430+
, ("rts.gc.mem_in_use_bytes" , Gauge . fromIntegral . Stats.gcdetails_mem_in_use_bytes . Stats.gc)
431+
, ("rts.gc.copied_bytes" , Gauge . fromIntegral . Stats.gcdetails_copied_bytes . Stats.gc)
432+
, ("rts.gc.par_max_copied_bytes" , Gauge . fromIntegral . Stats.gcdetails_par_max_copied_bytes . Stats.gc)
433+
#if MIN_VERSION_base(4,11,0)
434+
, ("rts.gc.gcdetails_par_balanced_copied_bytes" , Gauge . fromIntegral . Stats.gcdetails_par_balanced_copied_bytes . Stats.gc)
435435
#endif
436-
, ("rts.gc.mutator_cpu_ms" , Counter . nsToMs . Stats.mutator_cpu_ns)
437-
, ("rts.gc.mutator_wall_ms" , Counter . nsToMs . Stats.mutator_elapsed_ns)
438-
, ("rts.gc.gc_cpu_ms" , Counter . nsToMs . Stats.gc_cpu_ns)
439-
, ("rts.gc.gc_wall_ms" , Counter . nsToMs . Stats.gc_elapsed_ns)
440-
, ("rts.gc.cpu_ms" , Counter . nsToMs . Stats.cpu_ns)
441-
, ("rts.gc.wall_ms" , Counter . nsToMs . Stats.elapsed_ns)
442-
, ("rts.gc.max_bytes_used" , Gauge . fromIntegral . Stats.max_live_bytes)
443-
, ("rts.gc.current_bytes_used" , Gauge . fromIntegral . Stats.gcdetails_live_bytes . Stats.gc)
444-
, ("rts.gc.current_bytes_slop" , Gauge . fromIntegral . Stats.gcdetails_slop_bytes . Stats.gc)
445-
, ("rts.gc.max_bytes_slop" , Gauge . fromIntegral . Stats.max_slop_bytes)
446-
, ("rts.gc.peak_megabytes_allocated" , Gauge . fromIntegral . (`quot` (1024*1024)) . Stats.max_mem_in_use_bytes)
447-
, ("rts.gc.par_tot_bytes_copied" , Gauge . fromIntegral . Stats.par_copied_bytes)
448-
, ("rts.gc.par_avg_bytes_copied" , Gauge . fromIntegral . Stats.par_copied_bytes)
449-
, ("rts.gc.par_max_bytes_copied" , Gauge . fromIntegral . Stats.cumulative_par_max_copied_bytes)
436+
, ("rts.gc.sync_elapsed_ns" , Gauge . fromIntegral . Stats.gcdetails_sync_elapsed_ns . Stats.gc)
437+
, ("rts.gc.cpu_ns" , Gauge . fromIntegral . Stats.gcdetails_cpu_ns . Stats.gc)
438+
, ("rts.gc.elapsed_ns" , Gauge . fromIntegral . Stats.gcdetails_elapsed_ns . Stats.gc)
450439
])
451440
getRTSStats
452441
#else
442+
-- For pre-base-4.10 we translate the names from before GHC commit
443+
-- 24e6594cc7890babe69b8ba122d171affabad2d1 to their newer equivalents
444+
-- so that ekg-core always presents the same names (given that e.g.
445+
-- the ekg Javascript expects them to exist).
446+
-- The mapping is obtained obtained from
447+
-- https://hackage.haskell.org/package/base-4.10.0.0/docs/GHC-Stats.html
448+
-- which has both the old and the new interface, as well as from
449+
-- the commit diff implementation in `Stats.c`.
453450
(M.fromList
454-
[ ("rts.gc.bytes_allocated" , Counter . Stats.bytesAllocated)
455-
, ("rts.gc.num_gcs" , Counter . Stats.numGcs)
456-
, ("rts.gc.num_bytes_usage_samples" , Counter . Stats.numByteUsageSamples)
457-
, ("rts.gc.cumulative_bytes_used" , Counter . Stats.cumulativeBytesUsed)
458-
, ("rts.gc.bytes_copied" , Counter . Stats.bytesCopied)
459-
, ("rts.gc.mutator_cpu_ms" , Counter . sToMs . Stats.mutatorCpuSeconds)
460-
, ("rts.gc.mutator_wall_ms" , Counter . sToMs . Stats.mutatorWallSeconds)
461-
, ("rts.gc.gc_cpu_ms" , Counter . sToMs . Stats.gcCpuSeconds)
462-
, ("rts.gc.gc_wall_ms" , Counter . sToMs . Stats.gcWallSeconds)
463-
, ("rts.gc.cpu_ms" , Counter . sToMs . Stats.cpuSeconds)
464-
, ("rts.gc.wall_ms" , Counter . sToMs . Stats.wallSeconds)
465-
, ("rts.gc.max_bytes_used" , Gauge . Stats.maxBytesUsed)
466-
, ("rts.gc.current_bytes_used" , Gauge . Stats.currentBytesUsed)
467-
, ("rts.gc.current_bytes_slop" , Gauge . Stats.currentBytesSlop)
468-
, ("rts.gc.max_bytes_slop" , Gauge . Stats.maxBytesSlop)
469-
, ("rts.gc.peak_megabytes_allocated" , Gauge . Stats.peakMegabytesAllocated)
470-
, ("rts.gc.par_tot_bytes_copied" , Gauge . gcParTotBytesCopied)
471-
, ("rts.gc.par_avg_bytes_copied" , Gauge . gcParTotBytesCopied)
472-
, ("rts.gc.par_max_bytes_copied" , Gauge . Stats.parMaxBytesCopied)
451+
[ ("rts.allocated_bytes" , Counter . Stats.bytesAllocated)
452+
, ("rts.gcs" , Counter . Stats.numGcs)
453+
, ("rts.major_gcs" , Counter . Stats.numByteUsageSamples)
454+
, ("rts.cumulative_live_bytes" , Counter . Stats.cumulativeBytesUsed)
455+
, ("rts.copied_bytes" , Counter . Stats.bytesCopied)
456+
, ("rts.mutator_cpu_ns" , Counter . sToNs . Stats.mutatorCpuSeconds)
457+
, ("rts.mutator_elapsed_ns" , Counter . sToNs . Stats.mutatorWallSeconds)
458+
, ("rts.gc_cpu_ns" , Counter . sToNs . Stats.gcCpuSeconds)
459+
, ("rts.gc_elapsed_ns" , Counter . sToNs . Stats.gcWallSeconds)
460+
, ("rts.cpu_ns" , Counter . sToNs . Stats.cpuSeconds)
461+
, ("rts.elapsed_ns" , Counter . sToNs . Stats.wallSeconds)
462+
, ("rts.max_live_bytes" , Gauge . Stats.maxBytesUsed)
463+
, ("rts.gc.live_bytes" , Gauge . Stats.currentBytesUsed)
464+
, ("rts.gc.slop_bytes" , Gauge . Stats.currentBytesSlop)
465+
, ("rts.max_slop_bytes" , Gauge . Stats.maxBytesSlop)
466+
, ("rts.max_mem_in_use_bytes" , Gauge . Stats.peakMegabytesAllocated)
467+
-- Note that historically, the values
468+
-- par_tot_bytes_copied were both
469+
-- par_avg_bytes_copied
470+
-- were both taken from
471+
-- gcParTotBytesCopied
472+
-- after `parAvgBytesCopied` was renamed to `gcParTotBytesCopied`;
473+
-- see `ekg` commit
474+
-- 27467a61 - parAvgBytesCopied was renamed in GHC 7.6.1
475+
, ("rts.par_copied_bytes" , Gauge . gcParTotBytesCopied)
476+
, ("rts.gc.par_max_copied_bytes" , Gauge . Stats.parMaxBytesCopied)
473477
])
474478
getGcStats
475479
#endif

0 commit comments

Comments
 (0)