Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
A module to collect aggregates on how much time is spent in a computation
Aggregates can be identified with a label that determines where the time of each computation is accounted for.
Measures are collected only if the environment variable
DEBUG_TIMESTATS_ENABLE
is set to any value ahead of invoking any function
in this module.
Synopsis
- measureM :: MonadIO m => String -> m a -> m a
- measurePure :: String -> a -> a
- printTimeStats :: MonadIO m => m ()
- hPrintTimeStats :: MonadIO m => Handle -> m ()
- reset :: MonadIO m => m ()
- data TimeStats = TimeStats {}
- collect :: MonadIO m => m [(String, TimeStats)]
- asText :: [(String, TimeStats)] -> Text
- scope :: MonadIO m => m a -> m a
- data TimeStatsRef
- lookupTimeStatsRef :: String -> IO TimeStatsRef
- updateTimeStatsRef :: TimeStatsRef -> (TimeStats -> TimeStats) -> IO ()
Measuring
measureM :: MonadIO m => String -> m a -> m a Source #
Measure the time it takes to run the action.
Add the time to the stats of the given label and increase its count by one.
measureM
keeps the stats in a globally available store in order to minimize
the changes necessary when instrumenting a program. Otherwise a reference to
the store would need to be passed to every function that might invoke
functions that need this reference.
A time measure isn't collected if the given action fails with an exception. This is a deliberate choice to demand less of the monad in which measures are taken.
Time measures aren't collected either if the environment variable
DEBUG_TIMESTATS_ENABLE
isn't set the first time this function is
evaluated.
measurePure :: String -> a -> a Source #
Pure version of measureM
. Measures the time taken to reduce the given
value to head normal form.
measurePure
is a bit dangerous to use in contexts where there are monadic
computations. If measurePure
is applied to a monadic computation it
will measure the time of constructing the computation rather than the time
of executing it, and the typechecker won't catch the mistake. We try to
fence against it with a longer name.
Time stats manipulation
printTimeStats :: MonadIO m => m () Source #
Prints the time stats to stderr.
hPrintTimeStats :: MonadIO m => Handle -> m () Source #
Prints the time stats to the given handle.
Reports how much time (in nanoseconds) the invocations to measureM
took
for a given label and how many times it was invoked on a given label.
collect :: MonadIO m => m [(String, TimeStats)] Source #
Yields the labels and the stats collected thus far.
scope :: MonadIO m => m a -> m a Source #
Run an action by previously reseting all stats to initial values and printing them afterwards.
Not intended for direct use
These definitions are not intended for instrumenting applications, but they can be handy to implement other measuring primitives.
data TimeStatsRef Source #
A reference to a TimeStats
value
lookupTimeStatsRef :: String -> IO TimeStatsRef Source #
Looks up the stats of a label. If no stats are found for the label, a new TimeStatsRef is created with initial values.
updateTimeStatsRef :: TimeStatsRef -> (TimeStats -> TimeStats) -> IO () Source #
Updates the TimeStats in a TimeStatsRef