-
Notifications
You must be signed in to change notification settings - Fork 755
CDFs for EB announcements #6639
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: leios-prototype
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| {-# LANGUAGE NamedFieldPuns #-} | ||
| {-# LANGUAGE RecordWildCards #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
|
|
||
| -- | CDFs | ||
| -- | ||
| -- This module should be imported qualified. | ||
| -- | ||
| module Cardano.Node.Tracing.Cdf | ||
| ( Counter (..) | ||
| , Config (..) | ||
| , State | ||
| , size | ||
| , null | ||
| , empty | ||
| , minPriority | ||
| , defaultConfig | ||
| , processDataPoint | ||
| ) where | ||
|
|
||
| import Prelude hiding (null) | ||
| import Data.Int (Int64) | ||
| import Data.IntPSQ (IntPSQ) | ||
| import qualified Data.IntPSQ as Pq | ||
| import Data.Time (NominalDiffTime) | ||
|
|
||
| data Counter = Counter { | ||
| limit :: !Double | ||
| , counter :: !Int64 | ||
| } | ||
|
|
||
| decCdf :: Double -> Counter -> Counter | ||
| decCdf v cdf@Counter{..} | ||
| | v < limit = cdf {counter = counter - 1} | ||
| | otherwise = cdf | ||
|
|
||
| incCdf :: Double -> Counter -> Counter | ||
| incCdf v cdf@Counter{..} | ||
| | v < limit = cdf {counter = counter + 1} | ||
| | otherwise = cdf | ||
|
|
||
|
|
||
| -- | We keep the results in a priority queue, to be able to evict the oldest | ||
| -- entry when the data sets become larger than `numOfDataPoints`. | ||
| -- | ||
| newtype State p = State { cdfState :: IntPSQ p NominalDiffTime } | ||
|
|
||
| empty :: State p | ||
| empty = State Pq.empty | ||
|
|
||
| null :: State p -> Bool | ||
| null = Pq.null . cdfState | ||
|
|
||
| size :: State p -> Int | ||
| size = Pq.size . cdfState | ||
|
|
||
| minPriority :: Ord p => State p -> Maybe p | ||
| minPriority State { cdfState } = case Pq.minView cdfState of | ||
| Nothing -> Nothing | ||
| Just (_, p, _, _) -> Just p | ||
|
|
||
| newtype Config = Config { numOfDataPoints :: Int } | ||
|
|
||
| -- | Default `Config` keeps `k/2` data points. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The proportionality to
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But one other option is to just force each callers to choose a number
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's how it's done, we just happen to provide a |
||
| defaultConfig :: Config | ||
| defaultConfig = Config { numOfDataPoints = 1080 } | ||
|
|
||
|
|
||
| processDataPoint | ||
| :: forall f p. | ||
| ( Ord p | ||
| , Functor f | ||
| ) | ||
| => Config | ||
| -> (Int, p, NominalDiffTime) | ||
| -- ^ index, priority, value | ||
| -> State p | ||
| -> f Counter | ||
| -> Maybe (f Counter, State p) | ||
| processDataPoint Config { numOfDataPoints } (idx, p, delay) (State m) cdfs | ||
| | idx `Pq.member` m | ||
| = Nothing | ||
|
|
||
| | otherwise | ||
| = if Pq.size m' > numOfDataPoints | ||
| then | ||
| case Pq.minView m' of | ||
| Nothing -> Nothing | ||
| Just (_, minVal, minDelay, m'') | ||
| | minVal == p | ||
| -> Nothing | ||
|
|
||
| | otherwise | ||
| -> Just (adjustCdf (realToFrac minDelay) <$> cdfs, State m'') | ||
| else | ||
| Just (updateCdf <$> cdfs, State m') | ||
| where | ||
| m' = Pq.insert idx p delay m | ||
|
|
||
| updateCdf :: Counter -> Counter | ||
| updateCdf = incCdf (realToFrac delay) | ||
|
|
||
| adjustCdf :: Double -> Counter -> Counter | ||
| adjustCdf d = updateCdf . decCdf d | ||
Uh oh!
There was an error while loading. Please reload this page.