@@ -69,6 +69,7 @@ module System.Metrics
69
69
) where
70
70
71
71
import Control.Monad (forM )
72
+ import Data.Int (Int64 )
72
73
import qualified Data.IntMap.Strict as IM
73
74
import Data.IORef (IORef , atomicModifyIORef , newIORef , readIORef )
74
75
import qualified Data.HashMap.Strict as M
@@ -131,8 +132,8 @@ data GroupSampler = forall a. GroupSampler
131
132
}
132
133
133
134
-- TODO: Rename this to Metric and Metric to SampledMetric.
134
- data MetricSampler = CounterS ! (IO Int )
135
- | GaugeS ! (IO Int )
135
+ data MetricSampler = CounterS ! (IO Int64 )
136
+ | GaugeS ! (IO Int64 )
136
137
| LabelS ! (IO T. Text )
137
138
| DistributionS ! (IO Distribution. Stats )
138
139
@@ -154,18 +155,18 @@ newStore = do
154
155
-- | Register a non-negative, monotonically increasing, integer-valued
155
156
-- metric. The provided action to read the value must be thread-safe.
156
157
-- Also see 'createCounter'.
157
- registerCounter :: T. Text -- ^ Counter name
158
- -> IO Int -- ^ Action to read the current metric value
159
- -> Store -- ^ Metric store
158
+ registerCounter :: T. Text -- ^ Counter name
159
+ -> IO Int64 -- ^ Action to read the current metric value
160
+ -> Store -- ^ Metric store
160
161
-> IO ()
161
162
registerCounter name sample store =
162
163
register name (CounterS sample) store
163
164
164
165
-- | Register an integer-valued metric. The provided action to read
165
166
-- the value must be thread-safe. Also see 'createGauge'.
166
- registerGauge :: T. Text -- ^ Gauge name
167
- -> IO Int -- ^ Action to read the current metric value
168
- -> Store -- ^ Metric store
167
+ registerGauge :: T. Text -- ^ Gauge name
168
+ -> IO Int64 -- ^ Action to read the current metric value
169
+ -> Store -- ^ Metric store
169
170
-> IO ()
170
171
registerGauge name sample store =
171
172
register name (GaugeS sample) store
@@ -329,16 +330,6 @@ createDistribution name store = do
329
330
-- easily be added to a metrics store by calling their register
330
331
-- function.
331
332
332
- #if MIN_VERSION_base(4,10,0)
333
- -- | Convert nanoseconds to milliseconds.
334
- nsToMs :: Int -> Int
335
- nsToMs s = round (realToFrac s / (1000000.0 :: Double ))
336
- #else
337
- -- | Convert seconds to milliseconds.
338
- sToMs :: Double -> Int
339
- sToMs s = round (s * 1000.0 )
340
- #endif
341
-
342
333
-- | Register a number of metrics related to garbage collector
343
334
-- behavior.
344
335
--
@@ -447,15 +438,15 @@ registerGcMetrics =
447
438
, (" rts.gc.cumulative_bytes_used" , Counter . fromIntegral . Stats. cumulative_live_bytes)
448
439
, (" rts.gc.bytes_copied" , Counter . fromIntegral . Stats. copied_bytes)
449
440
#if MIN_VERSION_base(4,12,0)
450
- , (" rts.gc.init_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. init_cpu_ns)
451
- , (" rts.gc.init_wall_ms" , Counter . nsToMs . fromIntegral . Stats. init_elapsed_ns)
441
+ , (" rts.gc.init_cpu_ms" , Counter . nsToMs . Stats. init_cpu_ns)
442
+ , (" rts.gc.init_wall_ms" , Counter . nsToMs . Stats. init_elapsed_ns)
452
443
#endif
453
- , (" rts.gc.mutator_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. mutator_cpu_ns)
454
- , (" rts.gc.mutator_wall_ms" , Counter . nsToMs . fromIntegral . Stats. mutator_elapsed_ns)
455
- , (" rts.gc.gc_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. gc_cpu_ns)
456
- , (" rts.gc.gc_wall_ms" , Counter . nsToMs . fromIntegral . Stats. gc_elapsed_ns)
457
- , (" rts.gc.cpu_ms" , Counter . nsToMs . fromIntegral . Stats. cpu_ns)
458
- , (" rts.gc.wall_ms" , Counter . nsToMs . fromIntegral . Stats. elapsed_ns)
444
+ , (" rts.gc.mutator_cpu_ms" , Counter . nsToMs . Stats. mutator_cpu_ns)
445
+ , (" rts.gc.mutator_wall_ms" , Counter . nsToMs . Stats. mutator_elapsed_ns)
446
+ , (" rts.gc.gc_cpu_ms" , Counter . nsToMs . Stats. gc_cpu_ns)
447
+ , (" rts.gc.gc_wall_ms" , Counter . nsToMs . Stats. gc_elapsed_ns)
448
+ , (" rts.gc.cpu_ms" , Counter . nsToMs . Stats. cpu_ns)
449
+ , (" rts.gc.wall_ms" , Counter . nsToMs . Stats. elapsed_ns)
459
450
, (" rts.gc.max_bytes_used" , Gauge . fromIntegral . Stats. max_live_bytes)
460
451
, (" rts.gc.max_large_bytes_used" , Gauge . fromIntegral . Stats. max_large_objects_bytes)
461
452
, (" rts.gc.max_compact_bytes_used" , Gauge . fromIntegral . Stats. max_compact_bytes)
@@ -469,42 +460,46 @@ registerGcMetrics =
469
460
#if MIN_VERSION_base(4,11,0)
470
461
, (" rts.gc.par_balanced_bytes_copied" , Gauge . fromIntegral . Stats. cumulative_par_balanced_copied_bytes)
471
462
#if MIN_VERSION_base(4,15,0)
472
- , (" rts.gc.nm.sync_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_sync_cpu_ns)
473
- , (" rts.gc.nm.sync_elapsed_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_sync_elapsed_ns)
474
- , (" rts.gc.nm.sync_max_elapsed_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_sync_max_elapsed_ns)
475
- , (" rts.gc.nm.cpu_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_cpu_ns)
476
- , (" rts.gc.nm.elapsed_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_elapsed_ns)
477
- , (" rts.gc.nm.max_elapsed_ms" , Counter . nsToMs . fromIntegral . Stats. nonmoving_gc_max_elapsed_ns)
463
+ , (" rts.gc.nm.sync_cpu_ms" , Counter . nsToMs . Stats. nonmoving_gc_sync_cpu_ns)
464
+ , (" rts.gc.nm.sync_elapsed_ms" , Counter . nsToMs . Stats. nonmoving_gc_sync_elapsed_ns)
465
+ , (" rts.gc.nm.sync_max_elapsed_ms" , Counter . nsToMs . Stats. nonmoving_gc_sync_max_elapsed_ns)
466
+ , (" rts.gc.nm.cpu_ms" , Counter . nsToMs . Stats. nonmoving_gc_cpu_ns)
467
+ , (" rts.gc.nm.elapsed_ms" , Counter . nsToMs . Stats. nonmoving_gc_elapsed_ns)
468
+ , (" rts.gc.nm.max_elapsed_ms" , Counter . nsToMs . Stats. nonmoving_gc_max_elapsed_ns)
478
469
# endif
479
470
# endif
480
471
])
481
472
getRTSStats
473
+ where
474
+ -- | Convert nanoseconds to milliseconds.
475
+ nsToMs :: Int64 -> Int64
476
+ nsToMs s = round (realToFrac s / (1000000.0 :: Double ))
482
477
#else
483
478
(M. fromList
484
- [ (" rts.gc.bytes_allocated" , Counter . fromIntegral . Stats. bytesAllocated)
485
- , (" rts.gc.num_gcs" , Counter . fromIntegral . Stats. numGcs)
486
- , (" rts.gc.num_bytes_usage_samples" , Counter . fromIntegral . Stats. numByteUsageSamples)
487
- , (" rts.gc.cumulative_bytes_used" , Counter . fromIntegral . Stats. cumulativeBytesUsed)
488
- , (" rts.gc.bytes_copied" , Counter . fromIntegral . Stats. bytesCopied)
479
+ [ (" rts.gc.bytes_allocated" , Counter . Stats. bytesAllocated)
480
+ , (" rts.gc.num_gcs" , Counter . Stats. numGcs)
481
+ , (" rts.gc.num_bytes_usage_samples" , Counter . Stats. numByteUsageSamples)
482
+ , (" rts.gc.cumulative_bytes_used" , Counter . Stats. cumulativeBytesUsed)
483
+ , (" rts.gc.bytes_copied" , Counter . Stats. bytesCopied)
489
484
, (" rts.gc.mutator_cpu_ms" , Counter . sToMs . Stats. mutatorCpuSeconds)
490
485
, (" rts.gc.mutator_wall_ms" , Counter . sToMs . Stats. mutatorWallSeconds)
491
486
, (" rts.gc.gc_cpu_ms" , Counter . sToMs . Stats. gcCpuSeconds)
492
487
, (" rts.gc.gc_wall_ms" , Counter . sToMs . Stats. gcWallSeconds)
493
488
, (" rts.gc.cpu_ms" , Counter . sToMs . Stats. cpuSeconds)
494
489
, (" rts.gc.wall_ms" , Counter . sToMs . Stats. wallSeconds)
495
- , (" rts.gc.max_bytes_used" , Gauge . fromIntegral . Stats. maxBytesUsed)
496
- , (" rts.gc.current_bytes_used" , Gauge . fromIntegral . Stats. currentBytesUsed)
497
- , (" rts.gc.current_bytes_slop" , Gauge . fromIntegral . Stats. currentBytesSlop)
498
- , (" rts.gc.max_bytes_slop" , Gauge . fromIntegral . Stats. maxBytesSlop)
499
- , (" rts.gc.peak_megabytes_allocated" , Gauge . fromIntegral . Stats. peakMegabytesAllocated)
500
- , (" rts.gc.par_tot_bytes_copied" , Gauge . fromIntegral . gcParTotBytesCopied)
501
- , (" rts.gc.par_avg_bytes_copied" , Gauge . fromIntegral . gcParTotBytesCopied)
502
- , (" rts.gc.par_max_bytes_copied" , Gauge . fromIntegral . Stats. parMaxBytesCopied)
490
+ , (" rts.gc.max_bytes_used" , Gauge . Stats. maxBytesUsed)
491
+ , (" rts.gc.current_bytes_used" , Gauge . Stats. currentBytesUsed)
492
+ , (" rts.gc.current_bytes_slop" , Gauge . Stats. currentBytesSlop)
493
+ , (" rts.gc.max_bytes_slop" , Gauge . Stats. maxBytesSlop)
494
+ , (" rts.gc.peak_megabytes_allocated" , Gauge . Stats. peakMegabytesAllocated)
495
+ , (" rts.gc.par_tot_bytes_copied" , Gauge . gcParTotBytesCopied)
496
+ , (" rts.gc.par_avg_bytes_copied" , Gauge . gcParTotBytesCopied)
497
+ , (" rts.gc.par_max_bytes_copied" , Gauge . Stats. parMaxBytesCopied)
503
498
])
504
499
getGcStats
505
500
where
506
501
-- | Convert seconds to milliseconds.
507
- sToMs :: Double -> Int
502
+ sToMs :: Double -> Int64
508
503
sToMs s = round (s * 1000.0 )
509
504
#endif
510
505
@@ -619,7 +614,7 @@ getGcStats = Stats.getGCStats
619
614
# endif
620
615
621
616
-- | Helper to work around rename in GHC.Stats in base-4.6.
622
- -- gcParTotBytesCopied :: Stats.GCStats -> Int64
617
+ gcParTotBytesCopied :: Stats. GCStats -> Int64
623
618
# if MIN_VERSION_base(4,6,0)
624
619
gcParTotBytesCopied = Stats. parTotBytesCopied
625
620
# else
@@ -663,8 +658,8 @@ sampleGroups cbSamplers = concat `fmap` sequence (map runOne cbSamplers)
663
658
return $! map (\ (n, f) -> (n, f a)) (M. toList groupSamplerMetrics)
664
659
665
660
-- | The value of a sampled metric.
666
- data Value = Counter {- # UNPACK #-} !Int
667
- | Gauge {- # UNPACK #-} !Int
661
+ data Value = Counter {- # UNPACK #-} !Int64
662
+ | Gauge {- # UNPACK #-} !Int64
668
663
| Label {- # UNPACK #-} !T. Text
669
664
| Distribution ! Distribution. Stats
670
665
deriving (Eq , Show )
0 commit comments