\subsection{Cardano.BM.Counters.Common}
\label{code:Cardano.BM.Counters.Common}
Common functions that serve |readCounters| on all platforms.
%if style == newcode
\begin{code}
module Cardano.BM.Counters.Common
(
getMonoClock
, readRTSStats
) where
import Data.Text (Text)
import GHC.Clock (getMonotonicTimeNSec)
import qualified GHC.Stats as GhcStats
import Cardano.BM.Data.Aggregated (Measurable (..))
import Cardano.BM.Data.Counter
\end{code}
%endif
\label{code:nominalTimeToMicroseconds}\index{nominalTimeToMicroseconds}
\begin{spec}
nominalTimeToMicroseconds :: Word64 -> Microsecond
nominalTimeToMicroseconds = fromMicroseconds . toInteger . (`div` 1000)
\end{spec}
\subsubsection{Read monotonic clock}\label{code:getMonoClock}\index{getMonoClock}
\begin{code}
getMonoClock :: IO [Counter]
getMonoClock :: IO [Counter]
getMonoClock = do
Word64
t <- IO Word64
getMonotonicTimeNSec
[Counter] -> IO [Counter]
forall (m :: * -> *) a. Monad m => a -> m a
return [ CounterType -> Text -> Measurable -> Counter
Counter CounterType
MonotonicClockTime Text
"monoclock" (Measurable -> Counter) -> Measurable -> Counter
forall a b. (a -> b) -> a -> b
$ Word64 -> Measurable
Microseconds (Word64
t Word64 -> Word64 -> Word64
forall a. Integral a => a -> a -> a
`div` Word64
1000) ]
\end{code}
\subsubsection{Read GHC RTS statistics}\label{code:readRTSStats}\index{readRTSStats}
Read counters from GHC's |RTS| (runtime system). The values returned are as per the last
GC (garbage collection) run.
\begin{code}
readRTSStats :: IO [Counter]
readRTSStats :: IO [Counter]
readRTSStats = do
Bool
iscollected <- IO Bool
GhcStats.getRTSStatsEnabled
if Bool
iscollected
then IO [Counter]
ghcstats
else [Counter] -> IO [Counter]
forall (m :: * -> *) a. Monad m => a -> m a
return []
where
ghcstats :: IO [Counter]
ghcstats :: IO [Counter]
ghcstats = do
RTSStats
rts <- IO RTSStats
GhcStats.getRTSStats
let getrts :: (RTSStats -> Measurable, Text) -> Counter
getrts = RTSStats -> (RTSStats -> Measurable, Text) -> Counter
ghcval RTSStats
rts
[Counter] -> IO [Counter]
forall (m :: * -> *) a. Monad m => a -> m a
return [ (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.allocated_bytes, Text
"bytesAllocated")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.cumulative_live_bytes, Text
"liveBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.max_live_bytes, Text
"maxLiveBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.max_large_objects_bytes, Text
"maxLargeBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.max_compact_bytes, Text
"maxCompactBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.max_slop_bytes, Text
"maxSlopBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word64
GhcStats.max_mem_in_use_bytes, Text
"maxUsedMemBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GCDetails -> Word64
GhcStats.gcdetails_live_bytes (GCDetails -> Word64)
-> (RTSStats -> GCDetails) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> GCDetails
GhcStats.gc, Text
"gcLiveBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Bytes (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word64 -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word64 -> Word64) -> (RTSStats -> Word64) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GCDetails -> Word64
GhcStats.gcdetails_copied_bytes (GCDetails -> Word64)
-> (RTSStats -> GCDetails) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> GCDetails
GhcStats.gc, Text
"gcCopiedBytes")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Nanoseconds (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RtsTime -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RtsTime -> Word64) -> (RTSStats -> RtsTime) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> RtsTime
GhcStats.gc_cpu_ns, Text
"gcCpuNs")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Nanoseconds (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RtsTime -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RtsTime -> Word64) -> (RTSStats -> RtsTime) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> RtsTime
GhcStats.gc_elapsed_ns, Text
"gcElapsedNs")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Nanoseconds (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RtsTime -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RtsTime -> Word64) -> (RTSStats -> RtsTime) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> RtsTime
GhcStats.cpu_ns, Text
"cpuNs")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Word64 -> Measurable
Nanoseconds (Word64 -> Measurable)
-> (RTSStats -> Word64) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RtsTime -> Word64
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RtsTime -> Word64) -> (RTSStats -> RtsTime) -> RTSStats -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> RtsTime
GhcStats.elapsed_ns, Text
"elapsedNs")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Integer -> Measurable
PureI (Integer -> Measurable)
-> (RTSStats -> Integer) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger (Word32 -> Integer) -> (RTSStats -> Word32) -> RTSStats -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word32
GhcStats.gcs, Text
"gcNum")
, (RTSStats -> Measurable, Text) -> Counter
getrts (Integer -> Measurable
PureI (Integer -> Measurable)
-> (RTSStats -> Integer) -> RTSStats -> Measurable
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Word32 -> Integer
forall a. Integral a => a -> Integer
toInteger (Word32 -> Integer) -> (RTSStats -> Word32) -> RTSStats -> Integer
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RTSStats -> Word32
GhcStats.major_gcs, Text
"gcMajorNum")
]
ghcval :: GhcStats.RTSStats -> ((GhcStats.RTSStats -> Measurable), Text) -> Counter
ghcval :: RTSStats -> (RTSStats -> Measurable, Text) -> Counter
ghcval RTSStats
s (RTSStats -> Measurable
f, Text
n) = CounterType -> Text -> Measurable -> Counter
Counter CounterType
RTSStats Text
n (Measurable -> Counter) -> Measurable -> Counter
forall a b. (a -> b) -> a -> b
$ (RTSStats -> Measurable
f RTSStats
s)
\end{code}