From ced9acff3719b5d62fda8a95eaebaa0b056e407e Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 3 Jan 2018 12:06:10 +0100 Subject: [PATCH 1/3] Remove location from metadata The current location metadata is always null. The user may set an actual location on the command line. --- src/Hyperion/Main.hs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Hyperion/Main.hs b/src/Hyperion/Main.hs index fb2d081..3642f5a 100644 --- a/src/Hyperion/Main.hs +++ b/src/Hyperion/Main.hs @@ -267,13 +267,11 @@ doAnalyze Config{..} cinfo bks = do | otherwise = reportMeasurements .~ Nothing report = results & imapped %@~ analyze & mapped %~ strip now <- getCurrentTime - let -- TODO Use output of hostname(1) as reasonable default. - hostId = Nothing :: Maybe Text - metadata = + let metadata = configUserMetadata -- Prepend user metadata so that the user can rewrite @timestamp@, -- for instance. - <> HashMap.fromList [ "timestamp" JSON..= now, "location" JSON..= hostId ] + <> HashMap.fromList [ "timestamp" JSON..= now ] void $ bracket (mapM (openReportHandle cinfo) $ Set.toList configReportOutputs) From 2756ec7a0049e20aa1b18cdd0273ff1612f00b5f Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 3 Jan 2018 12:10:50 +0100 Subject: [PATCH 2/3] Split analysis from analysis reporting This allows users of the library to call `doAnalyze` and work on the results, rather than having to re-implement it. --- src/Hyperion/Main.hs | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/Hyperion/Main.hs b/src/Hyperion/Main.hs index 3642f5a..3eec811 100644 --- a/src/Hyperion/Main.hs +++ b/src/Hyperion/Main.hs @@ -210,6 +210,24 @@ doRun strategy bks = do throwIO $ DuplicateIdentifiers [ n | n:_:_ <- group (sort ids) ] foldMap (runBenchmark strategy) bks +reportAnalysis + :: Config + -> ContextInfo -- ^ Benchmark context information. + -> HashMap BenchmarkId Report + -> IO () +reportAnalysis config cinfo report = do + now <- getCurrentTime + let metadata = + configUserMetadata config + -- Prepend user metadata so that the user can rewrite @timestamp@, + -- for instance. + <> HashMap.fromList [ "timestamp" JSON..= now ] + void $ bracket + (mapM (openReportHandle cinfo) + $ Set.toList (configReportOutputs config)) + (mapM_ closeReportHandle) + (mapM (\h -> printReport h metadata report)) + -- | Print the report. printReport :: ReportOutput IO.Handle @@ -257,26 +275,15 @@ closeReportHandle (ReportJsonFlat h) = IO.hClose h doAnalyze :: Config -- ^ Hyperion config. - -> ContextInfo -- ^ Benchmark context information. -> [Benchmark] -- ^ Benchmarks to be run. - -> IO () -doAnalyze Config{..} cinfo bks = do + -> IO (HashMap BenchmarkId Report) +doAnalyze Config{..} bks = do results <- doRun (indexedStrategy Config{..}) bks let strip | configRaw = id | otherwise = reportMeasurements .~ Nothing report = results & imapped %@~ analyze & mapped %~ strip - now <- getCurrentTime - let metadata = - configUserMetadata - -- Prepend user metadata so that the user can rewrite @timestamp@, - -- for instance. - <> HashMap.fromList [ "timestamp" JSON..= now ] - void $ bracket - (mapM (openReportHandle cinfo) - $ Set.toList configReportOutputs) - (mapM_ closeReportHandle) - (mapM (\h -> printReport h metadata report)) + pure report defaultMainWith :: ConfigMonoid -- ^ Preset Hyperion config. @@ -302,7 +309,7 @@ defaultMainWith presetConfig packageName bks = do Run -> do _ <- doRun (indexedStrategy config) bks return () - Analyze -> doAnalyze config cinfo bks + Analyze -> doAnalyze config bks >>= reportAnalysis config cinfo defaultMain :: String -- ^ Package name, user provided. From 4c6456189529a641a4411b93cdba1c3763be136e Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Wed, 3 Jan 2018 18:06:30 +0100 Subject: [PATCH 3/3] Export analysis related functions --- examples/end-to-end-benchmarks.hs | 2 +- src/Hyperion/Main.hs | 14 +++++++++++--- tests/Hyperion/MainSpec.hs | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/end-to-end-benchmarks.hs b/examples/end-to-end-benchmarks.hs index 994a7ed..05fc69e 100755 --- a/examples/end-to-end-benchmarks.hs +++ b/examples/end-to-end-benchmarks.hs @@ -20,7 +20,7 @@ benchmarks = main :: IO () main = defaultMainWith config "hyperion-example-end-to-end" benchmarks where - config = defaultConfig + config = defaultConfigMonoid { configMonoidSamplingStrategy = pure $ timeBound (fromSeconds 5) (repeat 10) } diff --git a/src/Hyperion/Main.hs b/src/Hyperion/Main.hs index 3eec811..57e71d6 100644 --- a/src/Hyperion/Main.hs +++ b/src/Hyperion/Main.hs @@ -8,11 +8,16 @@ module Hyperion.Main ( defaultMain , Mode(..) + , Config(..) , ConfigMonoid(..) , ReportOutput(..) + , configFromMonoid , nullOutputPath , defaultConfig + , defaultConfigMonoid , defaultMainWith + , doAnalyze + , doRun ) where import Control.Applicative @@ -178,8 +183,11 @@ nullOutputPath = "nul" nullOutputPath = "/dev/null" #endif -defaultConfig :: ConfigMonoid -defaultConfig = mempty +defaultConfigMonoid :: ConfigMonoid +defaultConfigMonoid = mempty + +defaultConfig :: Config +defaultConfig = configFromMonoid defaultConfigMonoid data DuplicateIdentifiers a = DuplicateIdentifiers [a] instance (Show a, Typeable a) => Exception (DuplicateIdentifiers a) @@ -315,4 +323,4 @@ defaultMain :: String -- ^ Package name, user provided. -> [Benchmark] -- ^ Benchmarks to be run. -> IO () -defaultMain = defaultMainWith defaultConfig +defaultMain = defaultMainWith defaultConfigMonoid diff --git a/tests/Hyperion/MainSpec.hs b/tests/Hyperion/MainSpec.hs index 82c3d10..77f5255 100644 --- a/tests/Hyperion/MainSpec.hs +++ b/tests/Hyperion/MainSpec.hs @@ -15,8 +15,10 @@ spec = do it "checks for duplicate identifiers" $ property $ \b -> length (b^..identifiers) /= length (group (sort (b^..identifiers))) ==> expectFailure $ monadicIO $ run $ - defaultMainWith defaultConfig{configMonoidMode = return Run} "spec" [b] + defaultMainWith + defaultConfigMonoid{configMonoidMode = return Run} "spec" [b] it "Analyzes uniquely identified benchmarks" $ property $ \b -> length (b^..identifiers) == length (group (sort (b^..identifiers))) ==> monadicIO $ run $ - defaultMainWith defaultConfig{configMonoidReportOutputs = [ReportJson nullOutputPath]} "specs" [b] + defaultMainWith + defaultConfigMonoid{configMonoidReportOutputs = [ReportJson nullOutputPath]} "specs" [b]