Skip to content

Commit 2756ec7

Browse files
author
Nicolas Mattia
committed
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.
1 parent ced9acf commit 2756ec7

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/Hyperion/Main.hs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,24 @@ doRun strategy bks = do
210210
throwIO $ DuplicateIdentifiers [ n | n:_:_ <- group (sort ids) ]
211211
foldMap (runBenchmark strategy) bks
212212

213+
reportAnalysis
214+
:: Config
215+
-> ContextInfo -- ^ Benchmark context information.
216+
-> HashMap BenchmarkId Report
217+
-> IO ()
218+
reportAnalysis config cinfo report = do
219+
now <- getCurrentTime
220+
let metadata =
221+
configUserMetadata config
222+
-- Prepend user metadata so that the user can rewrite @timestamp@,
223+
-- for instance.
224+
<> HashMap.fromList [ "timestamp" JSON..= now ]
225+
void $ bracket
226+
(mapM (openReportHandle cinfo)
227+
$ Set.toList (configReportOutputs config))
228+
(mapM_ closeReportHandle)
229+
(mapM (\h -> printReport h metadata report))
230+
213231
-- | Print the report.
214232
printReport
215233
:: ReportOutput IO.Handle
@@ -257,26 +275,15 @@ closeReportHandle (ReportJsonFlat h) = IO.hClose h
257275

258276
doAnalyze
259277
:: Config -- ^ Hyperion config.
260-
-> ContextInfo -- ^ Benchmark context information.
261278
-> [Benchmark] -- ^ Benchmarks to be run.
262-
-> IO ()
263-
doAnalyze Config{..} cinfo bks = do
279+
-> IO (HashMap BenchmarkId Report)
280+
doAnalyze Config{..} bks = do
264281
results <- doRun (indexedStrategy Config{..}) bks
265282
let strip
266283
| configRaw = id
267284
| otherwise = reportMeasurements .~ Nothing
268285
report = results & imapped %@~ analyze & mapped %~ strip
269-
now <- getCurrentTime
270-
let metadata =
271-
configUserMetadata
272-
-- Prepend user metadata so that the user can rewrite @timestamp@,
273-
-- for instance.
274-
<> HashMap.fromList [ "timestamp" JSON..= now ]
275-
void $ bracket
276-
(mapM (openReportHandle cinfo)
277-
$ Set.toList configReportOutputs)
278-
(mapM_ closeReportHandle)
279-
(mapM (\h -> printReport h metadata report))
286+
pure report
280287

281288
defaultMainWith
282289
:: ConfigMonoid -- ^ Preset Hyperion config.
@@ -302,7 +309,7 @@ defaultMainWith presetConfig packageName bks = do
302309
Run -> do
303310
_ <- doRun (indexedStrategy config) bks
304311
return ()
305-
Analyze -> doAnalyze config cinfo bks
312+
Analyze -> doAnalyze config bks >>= reportAnalysis config cinfo
306313

307314
defaultMain
308315
:: String -- ^ Package name, user provided.

0 commit comments

Comments
 (0)