pipe benchmark result to diff directly
This commit is contained in:
parent
5fb5518c07
commit
030b96b4a4
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:
|
ps_bridge:
|
||||||
cabal run exe:agora-purescript-bridge -- -o $(PS_BRIDGE_OUTPUT_DIR)
|
cabal run exe:agora-purescript-bridge -- -o $(PS_BRIDGE_OUTPUT_DIR)
|
||||||
|
|
||||||
|
BENCH_OUTPUT = "bench.csv"
|
||||||
bench:
|
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:
|
bench_check:
|
||||||
(cabal run agora-bench -- -o "$(BENCH_TMPFILE)" \
|
cabal -v0 new-run agora-bench | diff bench.csv -
|
||||||
|| $(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)
|
|
||||||
|
|
||||||
scripts:
|
scripts:
|
||||||
cabal run agora-scripts -- -c
|
cabal run agora-scripts -- -c
|
||||||
|
|
|
||||||
|
|
@ -3,10 +3,10 @@ module Main (main) where
|
||||||
import Bench (specificationTreeToBenchmarks)
|
import Bench (specificationTreeToBenchmarks)
|
||||||
import Data.Csv (EncodeOptions (encUseCrLf), defaultEncodeOptions, encodeDefaultOrderedByNameWith)
|
import Data.Csv (EncodeOptions (encUseCrLf), defaultEncodeOptions, encodeDefaultOrderedByNameWith)
|
||||||
import Data.Text.Lazy.Encoding (decodeUtf8)
|
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 Options (Options (..), parseOptions)
|
||||||
import Prettyprinter (defaultLayoutOptions, layoutPretty, pretty)
|
import Prettyprinter (defaultLayoutOptions, layoutPretty, pretty)
|
||||||
import Prettyprinter.Render.String (renderString)
|
import Prettyprinter.Render.Text (renderLazy)
|
||||||
import Spec.AuthorityToken qualified as AuthorityToken
|
import Spec.AuthorityToken qualified as AuthorityToken
|
||||||
import Spec.Effect.GovernorMutation qualified as GovernorMutation
|
import Spec.Effect.GovernorMutation qualified as GovernorMutation
|
||||||
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
|
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.Proposal qualified as Proposal
|
||||||
import Spec.Stake qualified as Stake
|
import Spec.Stake qualified as Stake
|
||||||
import Spec.Treasury qualified as Treasury
|
import Spec.Treasury qualified as Treasury
|
||||||
|
import System.IO (hIsTerminalDevice, stdout)
|
||||||
import Test.Specification (group)
|
import Test.Specification (group)
|
||||||
import Prelude
|
import Prelude
|
||||||
|
|
||||||
|
|
@ -22,11 +23,14 @@ import Prelude
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
options <- parseOptions
|
options <- parseOptions
|
||||||
|
isTTY <- hIsTerminalDevice stdout
|
||||||
|
|
||||||
I.writeFile options.output $
|
mapM_ (`I.writeFile` csv) options.output
|
||||||
(decodeUtf8 . encodeDefaultOrderedByNameWith encodeOptions) res
|
|
||||||
|
|
||||||
mapM_ (putStrLn . renderString . layoutPretty defaultLayoutOptions . pretty) res
|
I.putStr $
|
||||||
|
if isTTY
|
||||||
|
then prettified
|
||||||
|
else csv
|
||||||
where
|
where
|
||||||
encodeOptions =
|
encodeOptions =
|
||||||
defaultEncodeOptions
|
defaultEncodeOptions
|
||||||
|
|
@ -49,3 +53,7 @@ main = do
|
||||||
, group "AuthorityToken" AuthorityToken.specs
|
, group "AuthorityToken" AuthorityToken.specs
|
||||||
, group "Governor" Governor.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
|
module Options (Options (..), parseOptions) where
|
||||||
|
|
||||||
|
import Control.Applicative (optional)
|
||||||
import Options.Applicative ((<**>))
|
import Options.Applicative ((<**>))
|
||||||
import Options.Applicative qualified as Opt
|
import Options.Applicative qualified as Opt
|
||||||
|
|
||||||
newtype Options = Options
|
newtype Options = Options
|
||||||
{ output :: FilePath
|
{ output :: Maybe FilePath
|
||||||
}
|
}
|
||||||
|
|
||||||
outputOpt :: Opt.Parser FilePath
|
outputOpt :: Opt.Parser (Maybe FilePath)
|
||||||
outputOpt =
|
outputOpt =
|
||||||
Opt.strOption
|
optional $
|
||||||
( Opt.long "output-path"
|
Opt.strOption
|
||||||
<> Opt.short 'o'
|
( Opt.long "output-path"
|
||||||
<> Opt.metavar "OUTPUT_PATH"
|
<> Opt.short 'o'
|
||||||
<> Opt.value "./bench.csv"
|
<> Opt.metavar "OUTPUT_PATH"
|
||||||
<> Opt.help "The path of the bench report file."
|
<> Opt.help "The path of the bench report file."
|
||||||
)
|
)
|
||||||
|
|
||||||
benchOpt :: Opt.Parser Options
|
benchOpt :: Opt.Parser Options
|
||||||
benchOpt = Options <$> outputOpt
|
benchOpt = Options <$> outputOpt
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue