...
  View open merge request
Commits (60)
packages: shake
source-repository-package
type: git
location: https://github.com/bgamari/tabular
tag: 204b01f63dec6bf0e0aba2862c71e77b2ec3909b
......@@ -35,6 +35,8 @@ instance Applicative Pure where
instance Monad Pure where
Pure x >>= k = k x
return = Pure
instance MonadFail Pure where
fail s = error s
instance MonadEval Pure where
......@@ -313,6 +315,8 @@ instance Monad Abs where
AbsState r s' -> runAbs (k r) s'
AbsFail m -> AbsFail m)
return = pure
instance MonadFail Abs where
fail s = Abs (\ n -> AbsFail s)
instance MonadEval Abs where
......
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module CachegrindParse where
import Data.Maybe
import qualified Data.Map as M
newtype EventName = EventName { getEventName :: String }
deriving (Show, Eq, Ord)
parse :: FilePath -> IO (M.Map EventName Integer)
parse fname = parse' <$> readFile fname
parse' :: String -> M.Map EventName Integer
parse' content =
M.fromList $ zip summary events
where
events = case mapMaybe isEventList $ lines content of
[] -> error "No event list found"
[x] -> x
_ -> error "More than one event list found"
summary = case mapMaybe isSummaryList $ lines content of
[] -> error "No event summary found"
[x] -> x
_ -> error "More than one event summary found"
isEventList :: String -> Maybe [Integer]
isEventList line
| "summary:" : rest <- words line = Just $ map read rest
| otherwise = Nothing
isSummaryList :: String -> Maybe [EventName]
isSummaryList line
| "events:" : rest <- words line = Just $ map EventName rest
| otherwise = Nothing
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Debug.Trace
import Data.Align (Align, alignWith)
import Data.Maybe
import Data.These
import Data.Char
import Data.List (intercalate, group)
import Data.Foldable
import Numeric
import qualified Data.Sequence as Seq
import qualified Data.Tree as Tree
import Data.Tree (Tree)
import qualified Data.Map.Strict as M
import qualified Data.Text as T
import System.Directory
import System.FilePath
import Text.Tabular
import qualified Text.Tabular.AsciiArt as AsciiArt
import qualified Text.Tabular.Csv as Csv
import qualified Text.Tabular.Latex as Latex
import Options.Applicative as O
import System.Console.ANSI.Codes as ANSI
import qualified MeasurementTree as MTree
import MeasurementTree (Measurements, Label)
import LabelMatch
data Mode = RelativeMode | AbsoluteMode
args :: Parser (Mode, OutputDest, OutputFormat, OutputOptions, [FilePath])
args =
(,,,,)
<$> flag RelativeMode AbsoluteMode (long "absolute" <> short 'a' <> help "show absolute metrics")
<*> outputDest
<*> formatOption
<*> outputOptions
<*> some (argument str (metavar "FILE" <> help "results.json file"))
where
formatOption :: Parser OutputFormat
formatOption = option (str >>= parse) (long "format" <> short 'f' <> help "Output format (one of markdown, ascii, csv, latex)" <> O.value FmtAsciiArt)
where
parse "markdown" = pure FmtMarkdown
parse "ascii" = pure FmtAsciiArt
parse "csv" = pure FmtCsv
parse "latex" = pure FmtLatex
parse _ = fail "Unknown --format"
outputDest :: Parser OutputDest
outputDest =
option (ToSingleFile <$> str) (long "output" <> short 'o' <> help "write output to single file")
<|> option (ToManyFiles <$> str) (long "output-dir" <> short 'O' <> help "write output to many files, one per table")
<|> pure ToStdout
outputOptions :: Parser OutputOptions
outputOptions =
OutputOptions
<$> switch (long "fancy-chars" <> short 'f' <> help "Use proper typography")
<*> switch (long "color" <> short 'c' <> help "Enable color output")
renderGitLabMarkdown :: (rh -> String) -> (ch -> String) -> (a -> String) -> Table rh ch a -> String
renderGitLabMarkdown renderRow renderCol renderCell (Table rows cols cells) =
unlines $ [header, headerSep] ++ cells'
where
prepend x = (x :)
joinCols xs = "| " ++ intercalate " | " xs ++ " |"
header = joinCols $ prepend "" $ map renderRow (headerContents rows)
headerSep = joinCols $ map (const " -------- ") header
emphasize x = "*"++x++"*"
cells' = zipWith (\rh row -> joinCols
$ prepend (emphasize $ renderRow rh)
$ map renderCell row
) (headerContents rows) cells
data OutputFormat = FmtMarkdown | FmtAsciiArt | FmtCsv | FmtLatex
render :: OutputFormat
-> (rh -> String) -> (ch -> String) -> (a -> String)
-> Table rh ch a
-> String
render FmtMarkdown = renderGitLabMarkdown
render FmtAsciiArt = AsciiArt.render
render FmtCsv = Csv.render
render FmtLatex = Latex.render
-- | Pick out the interesting part of a set of filenames for use as a friendly
-- name. Essentially we just break up all paths into their components and drop
-- all components common to all.
friendlyNameFiles :: [FilePath] -> M.Map MetricFile FilePath
friendlyNameFiles files =
M.fromList
[ (MetricFile $ joinPath $ toList name, path)
| (path, name) <- M.toList friendlyNames
]
where
friendlyNames :: M.Map FilePath (Seq.Seq String)
friendlyNames =
fmap (fmap snd . Seq.filter (not . fst) . Seq.zip isCommon) splitPaths
where
isCommon :: Seq.Seq Bool
isCommon = Seq.fromList $ fmap isCommonComp [0..maximum $ fmap length splitPaths]
splitPaths :: M.Map FilePath (Seq.Seq String)
splitPaths = M.fromList [ (f, Seq.fromList $ splitPath f) | f <- files ]
isCommonComp :: Int -> Bool
isCommonComp n = allEqual $ M.elems $ fmap (Seq.!? n) splitPaths
allEqual :: Eq a => [a] -> Bool
allEqual xs = length (group xs) == 1
mapColHeader :: (ch -> ch') -> Table rh ch a -> Table rh ch' a
mapColHeader f (Table rh ch xs) = Table rh (fmap f ch) xs
mapRowHeader :: (rh -> rh') -> Table rh ch a -> Table rh' ch a
mapRowHeader f (Table rh ch xs) = Table (fmap f rh) ch xs
mapTable :: (a -> b) -> Table rh ch a -> Table rh ch b
mapTable f (Table rh ch xs) = Table rh ch (map (map f) xs)
mapSemiTable :: (a -> b) -> SemiTable h a -> SemiTable h b
mapSemiTable f (SemiTable h xs) = SemiTable h (map f xs)
data OutputOptions = OutputOptions { fancyChars, color :: Bool }
simpleOutput :: OutputOptions
simpleOutput = OutputOptions False False
class ToRowLabel a where toRowLabel :: a -> String
instance ToRowLabel String where toRowLabel = id
instance ToRowLabel Label where toRowLabel = T.unpack . MTree.encodeLabel
instance (ToRowLabel a, ToRowLabel b) => ToRowLabel (a,b) where
toRowLabel (a,b) = toRowLabel a ++ " // " ++ toRowLabel b
withColor :: OutputOptions -> ANSI.Color -> ShowS -> ShowS
withColor opts c s
| color opts =
showString start . s . showString end
| otherwise = s
where
start = ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Vivid c]
end = ANSI.setSGRCode [ANSI.Reset]
showGFloat' :: RealFloat a => OutputOptions -> Maybe Int -> a -> ShowS
showGFloat' opts prec x = prettySign opts x . showGFloat prec (abs x)
prettySign :: (Ord a, Num a) => OutputOptions -> a -> ShowS
prettySign opts x
| x < 0 = if fancyChars opts then showChar '−' else showChar '-'
| x > 0 = showChar '+'
| otherwise = id
-- | The presentation name of a metric file.
newtype MetricFile = MetricFile { metricFileFriendlyName :: String }
deriving (Ord, Eq, Show)
-- | Where to write output?
data OutputDest = ToStdout | ToSingleFile FilePath | ToManyFiles FilePath
initializeOutputDest :: OutputDest -> IO ()
initializeOutputDest ToStdout = return ()
initializeOutputDest (ToSingleFile path) = writeFile path "" -- truncate
initializeOutputDest (ToManyFiles path) = createDirectoryIfMissing False path
writeTable :: OutputDest
-> String -- ^ table title
-> String -- ^ contents
-> IO ()
writeTable (ToManyFiles dir) title contents =
writeFile (dir </> fname) contents
where
fname = map sanitize title
sanitize ' ' = '-'
sanitize x = toLower x
writeTable dest title contents =
write $ unlines
[ ""
, "# " <> title
, ""
, contents
]
where
write = case dest of
ToStdout -> putStrLn
ToSingleFile path -> appendFile path
main :: IO ()
main = do
(mode, outputDest, fmt, opts, files) <- execParser $ info (helper <*> args) mempty
initializeOutputDest outputDest
let filesWithFriendlyNames :: M.Map MetricFile FilePath
filesWithFriendlyNames = friendlyNameFiles files
-- Yuck. Figure out friendly name of reference set
[ref] = [ name
| (name, fname) <- M.toList filesWithFriendlyNames
, fname == head files
]
mtrees <- mapM MTree.readFile filesWithFriendlyNames
:: IO (M.Map MetricFile (Measurements Double))
let mtrees' :: M.Map MetricFile (M.Map Label (MeanStddev Double))
mtrees' = fmap (MTree.toMap (fromJust . meanStdErr)) mtrees
let aligned :: M.Map Label (M.Map MetricFile (MeanStddev Double))
aligned = alignMany mtrees'
let tabulate :: forall rh. (Ord rh, ToRowLabel rh) => String -> LabelMatcher rh -> IO ()
tabulate heading pred = writeTable outputDest heading contents
where
xs :: M.Map rh (M.Map MetricFile (MeanStddev Double))
xs = M.fromList
$ mapMaybe (\(k,v) -> (\k' -> (k',v)) <$> match pred k)
$ M.toList aligned
contents
| null xs = "## no samples"
| otherwise =
case mode of
RelativeMode ->
let showRel = maybe "∙" (showRelative (showGFloat' opts (Just 3)) (showPercent opts))
relChg = toRelativeChange ref (fmap (fmap msMean) xs)
cols :: [SemiTable Column Cell]
cols =
[ absoluteCol xs ref, stderrCol xs ref ] ++
concat
[ [ relativeCol xs ref metricFile
, stderrCol xs metricFile
]
| metricFile <- M.keys mtrees
, metricFile /= ref
]
table :: Table rh Column Cell
table = foldl' (^|^) (baseTable xs) cols
in render fmt id (runShowS . showColumn) id
$ mapRowHeader toRowLabel (mapTable (runShowS . showCell opts) table)
+====+
mapSemiTable (maybe "" (\x -> showsPctChange opts x "")) (geomMeanRow relChg)
AbsoluteMode ->
let cols :: [SemiTable Column Cell]
cols = concat
[ [ absoluteCol xs metricFile
, stderrCol xs metricFile
]
| metricFile <- M.keys mtrees
]
table :: Table rh Column Cell
table = foldl' (^|^) (baseTable xs) cols
in render fmt toRowLabel (runShowS . showColumn) (runShowS . showCell opts) table
-- compile-time metrics
tabulate "compiler allocations" $ objectCompilerRtsStats <* "bytes allocated"
tabulate "compiler mutator time" $ objectCompilerRtsStats <* "mutator_cpu_seconds"
tabulate "compiler GC time" $ objectCompilerRtsStats <* "GC_cpu_seconds"
tabulate "executable size" $ testName <* "executable size"
-- run-time metrics
tabulate "bytes allocated" $ runRtsStats <* "bytes allocated"
tabulate "mutator time" $ runRtsStats <* ("mutator_cpu_seconds" <|> "mut_cpu_seconds")
tabulate "GC time" $ runRtsStats <* "GC_cpu_seconds"
-- cachegrind
tabulate "instructions" $ cachegrindStats <* "Ir"
tabulate "LLC cache misses" $ cachegrindStats <* "DLmr"
tabulate "L1 cache misses" $ cachegrindStats <* "D1mr"
tabulate "perf cache-misses" $ perfStats <* ("cache-misses" <|> "cache-misses:u")
tabulate "perf instructions" $ perfStats <* ("instructions" <|> "instructions:u")
tabulate "perf cycles" $ perfStats <* ("cycles" <|> "cycles:u")
alignMany :: (Align f, Ord k) => M.Map k (f a) -> f (M.Map k a)
alignMany mtrees =
foldl1 (alignWith (mergeThese M.union))
[ fmap (M.singleton k) mtree
| (k, mtree) <- M.toList mtrees
]
type TestName = String
type ModuleName = String
testName :: LabelMatcher TestName
testName = wildcard
objectCompilerRtsStats :: LabelMatcher (TestName, ModuleName)
objectCompilerRtsStats = (,) <$> testName <* "objects" <*> wildcard <* "rts stats"
runRtsStats :: LabelMatcher TestName
runRtsStats = testName <* "run" <* "rts stats"
cachegrindStats :: LabelMatcher TestName
cachegrindStats = testName <* "run" <* "cachegrind"
perfStats :: LabelMatcher TestName
perfStats = testName <* "run" <* "perf"
data Column = AbsoluteCol MetricFile
| RelativeCol MetricFile
| StderrCol MetricFile
deriving (Show)
showColumn :: Column -> ShowS
showColumn (AbsoluteCol mf) = showString $ metricFileFriendlyName mf
showColumn (RelativeCol mf) = showString (metricFileFriendlyName mf) . showString " (rel)"
showColumn (StderrCol mf) = showString "std. err." --showString (metricFileFriendlyName mf) . showString " (\\sigma)"
data Cell = CellPctChange (ValueBaseline Double)
| CellMissing
| CellAbsolute Double
| CellStderrRel (MeanStddev Double)
deriving (Show)
showCell :: OutputOptions -> Cell -> ShowS
showCell opts (CellPctChange vb) = showString $ showPercent opts vb
showCell opts CellMissing = showChar '∙'
showCell opts (CellAbsolute x) = showGFloat' opts (Just 3) x
showCell opts (CellStderrRel ms) = showGFloat (Just 1) (msStddev ms / msMean ms * 100) . showChar '%'
baseTable :: M.Map rh (M.Map MetricFile (MeanStddev Double))
-> Table rh Column Cell
baseTable mtrees =
Table (Group NoLine $ map Header rowLbls) (Group NoLine []) ([] <$ rowLbls)
where rowLbls = M.keys mtrees
absoluteCol :: M.Map lbl (M.Map MetricFile (MeanStddev Double))
-> MetricFile
-> SemiTable Column Cell
absoluteCol mtrees metricFile =
col (AbsoluteCol metricFile)
[ maybe CellMissing (CellAbsolute . msMean) $ M.lookup metricFile xs
| (_metric, xs) <- M.toList mtrees
]
relativeCol :: M.Map lbl (M.Map MetricFile (MeanStddev Double))
-> MetricFile -- ^ reference
-> MetricFile
-> SemiTable Column Cell
relativeCol mtrees refFile metricFile =
col (RelativeCol metricFile)
[ fromMaybe CellMissing $ do
baseline <- msMean <$> M.lookup refFile xs
value <- msMean <$> M.lookup metricFile xs
return $ CellPctChange $ ValueBaseline baseline value
| (metric, xs) <- M.toList mtrees
]
stderrCol :: M.Map lbl (M.Map MetricFile (MeanStddev Double))
-> MetricFile
-> SemiTable Column Cell
stderrCol mtrees metricFile =
col (StderrCol metricFile)
[ maybe CellMissing CellStderrRel $ M.lookup metricFile xs
| (_metric, xs) <- M.toList mtrees
]
data ValueBaseline a = ValueBaseline { baseline, value :: a }
deriving (Show)
showBoth :: (RealFloat a, Show a) => ValueBaseline a -> String
showBoth (ValueBaseline ref val) = show (ref, val)
newtype PctChange a = PctChange a
deriving (Show)
showsPctChange :: (Ord a, RealFloat a) => OutputOptions -> PctChange a -> ShowS
showsPctChange opts (PctChange percent) =
withColor opts color $ prettySign opts rel . showFFloat (Just 2) (abs rel) . showChar '%'
where
rel = percent - 100
color
| rel < 0 = Green
| rel > 0 = Red
| otherwise = White
toPctChange :: RealFloat a => ValueBaseline a -> PctChange a
toPctChange (ValueBaseline ref val) = PctChange ((val / ref) * 100)
showPercent :: (RealFloat a, Show a) => OutputOptions -> ValueBaseline a -> String
showPercent opts x = showsPctChange opts (toPctChange x) ""
data Relative a = Reference a
| Relative (ValueBaseline a)
| NoReference
showRelative :: (Ord a, RealFloat a, Show a)
=> (a -> ShowS) -> (ValueBaseline a -> String) -> Relative a -> String
showRelative showRef _showRel (Reference n) = showRef n ""
showRelative _showRef showRel (Relative vb) = showRel vb
showRelative _showRef _showRel NoReference = "no ref"
toRelativeChange :: (Ord r, Ord c, RealFrac a)
=> c
-> M.Map r (M.Map c a)
-> M.Map r (M.Map c (Relative a))
toRelativeChange ref xs = fmap f xs
where
f ys
| Just y0 <- M.lookup ref ys =
M.mapWithKey (\k y -> if k == ref then Reference y0 else Relative (ValueBaseline y0 y)) ys
| otherwise = fmap (const NoReference) ys
transpose :: (Ord r, Ord c)
=> M.Map r (M.Map c a)
-> M.Map c (M.Map r a)
transpose xs = M.fromListWith (<>)
[ (c, M.singleton r x)
| (r, cs) <- M.toList xs
, (c, x) <- M.toList cs
]
mean :: (Functor f, Foldable f, RealFloat a)
=> f a -> Maybe a
mean xs
| null xs = Nothing
| otherwise = Just $ (sum xs) / realToFrac (length xs)
data MeanStddev a = MeanStddev { msMean, msStddev :: a }
deriving (Show)
meanStddev :: (Functor f, Foldable f, RealFloat a)
=> f a -> Maybe (MeanStddev a)
meanStddev xs = do
mu <- mean xs
sigma <- fmap sqrt $ mean $ fmap (\x -> (x-mu)^2) xs
return $ MeanStddev mu sigma
meanStdErr :: (Functor f, Foldable f, RealFloat a)
=> f a -> Maybe (MeanStddev a)
meanStdErr xs = do
ms <- meanStddev xs
return ms { msStddev = msStddev ms / sqrt n }
where n = realToFrac $ length xs
geomMean :: (Functor f, Foldable f, RealFloat a)
=> f a -> Maybe a
geomMean = fmap exp . mean . fmap log'
where log' = log . max 0.05
geomMeanRow :: (Ord r, Ord c, RealFloat a)
=> M.Map r (M.Map c (Relative a))
-> SemiTable String (Maybe (PctChange a))
geomMeanRow xs =
row "geom mean" (M.elems $ fmap (fmap (PctChange . (*100)) . geomMean . mapMaybe ratios . M.elems) $ transpose xs)
where
ratios :: Fractional a => Relative a -> Maybe a
ratios (Relative (ValueBaseline ref val)) = Just (val / ref)
ratios _ = Nothing
runShowS :: ShowS -> String
runShowS = ($ [])
Copyright (c) 2019, Ben Gamari
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Ben Gamari nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GADTs #-}
module LabelMatch where
import Control.Applicative
import Control.Monad
import Data.String
import qualified Data.Text as T
import MeasurementTree (Label(..))
import qualified MeasurementTree as MTree
newtype LabelMatcher a = LabelMatcher (Label -> Maybe (Label, a))
deriving (Functor)
match :: LabelMatcher a -> Label -> Maybe a
match (LabelMatcher f) l = snd <$> f l
instance (a ~ ()) => IsString (LabelMatcher a) where
fromString = matchPart . fromString
instance Applicative LabelMatcher where
pure x = LabelMatcher $ \lbl -> Just (lbl, x)
(<*>) = ap
instance Alternative LabelMatcher where
LabelMatcher f <|> LabelMatcher g =
LabelMatcher $ \lbl -> f lbl <|> g lbl
empty = LabelMatcher $ const Nothing
instance Monad LabelMatcher where
LabelMatcher f >>= g = LabelMatcher $ \lbl ->
case f lbl of
Nothing -> Nothing
Just (lbl', x) -> let LabelMatcher h = g x
in h lbl'
matchPart :: T.Text -> LabelMatcher ()
matchPart s = LabelMatcher f
where
f (Label (x:xs))
| x == s = Just (Label xs, ())
f _ = Nothing
wildcard :: LabelMatcher String
wildcard = LabelMatcher f
where
f (Label (x:xs)) = Just (Label xs, T.unpack x)
f (Label []) = Nothing
end :: LabelMatcher ()
end = LabelMatcher f
where
f (Label []) = Just (Label [], ())
f (Label _) = Nothing
{-# LANGUAGE RecordWildCards, DeriveDataTypeable #-}
module Main(main) where
-- Standard libraries
import Control.Concurrent
import Control.Exception
import Control.Monad
import Data.Bifunctor
import Data.Char
import Data.Foldable
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import Data.Time.Clock
import qualified System.Directory as IO
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import System.Exit
import System.Info
import System.IO
import System.Process
import System.Console.CmdArgs
-- Shake - build system
import Development.Shake hiding ((*>))
import Development.Shake.FilePath hiding (exe)
import qualified MeasurementTree as MTree
import MeasurementTree (Measurements, Label(..))
import qualified ParseResults
import qualified CachegrindParse
import qualified PerfStatParse
ml = MTree.mkLabel
---------------------------------------------------------------------
-- TEST CONFIGURATION - which tests are available to run
-- | These are directories that contain tests.
testRoots :: [String]
testRoots = words "imaginary spectral real parallel spectral/hartel gc"
-- | These are tests that are under testRoots, but should be skipped (all are skipped by the Makefile system)
disabledTests :: [String]
disabledTests = words "hartel last-piece secretary triangle ebnf2ps HMMS PolyGP rx cfd dcbm linsolv warshall"
-- | These tests are compiled by the Makefile system, but don't work for me (mostly GHC 7.4 breaks)
newlyDisabledTests :: [String]
newlyDisabledTests = words "power lift fulsom fluid eff"
-- | Directories containing tests that the system can run.
allTests :: IO [FilePath]
allTests = do
xs <- forM testRoots $ \x -> do
ys <- IO.getDirectoryContents x
return [x </> y | y <- ys, '.' `notElem` y, y `notElem` disabledTests, y `notElem` newlyDisabledTests]
fmap sort $ flip filterM (concat xs) $ \x -> do
b <- IO.doesDirectoryExist x
if not b then return False else
IO.doesFileExist $ x </> "Makefile"
---------------------------------------------------------------------
-- ARGUMENT PARSING - mostly based on CmdArgs
data Nofib
= Clean
| Build
{clean :: Bool
,tests :: [String]
,way :: [String]
,threads :: Int
,compiler :: String
,compiler_args :: String
,tag :: String
,output :: String
,cachegrind :: Bool
,cachegrind_args :: String
,perf :: Bool
,perf_args :: String
,run :: Bool
,speed :: Speed
,rts_args :: [String]
,times :: Int
,skip_check :: Bool
}
deriving (Data, Show)
data Speed = Fast | Norm | Slow
deriving (Data, Show)
nofibMode :: Mode (CmdArgs Nofib)
nofibMode = cmdArgsMode $ modes
[Clean
&= help "Clean the build"
,Build
{clean = False &= groupname "Building" &= help "Clean before building"
,tests = [] &= args &= typ "TEST"
,way = [] &= help "Which way to build, defaults to -O1"
,threads = 1 &= name "j" &= typ "NUM" &= help "Number of threads, defaults to 1"
,compiler = "ghc" &= help "Compiler to use, defaults to ghc"
,compiler_args = "" &= help "Extra arguments to pass to the Compiler when building tests"
,tag = "" &= help "Tag to name the compiler, defaults to compiler --version"
,output = "" &= help "Where to put created files under _make, defaults to tag/way"
,cachegrind = False &= groupname "Running" &= help "Run the tests under cachegrind"
,cachegrind_args = "" &= groupname "Running" &= help "Extra arguments to pass to cachegrind"
,perf = False &= groupname "Running" &= help "Run the tests under `perf stat`"
,perf_args = "-e instructions,cycles,cache-misses,task-clock -r5" &= groupname "Running" &= help "Extra arguments to pass to `perf stat`"
,run = False &= groupname "Running" &= help "Run the tests"
,speed = Norm &= groupname "Running" &= help "Test speed (Fast,Norm,Slow)"
,times = 1 &= help "Number of times to run each test"
,rts_args = [] &= help "Which RTS options to pass when running"
,skip_check = False &= help "Skip checking the results of the tests"
} &= auto &= help "Build"
&= help "Build and run"
]
&= summary "Nofib benchmark suite"
-- | Create a clean set of arguments, with any defaults filled in
nofibArgs :: IO Nofib
nofibArgs = do
args <- cmdArgsRun nofibMode
case args of
Clean -> return args
Build{..} -> do
way <- return $ let xs = concatMap words way in if null xs then ["-O1"] else xs
tag <- if tag == "" then compilerTag compiler else return tag
tests <- resolveTests tests
output <- return $ "_make" </> (if null output then tag </> intercalate "_" way else output)
return Build{..}
-- | Given the tests the user asked for, expand them out, e.g. real is the full real suite.
resolveTests :: [String] -> IO [String]
resolveTests [] = allTests
resolveTests finds = do
let slash1 x = "/" ++ map (\i -> if i == '\\' then '/' else i) x
slash2 x = slash1 x ++ "/"
tests <- allTests
let whole = filter (\test -> any (\find -> slash2 find `isInfixOf` slash2 test) finds) tests -- whole matches
let prefix = filter (\test -> any (\find -> slash1 find `isInfixOf` slash2 test) finds) tests -- prefix matches
let res = if null whole then prefix else whole
when (null res) $
error $ "The targets failed to match any programs: " ++ unwords finds
return res
-- | Find the default compiler string, e.g. ghc-7.4.1
compilerTag :: String -> IO String
compilerTag compiler = do
(_,stdout,_) <- readProcessWithExitCode compiler ["--version"] ""
let ver = takeWhile (\x -> isDigit x || x == '.') $ dropWhile (not . isDigit) stdout
return $ if null ver then "unknown" else ver
---------------------------------------------------------------------
-- MAIN DRIVER
-- | Main program, just interpret the arguments and dispatch the tasks.
main = do
args <- nofibArgs
case args of
Clean -> removeDirectoryRecursive "_make"
Build{..} -> do
when clean $
removeDirectoryRecursive output
putStrLn $ "Running: " ++ unwords tests
shake shakeOptions
{shakeThreads=threads
,shakeFiles=output ++ "/"
,shakeReport=[output ++ "/shake_report.html"]
,shakeStaunch=True
,shakeVerbosity=Development.Shake.Loud} $
buildRules args
putStrLn "Build completed"
when run $ do
ns <- mapM (runTest args) tests
let tot = length ns
bad = length $ filter not ns
t i = if i == 1 then "1 test" else show i ++ " tests"
if bad == 0 then
putStrLn $ "Ran " ++ t tot ++ " successfully"
else
putStrLn $ "WARNING: " ++ t bad ++ " failed, out of " ++ t tot
-- | Rules to build the given tests. For each test, there are three files
-- we care about:
--
-- * config.txt - a cleaned up version of the configuration out of Makefile,
-- created by convertConfig. Also contains "MAIN" which points at the name
-- of the Main module.
--
-- * Main.exe - the actual binary, produced by ghc linking everything.
--
-- * Main.deps - the files that Main.exe depends on, ghc -M.
--
-- * .hi/.o - files produced by ghc -c.
--
-- * .result - the stdout and stderr output from the build
--
-- Most complication comes from modules not named Main, which still produce
-- Main.o object files (I think ghc -M gets these wrong).
buildRules :: Nofib -> Rules ()
buildRules nofib@Build{..} = do
r <- newResource "ghc linker" 1
let unoutput x =
let f x = if hasExtension x then f $ takeDirectory x else x
in f $ takeDirectory $ drop (length output + 1) x
want $ concat
[ [s </> "Main" <.> exe, s </> "config.txt"] | t <- tests, let s = output </> t]
when cachegrind $ want [ "cachegrind" ]
when perf $ want [ "perf" ]
"//all-results" %> \out -> do
let results = [ s </> "Main" <.> exe <.> "result"
| t <- tests
, let s = output </> t
]
need results
xs <- mapM readFileLines results
writeFileLines out (concat xs)
"//perf" %> \out -> do
let results = [ s </> "Main" <.> "perf" <.> "result"
| t <- tests
, let s = output </> t
]
need results
xs <- mapM readFileLines results
writeFileLines out (concat xs)
"//cachegrind" %> \out -> do
let results = [ s </> "Main" <.> "cachegrind" <.> "result"
| t <- tests
, let s = output </> t
]
need results
xs <- mapM readFileLines results
writeFileLines out (concat xs)
"//config.txt" %> \out -> do
let dir = unoutput out
src <- readFileLines $ dir </> "Makefile"
let poss = ["Main.hs","Main.lhs","Era.hs","SumEuler.hs",takeFileName dir <.> "hs",takeFileName dir <.> "lhs"]
bs <- filterM (doesFileExist . (dir </>)) poss
let mainMod = case bs of
[] -> error $ "Could not find Main file for " ++ dir
x:_ -> "MAIN = " ++ x
writeFileLines out $ mainMod : convertConfig src
["//Main" <.> exe, "//Main" <.> exe <.> "result", "//Main.results.json"] &%> \[out, result, resultsJson] -> do
deps <- readFile' $ replaceExtension out "deps"
let os = nub [ if isLower $ head $ takeFileName x then replaceExtension out "o" else output </> x
| x <- words deps, takeExtension x == ".o"]
need os
config <- readConfig' $ takeDirectory out </> "config.txt"
let dir = unoutput out
obj = takeDirectory out
name = takeFileName dir
resultHdl <- liftIO $ openFile result WriteMode
-- Add results from object compilation to results output
objectResults <- forM os $ \o -> do
ls <- liftIO $ BS.readFile (o <.> "result")
liftIO $ BS.hPutStr resultHdl ls
ms <- liftIO $ MTree.readFile (o <.> "results.json")
return ms
-- Link executable
liftIO $ hPutStrLn resultHdl $ "==nofib== " ++ name ++ " : time to link " ++ name ++ " follows..."
compileArgs <- liftIO $ getTestCompileArgs nofib dir
Stdouterr out_err <- withResource r 1 $
cmd compiler $ ["-Rghc-timing","-rtsopts","-o", out] ++ os ++ way ++ compileArgs
liftIO $ BS.hPutStr resultHdl out_err
liftIO $ hPutStrLn resultHdl $ "==nofib== " ++ name ++ ": size of " ++ name ++ " follows..."
-- Report executable size
Stdout out_err <- cmd "size" [out]
let execSize = ParseResults.parseCodeSize $ BS.unpack out_err
liftIO $ BS.hPutStr resultHdl out_err
liftIO $ hClose resultHdl
liftIO $ MTree.writeFile resultsJson
$ fold objectResults
<> MTree.singleton (ml "executable size") (realToFrac execSize)
["//*.o","//*.hi","//*.o.result","//*.o.results.json"] &%> \[o,hi,result,resultsJson] -> do
let dir = unoutput o
obj = output </> dir
config <- readConfig' $ obj </> "config.txt"
let mod = let x = dropExtension $ drop (length obj + 1) o
in if x == "Main" then dropExtension $ config "MAIN" else x
src <- do b <- doesFileExist $ dir </> mod <.> "hs"
return $ dir </> mod <.> (if b then "hs" else "lhs")
deps <- readFileLines $ obj </> "Main.deps"
need [ if takeExtension r `elem` [".h",".hs",".lhs"] then r else output </> r
| lhs:":":rhs <- map words $ deps, dir </> mod <.> "o" == lhs, r <- rhs]
let test = takeFileName dir
resultHdl <- liftIO $ openFile result WriteMode
liftIO $ hPutStrLn resultHdl $ "==nofib== " ++ test ++ " : time to compile " ++ mod ++ " follows..."
let rts_args = [ "+RTS", "--machine-readable", "-t"++o++".stats" ]
compileArgs <- liftIO $ getTestCompileArgs nofib dir
Stdouterr out_err <- cmd compiler $ ["-Rghc-timing","-c",src,"-w","-i"++obj,"-odir="++obj,"-hidir="++obj] ++
way ++ compileArgs ++ [compiler_args] ++ rts_args
liftIO $ BS.hPutStr resultHdl out_err
liftIO $ hPutStrLn resultHdl $ "==nofib== " ++ test ++ ": size of " ++ takeFileName o ++ " follows..."
Stdout out_err <- cmd "size" [o]
liftIO $ BS.hPutStr resultHdl out_err
rtsStats <- liftIO $ readRtsStats $ o++".stats"
liftIO $ MTree.writeFile resultsJson
$ MTree.prefix (MTree.mkLabel test <> ml "objects" <> MTree.mkLabel (takeFileName o))
$ MTree.singleton (ml "size") (realToFrac $ ParseResults.parseCodeSize $ BS.unpack out_err)
<> MTree.prefix (ml "rts stats") rtsStats
liftIO $ hClose resultHdl
"//Main.deps" %> \out -> do
let dir = unoutput out
config <- readConfig' $ takeDirectory out </> "config.txt"
compileArgs <- liftIO $ getTestCompileArgs nofib dir
cmd_ compiler $
[ "-w"
, "-M",dir </> config "MAIN"
, "-i" ++ dir
, "-dep-makefile=" ++ out
, "-dep-suffix", ""
] ++ compileArgs
src <- liftIO $ readFile out
need [x | x <- words src, takeExtension x `elem` [".hs",".lhs",".h"]]
["//Main.perf.result", "//Main.perf.results.json"] &%> \[out, resultsJson] -> do
need [takeDirectory out </> "config.txt"]
need [replaceExtensions out exe]
let test = unoutput out
(stdin, args) <- liftIO $ getTestCmdline nofib test
executable <- liftIO $ IO.canonicalizePath $ output </> test </> "Main" <.> exe
let rtsStatsOut = executable <.> "stats"
out' <- liftIO $ IO.canonicalizePath out
liftIO $ writeFile out "" -- truncate output
replicateM_ times $ cmd_ (Cwd test) (EchoStdout False) (StdinBS stdin)
"perf" "stat" perf_args "-x," ("--output="++out') "--append" "--"
executable args "+RTS" rts_args "--machine-readable" ("-t"++rtsStatsOut)
stats <- liftIO $ PerfStatParse.readPerfStat out'
liftIO $ MTree.writeFile resultsJson
$ MTree.fromList
[ (MTree.mkLabel test <> ml "run" <> ml "perf" <> lbl, v)
| (eventName, vs) <- M.toList stats
, v <- vs
, let lbl = MTree.mkLabel $ PerfStatParse.getEventName eventName
]
["//Main.cachegrind.result", "//Main.cachegrind.results.json"] &%> \[out, resultsJson] -> do
need [takeDirectory out </> "config.txt"]
need [replaceExtensions out exe]
let test = unoutput out
(stdin, args) <- liftIO $ getTestCmdline nofib test
executable <- liftIO $ IO.canonicalizePath $ output </> test </> "Main" <.> exe
let rtsStatsOut = executable <.> "stats"
out' <- liftIO $ IO.canonicalizePath out
cmd_ (Cwd test) (EchoStdout False) (StdinBS stdin)
"valgrind" "--tool=cachegrind" cachegrind_args ("--cachegrind-out-file="++out')
executable args "+RTS" rts_args "--machine-readable" ("-t"++rtsStatsOut)
stats <- liftIO $ CachegrindParse.parse out'
rtsStats <- liftIO $ readRtsStats rtsStatsOut
liftIO $ MTree.writeFile resultsJson
$ MTree.fromList
[ (MTree.mkLabel test <> ml "run" <> ml "cachegrind" <> lbl, realToFrac v)
| (eventName, v) <- M.toList stats
, let lbl = MTree.mkLabel $ CachegrindParse.getEventName eventName
]
<> MTree.prefix (MTree.mkLabel test <> ml "run" <> ml "rts stats") rtsStats
where
objectsForExecutable :: FilePath -> Action [FilePath]
objectsForExecutable executable = do
deps <- readFile' $ replaceExtension executable "deps"
return $ nub [ if isLower $ head $ takeFileName x then replaceExtension executable "o" else output </> x
| x <- words deps, takeExtension x == ".o"]
getTestCompileArgs :: Nofib -> String -> IO [String]
getTestCompileArgs nofib@Build{..} test = do
config <- readConfig $ output </> test </> "config.txt"
return $ words (config "SRC_HC_OPTS")
++ concat [ ["-package", pkg] | pkg <- words (config "SRC_DEPS") ]
getTestCmdline :: Nofib -> String -> IO (BSL.ByteString, [String])
getTestCmdline nofib@Build{..} test = do
config <- readConfig $ output </> test </> "config.txt"
let args = words (config "PROG_ARGS")
++ words (config $ map toUpper (show speed) ++ "_OPTS")
stdin_path <-
let s = config "STDIN_FILE"
in if s == ""
then grab "stdin"
else pure $ Just $ test </> s
putStrLn $ "test " <> test <> " stdin: " <> show stdin_path
stdin <- maybe (pure BSL.empty) BSL.readFile stdin_path
return (stdin, args)
where
grab :: String -> IO (Maybe FilePath)
grab ext = do
let s = [test </> takeFileName test <.> map toLower (show speed) ++ ext
,test </> takeFileName test <.> ext]
ss <- filterM IO.doesFileExist s
return $ listToMaybe ss
readRtsStats :: FilePath -> IO (Measurements Double)
readRtsStats fname = do
rtsStats <- ParseResults.parseRtsStats <$> readFile fname
return $ MTree.fromList $ map (first MTree.mkLabel) $ M.toList rtsStats
-- | Run a test, checking stdout/stderr are as expected, and reporting time.
-- Return True if the test passes.
runTest :: Nofib -> String -> IO Bool
runTest nofib@Build{..} test = do
putStrLn $ "==nofib== " ++ takeDirectory1 test ++ ": time to run " ++ takeDirectory1 test ++ " follows..."
(stdin, args) <- getTestCmdline nofib test
stats <- IO.canonicalizePath $ output </> test </> "stat.txt"
executable <- liftIO $ IO.canonicalizePath $ output </> test </> "Main" <.> exe
fmap and $ replicateM times $ do
start <- getCurrentTime
(code,stdout,stderr) <- readProcessWithExitCodeAndWorkingDirectory
test executable (args++"+RTS":rts_args++["--machine-readable", "-t"++stats]) stdin
end <- getCurrentTime
stdoutWant <- grab "stdout"
stderrWant <- grab "stderr"
BSL.writeFile (output </> test </> "stdout") stdout
BSL.writeFile (output </> test </> "stderr") stderr
putStrLn $ show (floor $ fromRational (toRational $ end `diffUTCTime` start) * 1000) ++ "ms"
putStr =<< readFile stats
rtsStats <- readRtsStats stats
MTree.writeFile (output </> test </> "run.results.json")
$ MTree.prefix (MTree.mkLabel test <> ml "run" <> ml "rts stats") rtsStats
err <- return $
if not skip_check && stderr /= stderrWant then "FAILED STDERR\nWANTED: " ++ snip stderrWant ++ "\nGOT: " ++ snip stderr
else if not skip_check && stdout /= stdoutWant then "FAILED STDOUT\nWANTED: " ++ snip stdoutWant ++ "\nGOT: " ++ snip stdout
else if not skip_check && code /= ExitSuccess then "FAILED EXIT CODE " ++ show code
else ""
if null err then return True else putStrLn err >> return False
where
snip :: BSL.ByteString -> String
snip x = if BSL.length x > 200 then BSL.unpack (BSL.take 200 x) ++ "..." else BSL.unpack x
grab :: String -> IO BSL.ByteString
grab ext = do
let s = [test </> takeFileName test <.> map toLower (show speed) ++ ext
,test </> takeFileName test <.> ext]
ss <- filterM IO.doesFileExist s
maybe (return BSL.empty) BSL.readFile $ listToMaybe ss
---------------------------------------------------------------------
-- CONFIGURATION UTILITIES
-- The Makefile's are slurped for configuration, to produce a cleaned-up config file
-- | Given the source of a Makefile, slurp out the configuration strings.
convertConfig :: [String] -> [String]
convertConfig xs =
[ k ++ " = " ++ v
| (k, v) <- M.toList vars
]
where
vars =
M.fromListWith (\a b -> a ++ " " ++ b)
[ (remap a, b)
| x <- xs
, let (a,b) = separate x, a `elem` keep
]
keep = words "PROG_ARGS SRC_HC_OPTS SLOW_OPTS NORM_OPTS FAST_OPTS STDIN_FILE SRC_DEPS"
remap x = x
separate x = (name,rest)
where (name,x2) = span (\x -> isAlpha x || x == '_') x
rest = dropWhile isSpace $ dropWhile (`elem` "+=") $ dropWhile isSpace x2
-- | Read a configuration file (new format) into a function supplying options.
readConfig :: FilePath -> IO (String -> String)
readConfig x = do
src <- readFile x
let res = [ (reverse $ dropWhile isSpace $ reverse a, dropWhile isSpace $ drop 1 b)
| y <- lines src, let (a,b) = break (== '=') y]
return $ \x -> fromMaybe "" $ lookup x res
-- | readConfig lifted into the Action monad.
readConfig' :: FilePath -> Action (String -> String)
readConfig' x = do
need [x]
liftIO $ readConfig x
---------------------------------------------------------------------
-- GENERAL UTILITIES
-- | The executable extension on this platform.
exe :: String
exe = if os == "mingw32" then "exe" else ""
-- | Like the standard removeDirectoryRecursive, but doesn't fail if the path is missing.
removeDirectoryRecursive :: FilePath -> IO ()
removeDirectoryRecursive x = do
b <- IO.doesDirectoryExist x
when b $ IO.removeDirectoryRecursive x
-- | Source for readProcessWithExitCode, plus addition of cwd
readProcessWithExitCodeAndWorkingDirectory
:: FilePath -- ^ directory to use
-> FilePath -- ^ command to run
-> [String] -- ^ any arguments
-> BSL.ByteString -- ^ standard input
-> IO (ExitCode, BSL.ByteString, BSL.ByteString) -- ^ exitcode, stdout, stderr
readProcessWithExitCodeAndWorkingDirectory cwd cmd args input = do
(Just inh, Just outh, Just errh, pid) <-
createProcess (proc cmd args){ cwd = Just cwd,
std_in = CreatePipe,
std_out = CreatePipe,
std_err = CreatePipe }
outMVar <- newEmptyMVar
out <- BSL.hGetContents outh
_ <- forkIO $ evaluate (BSL.length out) >> putMVar outMVar ()
err <- BSL.hGetContents errh
_ <- forkIO $ evaluate (BSL.length err) >> putMVar outMVar ()
when (not (BSL.null input)) $ do BSL.hPutStr inh input; hFlush inh
hClose inh
takeMVar outMVar
takeMVar outMVar
hClose outh
hClose errh
ex <- waitForProcess pid
return (ex, out, err)
{-# LANGUAGE OverloadedStrings #-}
import Data.Foldable
import Options.Applicative
import qualified Data.ByteString.Lazy as BS
import qualified Data.Csv as Csv
import qualified MeasurementTree as MTree
import MeasurementTree (Measurements, Label)
args :: Parser (FilePath, [FilePath], Bool)
args =
(,,)
<$> option str (long "output" <> short 'o' <> help "output file")
<*> some (argument str (metavar "FILE" <> help "results.json files"))
<*> switch (long "csv" <> short 'c' <> help "produce CSV output")
main :: IO ()
main = do
(output, files, csv) <- execParser $ info (helper <*> args) mempty
trees <- mapM MTree.readFile files
let result = fold trees
if csv
then MTree.writeFileCsv output result
else MTree.writeFile output result
module ParseResults
( parseCodeSize
, parseRtsStats
) where
import qualified Data.Map.Strict as M
import Data.Maybe
-- | Parse text section size out of Berkley-format @size@ output
parseCodeSize :: String -> Integer
parseCodeSize content
| header : sizes : _ <- lines content
, "text" : _ <- words header =
read $ head $ words sizes
| otherwise = error "unrecognized size output"
parseRtsStats :: String -> M.Map String Double
parseRtsStats = foldMap parseValue . readPairs . dropFirstLine
where
parseValue (name, value)
| (x, ""):_ <- reads value = M.singleton name x
| otherwise = M.empty
dropFirstLine = unlines . drop 1 . lines
readPairs :: String -> [(String, String)]
readPairs s
| (x, _):_ <- reads s = x
| otherwise = error $ "Failed to parse RTS statistics: " ++ s
{-# LANGUAGE OverloadedStrings #-}
module PerfStatParse (readPerfStat, EventName(..)) where
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Data.Map as M
newtype EventName = EventName { getEventName :: String }
deriving (Show, Eq, Ord)
-- | Read metrics from @perf stat -x,@ invocation.
readPerfStat :: FilePath -> IO (M.Map EventName [Double])
readPerfStat path = do
parsePerfStat <$> TIO.readFile path
parsePerfStat :: T.Text -> M.Map EventName [Double]
parsePerfStat = M.unionsWith (++) . map parseLine . T.lines
where
parseLine line
| "#" `T.isPrefixOf` line = mempty
| value:_:metric:_ <- T.splitOn "," line
, (val, "") : _ <- reads $ T.unpack value
= M.singleton (EventName $ T.unpack metric) [val]
| otherwise = mempty
import Distribution.Simple
main = defaultMain
cabal-version: >=1.10
name: nofib
version: 0.1.0.0
-- synopsis:
-- description:
-- bug-reports:
license: BSD3
license-file: LICENSE
author: Ben Gamari
maintainer: ben@smart-cactus.org
-- copyright:
-- category:
build-type: Simple
library
exposed-modules: MeasurementTree
hs-source-dirs: src
build-depends: base >=4.10 && <4.13,
aeson,
these >= 0.8,
containers,
cassava,
text,
vector,
bytestring
default-language: Haskell2010
executable nofib-run
main-is: Main.hs
other-modules: CachegrindParse, PerfStatParse, ParseResults
other-extensions: RecordWildCards, DeriveDataTypeable
build-depends: base >=4.10 && <4.13,
time >=1.8 && <1.9,
containers,
bytestring,
directory >=1.3 && <1.4,
process >=1.6 && <1.7,
text,
cmdargs,
shake,
nofib
default-language: Haskell2010
executable nofib-compare
main-is: Compare.hs
other-modules: LabelMatch
other-extensions: RecordWildCards, DeriveDataTypeable
build-depends: base >=4.10 && <4.13,
these,
containers,
directory,
filepath,
text,
aeson,
ansi-wl-pprint,
tabular,
these,
semialign,
optparse-applicative,
ansi-terminal,
nofib
default-language: Haskell2010
executable nofib-merge
main-is: Merge.hs
build-depends: base >=4.10 && <4.13,
optparse-applicative,
cassava,
bytestring,
nofib
default-language: Haskell2010
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
module MeasurementTree
( -- * Labels
-- | A label hierarchically identifies a type of measurement (e.g.
-- @T1234//bytes allocated@)
Label(..)
, mkLabel
, encodeLabel
-- * Measurements
, Measurements(..)
, toMap
, fromMap
, prefix
, singleton
, fromList
-- ** I/O with JSON representation