module HSBencher.Harvesters ( customTagHarvesterInt,
customTagHarvesterDouble,
customTagHarvesterString,
customAccumHarvesterInt,
customAccumHarvesterDouble,
customAccumHarvesterString
) where
import HSBencher.Types
import HSBencher.Internal.MeasureProcess
import Data.ByteString.Char8 as B
customTagHarvesterInt :: String -> LineHarvester
customTagHarvesterInt tag =
taggedLineHarvester (pack tag) $
\d r -> r {custom = (tag,IntResult d) : custom r}
customTagHarvesterDouble :: String -> LineHarvester
customTagHarvesterDouble tag =
taggedLineHarvester (pack tag) $
\d r -> r {custom = (tag,DoubleResult d) : custom r}
customTagHarvesterString :: String -> LineHarvester
customTagHarvesterString tag =
taggedLineHarvesterStr (pack tag) $
\s r -> r {custom = (tag,StringResult s) : custom r}
customAccumHarvesterInt :: String -> LineHarvester
customAccumHarvesterInt = accumHarvester IntResult
customAccumHarvesterDouble :: String -> LineHarvester
customAccumHarvesterDouble = accumHarvester DoubleResult
customAccumHarvesterString :: String -> LineHarvester
customAccumHarvesterString = accumHarvester StringResult
accumHarvester :: Read a => (a -> SomeResult) -> String -> LineHarvester
accumHarvester ctr tag =
taggedLineHarvester (pack tag) $ \s r ->
r {
custom = (tag, AccumResult [ctr s]) : custom r
}
taggedLineHarvesterStr :: B.ByteString
-> (String -> RunResult -> RunResult)
-> LineHarvester
taggedLineHarvesterStr tag stickit = LineHarvester $ \ ln ->
let failit = (id, False) in
case B.words ln of
[] -> failit
hd:tl | hd == tag || hd == (tag `B.append` (pack ":")) ->
(stickit (unpack (B.unwords tl)), True)
_ -> failit