pipe benchmark result to diff directly
This commit is contained in:
parent
8f3423c451
commit
968409cf34
3 changed files with 26 additions and 23 deletions
12
Makefile
12
Makefile
|
|
@ -57,18 +57,12 @@ PS_BRIDGE_OUTPUT_DIR := agora-purescript-bridge/
|
|||
ps_bridge:
|
||||
cabal run exe:agora-purescript-bridge -- -o $(PS_BRIDGE_OUTPUT_DIR)
|
||||
|
||||
BENCH_OUTPUT = "bench.csv"
|
||||
bench:
|
||||
cabal run agora-bench
|
||||
cabal run agora-bench -- -o $(BENCH_OUTPUT)
|
||||
|
||||
BENCH_TMPDIR := $(shell mktemp -d)
|
||||
BENCH_TMPFILE := $(BENCH_TMPDIR)/bench.csv
|
||||
bench_check:
|
||||
(cabal run agora-bench -- -o "$(BENCH_TMPFILE)" \
|
||||
|| $(bench) -o "$(BENCH_TMPFILE)") >> /dev/null
|
||||
diff bench.csv $(BENCH_TMPFILE) \
|
||||
|| (echo "bench.csv is outdated"; exit 1)
|
||||
# TODO: do the clean-up even if `diff` fails.
|
||||
rm -rf $(BENCH_TMPDIR)
|
||||
cabal -v0 new-run agora-bench | diff bench.csv -
|
||||
|
||||
scripts:
|
||||
cabal run agora-scripts -- -c
|
||||
|
|
|
|||
|
|
@ -3,10 +3,10 @@ module Main (main) where
|
|||
import Bench (specificationTreeToBenchmarks)
|
||||
import Data.Csv (EncodeOptions (encUseCrLf), defaultEncodeOptions, encodeDefaultOrderedByNameWith)
|
||||
import Data.Text.Lazy.Encoding (decodeUtf8)
|
||||
import Data.Text.Lazy.IO as I (writeFile)
|
||||
import Data.Text.Lazy.IO as I (putStr, writeFile)
|
||||
import Options (Options (..), parseOptions)
|
||||
import Prettyprinter (defaultLayoutOptions, layoutPretty, pretty)
|
||||
import Prettyprinter.Render.String (renderString)
|
||||
import Prettyprinter.Render.Text (renderLazy)
|
||||
import Spec.AuthorityToken qualified as AuthorityToken
|
||||
import Spec.Effect.GovernorMutation qualified as GovernorMutation
|
||||
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
|
||||
|
|
@ -14,6 +14,7 @@ import Spec.Governor qualified as Governor
|
|||
import Spec.Proposal qualified as Proposal
|
||||
import Spec.Stake qualified as Stake
|
||||
import Spec.Treasury qualified as Treasury
|
||||
import System.IO (hIsTerminalDevice, stdout)
|
||||
import Test.Specification (group)
|
||||
import Prelude
|
||||
|
||||
|
|
@ -22,11 +23,14 @@ import Prelude
|
|||
main :: IO ()
|
||||
main = do
|
||||
options <- parseOptions
|
||||
isTTY <- hIsTerminalDevice stdout
|
||||
|
||||
I.writeFile options.output $
|
||||
(decodeUtf8 . encodeDefaultOrderedByNameWith encodeOptions) res
|
||||
mapM_ (`I.writeFile` csv) options.output
|
||||
|
||||
mapM_ (putStrLn . renderString . layoutPretty defaultLayoutOptions . pretty) res
|
||||
I.putStr $
|
||||
if isTTY
|
||||
then prettified
|
||||
else csv
|
||||
where
|
||||
encodeOptions =
|
||||
defaultEncodeOptions
|
||||
|
|
@ -49,3 +53,7 @@ main = do
|
|||
, group "AuthorityToken" AuthorityToken.specs
|
||||
, group "Governor" Governor.specs
|
||||
]
|
||||
|
||||
csv = decodeUtf8 $ encodeDefaultOrderedByNameWith encodeOptions res
|
||||
|
||||
prettified = renderLazy $ layoutPretty defaultLayoutOptions $ pretty res
|
||||
|
|
|
|||
|
|
@ -1,21 +1,22 @@
|
|||
module Options (Options (..), parseOptions) where
|
||||
|
||||
import Control.Applicative (optional)
|
||||
import Options.Applicative ((<**>))
|
||||
import Options.Applicative qualified as Opt
|
||||
|
||||
newtype Options = Options
|
||||
{ output :: FilePath
|
||||
{ output :: Maybe FilePath
|
||||
}
|
||||
|
||||
outputOpt :: Opt.Parser FilePath
|
||||
outputOpt :: Opt.Parser (Maybe FilePath)
|
||||
outputOpt =
|
||||
Opt.strOption
|
||||
( Opt.long "output-path"
|
||||
<> Opt.short 'o'
|
||||
<> Opt.metavar "OUTPUT_PATH"
|
||||
<> Opt.value "./bench.csv"
|
||||
<> Opt.help "The path of the bench report file."
|
||||
)
|
||||
optional $
|
||||
Opt.strOption
|
||||
( Opt.long "output-path"
|
||||
<> Opt.short 'o'
|
||||
<> Opt.metavar "OUTPUT_PATH"
|
||||
<> Opt.help "The path of the bench report file."
|
||||
)
|
||||
|
||||
benchOpt :: Opt.Parser Options
|
||||
benchOpt = Options <$> outputOpt
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue