Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixup shake-bench #63

Merged
merged 1 commit into from Jan 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions shake-bench/shake-bench.cabal
Expand Up @@ -27,6 +27,8 @@ library
directory,
extra >= 1.7.2,
filepath,
lens,
lens-aeson,
shake,
text
default-language: Haskell2010
Expand Down
31 changes: 18 additions & 13 deletions shake-bench/src/Development/Benchmark/Rules.hs
Expand Up @@ -68,16 +68,19 @@ module Development.Benchmark.Rules

import Control.Applicative
import Control.Monad
import Control.Lens ((^.))
import Data.Aeson (FromJSON (..),
ToJSON (..),
Value (..), (.!=),
(.:?))
Value (..), object, (.!=),
(.:?), (.=))
import Data.Aeson.Lens (_Object)
import Data.Char (isDigit)
import Data.List (find, isInfixOf,
stripPrefix,
transpose)
import Data.List.Extra (lower)
import Data.Maybe (fromMaybe)
import Data.String (fromString)
import Data.Text (Text)
import qualified Data.Text as T
import Development.Shake
Expand All @@ -88,7 +91,6 @@ import GHC.Exts (IsList (toList),
import GHC.Generics (Generic)
import GHC.Stack (HasCallStack)
import qualified Graphics.Rendering.Chart.Backend.Diagrams as E
import Graphics.Rendering.Chart.Easy ((.=))
import qualified Graphics.Rendering.Chart.Easy as E
import System.Directory (createDirectoryIfMissing,
findExecutable,
Expand Down Expand Up @@ -498,21 +500,24 @@ data GitCommit = GitCommit

instance FromJSON GitCommit where
parseJSON (String s) = pure $ GitCommit s Nothing Nothing True
parseJSON (Object (toList -> [(name, String gitName)])) =
pure $ GitCommit gitName (Just name) Nothing True
parseJSON (Object (toList -> [(name, Object props)])) =
GitCommit
<$> props .:? "git" .!= name
<*> pure (Just name)
<*> props .:? "parent"
<*> props .:? "include" .!= True
parseJSON o@(Object _) = do
let keymap = o ^. _Object
case toList keymap of
[(name, String gitName)] -> pure $ GitCommit gitName (Just (fromString $ show name)) Nothing True
[(name, Object props)] ->
GitCommit
<$> props .:? "git" .!= name
<*> pure (Just (fromString $ show name))
<*> props .:? "parent"
<*> props .:? "include" .!= True
_ -> empty
parseJSON _ = empty

instance ToJSON GitCommit where
toJSON GitCommit {..} =
case name of
Nothing -> String gitName
Just n -> Object $ fromList [(n, String gitName)]
Just n -> object [fromString (T.unpack n) .= String gitName]

humanName :: GitCommit -> Text
humanName GitCommit {..} = fromMaybe gitName name
Expand Down Expand Up @@ -607,7 +612,7 @@ plotDiagram :: Bool -> Diagram -> FilePath -> Action ()
plotDiagram includeFailed t@Diagram {traceMetric, runLogs} out = do
let extract = frameMetric traceMetric
liftIO $ E.toFile E.def out $ do
E.layout_title .= title t
E.layout_title E..= title t
E.setColors myColors
forM_ runLogs $ \rl ->
when (includeFailed || runSuccess rl) $ E.plot $ do
Expand Down