Skip to content

Commit

Permalink
feat(sut): add throughput to metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-stevan-andjelkovic committed Mar 10, 2022
1 parent 3c3d300 commit 67ee633
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions src/sut/dumblog/src/Dumblog/Metrics/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Control.Monad (forever)
import Data.Maybe (fromMaybe)
import GHC.IO.Encoding (setLocaleEncoding, utf8)
import Text.Printf (printf)
import Data.Time (UTCTime, getCurrentTime, diffUTCTime)

import Dumblog.Journal.Main
import Dumblog.Journal.Metrics
Expand All @@ -18,15 +19,18 @@ import Journal.Types
------------------------------------------------------------------------

metricsMain :: IO ()
metricsMain = forever $ do
setLocaleEncoding utf8 -- Otherwise we can't print µ...
metrics <- newMetrics dumblogSchema dUMBLOG_METRICS
eMeta <- journalMetadata dUMBLOG_JOURNAL dumblogOptions
putStrLn ansiClearScreen
displayServiceTime metrics
displayJournalMetadata eMeta
displayConcurrentConnections metrics
threadDelay 1_000_000
metricsMain = do
startTime <- getCurrentTime
forever $ do
setLocaleEncoding utf8 -- Otherwise we can't print µ...
metrics <- newMetrics dumblogSchema dUMBLOG_METRICS
eMeta <- journalMetadata dUMBLOG_JOURNAL dumblogOptions
putStrLn ansiClearScreen
displayServiceTime metrics
displayThroughput metrics startTime
displayJournalMetadata eMeta
displayConcurrentConnections metrics
threadDelay 1_000_000

ansiClearScreen :: String
ansiClearScreen = "\ESC[2J"
Expand Down Expand Up @@ -61,7 +65,16 @@ displayServiceTime metrics = do
totalCnt = realToFrac (writeCnt + readCnt)
printf " count %7d (%2.0f%%) %10d (%2.0f%%)\n"
writeCnt (realToFrac writeCnt / totalCnt * 100)
readCnt (realToFrac readCnt / totalCnt * 100)
readCnt (realToFrac readCnt / totalCnt * 100)

displayThroughput :: DumblogMetrics -> UTCTime -> IO ()
displayThroughput metrics startTime = do
now <- getCurrentTime
writeCnt <- count metrics ServiceTimeWrites
readCnt <- count metrics ServiceTimeReads
let totalCnt :: Double
totalCnt = realToFrac (writeCnt + readCnt)
printf "\nThroughput: %.2f ops/s\n" (totalCnt / realToFrac (diffUTCTime now startTime))

displayJournalMetadata :: Either IOException Metadata -> IO ()
displayJournalMetadata (Left _err) = do
Expand Down

0 comments on commit 67ee633

Please sign in to comment.