Skip to content

Commit 5b3a3b0

Browse files
committed
some refactors
1 parent 5691388 commit 5b3a3b0

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

System/Metrics.hs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -198,14 +198,14 @@ register :: T.Text
198198
-> IO ()
199199
register name sample store = do
200200
atomicModifyIORef (storeState store) $ \ state@State{..} ->
201-
case M.member name stateMetrics of
202-
False -> let !state' = state {
201+
if M.member name stateMetrics
202+
then alreadyInUseError name
203+
else let !state' = state {
203204
stateMetrics = M.insert name
204205
(Left sample)
205206
stateMetrics
206207
}
207208
in (state', ())
208-
True -> alreadyInUseError name
209209

210210
-- | Raise an exception indicating that the metric name is already in
211211
-- use.
@@ -331,16 +331,6 @@ createDistribution name store = do
331331
-- easily be added to a metrics store by calling their register
332332
-- function.
333333

334-
#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))
338-
#else
339-
-- | Convert seconds to milliseconds.
340-
sToMs :: Double -> Int64
341-
sToMs s = round (s * 1000.0)
342-
#endif
343-
344334
-- | Register a number of metrics related to garbage collector
345335
-- behavior.
346336
--
@@ -420,7 +410,7 @@ sToMs s = round (s * 1000.0)
420410
-- 1 for a maximally sequential run and approaches the number of
421411
-- threads (set by the RTS flag @-N@) for a maximally parallel run.
422412
registerGcMetrics :: Store -> IO ()
423-
registerGcMetrics store =
413+
registerGcMetrics =
424414
registerGroup
425415
#if MIN_VERSION_base(4,10,0)
426416
(M.fromList
@@ -449,6 +439,10 @@ registerGcMetrics store =
449439
, ("rts.gc.par_max_bytes_copied" , Gauge . fromIntegral . Stats.cumulative_par_max_copied_bytes)
450440
])
451441
getRTSStats
442+
where
443+
-- | Convert nanoseconds to milliseconds.
444+
nsToMs :: Int64 -> Int64
445+
nsToMs s = round (realToFrac s / (1000000.0 :: Double))
452446
#else
453447
(M.fromList
454448
[ ("rts.gc.bytes_allocated" , Counter . Stats.bytesAllocated)
@@ -472,8 +466,11 @@ registerGcMetrics store =
472466
, ("rts.gc.par_max_bytes_copied" , Gauge . Stats.parMaxBytesCopied)
473467
])
474468
getGcStats
469+
where
470+
-- | Convert seconds to milliseconds.
471+
sToMs :: Double -> Int64
472+
sToMs s = round (s * 1000.0)
475473
#endif
476-
store
477474

478475
#if MIN_VERSION_base(4,10,0)
479476
-- | Get RTS statistics.

0 commit comments

Comments
 (0)