module HSBencher.Harvesters ( customTagHarvesterInt,
customTagHarvesterDouble,
customTagHarvesterString) 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}
taggedLineHarvesterStr :: B.ByteString
-> (String -> RunResult -> RunResult)
-> LineHarvester
taggedLineHarvesterStr tag stickit = LineHarvester $ \ ln ->
let fail = (id, False) in
case B.words ln of
[] -> fail
hd:tl | hd == tag || hd == (tag `B.append` (pack ":")) ->
(stickit (unpack (B.unwords tl)), True)
_ -> fail