@@ -70,7 +70,6 @@ module System.Metrics
7070
7171import Control.Applicative ((<$>) )
7272import Control.Monad (forM )
73- import Data.Int (Int64 )
7473import qualified Data.IntMap.Strict as IM
7574import Data.IORef (IORef , atomicModifyIORef , newIORef , readIORef )
7675import qualified Data.HashMap.Strict as M
@@ -133,8 +132,8 @@ data GroupSampler = forall a. GroupSampler
133132 }
134133
135134-- TODO: Rename this to Metric and Metric to SampledMetric.
136- data MetricSampler = CounterS ! (IO Int64 )
137- | GaugeS ! (IO Int64 )
135+ data MetricSampler = CounterS ! (IO Int )
136+ | GaugeS ! (IO Int )
138137 | LabelS ! (IO T. Text )
139138 | DistributionS ! (IO Distribution. Stats )
140139
@@ -156,18 +155,18 @@ newStore = do
156155-- | Register a non-negative, monotonically increasing, integer-valued
157156-- metric. The provided action to read the value must be thread-safe.
158157-- Also see 'createCounter'.
159- registerCounter :: T. Text -- ^ Counter name
160- -> IO Int64 -- ^ Action to read the current metric value
161- -> Store -- ^ Metric store
158+ registerCounter :: T. Text -- ^ Counter name
159+ -> IO Int -- ^ Action to read the current metric value
160+ -> Store -- ^ Metric store
162161 -> IO ()
163162registerCounter name sample store =
164163 register name (CounterS sample) store
165164
166165-- | Register an integer-valued metric. The provided action to read
167166-- the value must be thread-safe. Also see 'createGauge'.
168- registerGauge :: T. Text -- ^ Gauge name
169- -> IO Int64 -- ^ Action to read the current metric value
170- -> Store -- ^ Metric store
167+ registerGauge :: T. Text -- ^ Gauge name
168+ -> IO Int -- ^ Action to read the current metric value
169+ -> Store -- ^ Metric store
171170 -> IO ()
172171registerGauge name sample store =
173172 register name (GaugeS sample) store
@@ -333,11 +332,11 @@ createDistribution name store = do
333332
334333#if MIN_VERSION_base(4,10,0)
335334-- | Convert nanoseconds to milliseconds.
336- nsToMs :: Int64 -> Int64
335+ nsToMs :: Int -> Int
337336nsToMs s = round (realToFrac s / (1000000.0 :: Double ))
338337#else
339338-- | Convert seconds to milliseconds.
340- sToMs :: Double -> Int64
339+ sToMs :: Double -> Int
341340sToMs s = round (s * 1000.0 )
342341#endif
343342
@@ -430,15 +429,15 @@ registerGcMetrics store =
430429 , (" rts.gc.cumulative_bytes_used" , Counter . fromIntegral . Stats. cumulative_live_bytes)
431430 , (" rts.gc.bytes_copied" , Counter . fromIntegral . Stats. copied_bytes)
432431#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)
432+ , (" rts.gc.init_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. init_cpu_ns)
433+ , (" rts.gc.init_wall_ms" , Counter . nsToMs . fromIntegral . Stats. init_elapsed_ns)
435434#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)
435+ , (" rts.gc.mutator_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. mutator_cpu_ns)
436+ , (" rts.gc.mutator_wall_ms" , Counter . nsToMs . fromIntegral . Stats. mutator_elapsed_ns)
437+ , (" rts.gc.gc_cpu_ms" , Counter . nsToMs . fromIntegral . Stats. gc_cpu_ns)
438+ , (" rts.gc.gc_wall_ms" , Counter . nsToMs . fromIntegral . Stats. gc_elapsed_ns)
439+ , (" rts.gc.cpu_ms" , Counter . nsToMs . fromIntegral . Stats. cpu_ns)
440+ , (" rts.gc.wall_ms" , Counter . nsToMs . fromIntegral . Stats. elapsed_ns)
442441 , (" rts.gc.max_bytes_used" , Gauge . fromIntegral . Stats. max_live_bytes)
443442 , (" rts.gc.current_bytes_used" , Gauge . fromIntegral . Stats. gcdetails_live_bytes . Stats. gc)
444443 , (" rts.gc.current_bytes_slop" , Gauge . fromIntegral . Stats. gcdetails_slop_bytes . Stats. gc)
@@ -615,8 +614,8 @@ sampleGroups cbSamplers = concat `fmap` sequence (map runOne cbSamplers)
615614 return $! map (\ (n, f) -> (n, f a)) (M. toList groupSamplerMetrics)
616615
617616-- | The value of a sampled metric.
618- data Value = Counter {- # UNPACK #-} !Int64
619- | Gauge {- # UNPACK #-} !Int64
617+ data Value = Counter {- # UNPACK #-} !Int
618+ | Gauge {- # UNPACK #-} !Int
620619 | Label {- # UNPACK #-} !T. Text
621620 | Distribution ! Distribution. Stats
622621 deriving (Eq , Show )
0 commit comments