2016-01-12 17:01:44 +00:00
|
|
|
{- git-annex benchmark
|
|
|
|
-
|
2019-01-04 17:43:53 +00:00
|
|
|
- Copyright 2016-2019 Joey Hess <id@joeyh.name>
|
2016-01-12 17:01:44 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2016-01-12 17:01:44 +00:00
|
|
|
-}
|
|
|
|
|
2019-01-05 12:09:28 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
2016-01-12 17:01:44 +00:00
|
|
|
|
|
|
|
module Command.Benchmark where
|
|
|
|
|
|
|
|
import Command
|
2019-01-04 17:43:53 +00:00
|
|
|
import Types.Benchmark
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2019-10-29 19:16:15 +00:00
|
|
|
import Database.Benchmark
|
|
|
|
|
2016-01-12 17:01:44 +00:00
|
|
|
import Criterion.Main
|
2019-10-29 19:16:15 +00:00
|
|
|
import Criterion.Main.Options (parseWith)
|
2019-01-05 12:09:28 +00:00
|
|
|
#endif
|
2019-01-04 17:43:53 +00:00
|
|
|
|
|
|
|
cmd :: BenchmarkGenerator -> Command
|
|
|
|
cmd generator = command "benchmark" SectionTesting
|
|
|
|
"benchmark git-annex commands"
|
|
|
|
paramNothing
|
|
|
|
(seek generator <$$> optParser)
|
|
|
|
|
2019-10-29 19:16:15 +00:00
|
|
|
data BenchmarkOptions
|
|
|
|
= BenchmarkOptions CmdParams CriterionMode
|
2019-11-21 21:25:20 +00:00
|
|
|
| BenchmarkDatabases CriterionMode Integer
|
2019-01-04 17:43:53 +00:00
|
|
|
|
|
|
|
optParser :: CmdParamsDesc -> Parser BenchmarkOptions
|
2019-10-29 19:16:15 +00:00
|
|
|
optParser desc = benchmarkoptions <|> benchmarkdatabases
|
|
|
|
where
|
|
|
|
benchmarkoptions = BenchmarkOptions
|
|
|
|
<$> cmdParams desc
|
|
|
|
<*> criterionopts
|
|
|
|
benchmarkdatabases = BenchmarkDatabases
|
|
|
|
<$> criterionopts
|
2019-11-21 21:25:20 +00:00
|
|
|
<*> option auto
|
|
|
|
( long "databases"
|
|
|
|
<> metavar paramNumber
|
2019-10-29 19:16:15 +00:00
|
|
|
<> help "benchmark sqlite databases"
|
2019-11-21 21:25:20 +00:00
|
|
|
)
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2019-10-29 19:16:15 +00:00
|
|
|
criterionopts = parseWith defaultConfig
|
2019-01-05 12:09:28 +00:00
|
|
|
#else
|
2019-10-29 19:16:15 +00:00
|
|
|
criterionopts = pure ()
|
2019-01-05 12:09:28 +00:00
|
|
|
#endif
|
2019-01-04 17:43:53 +00:00
|
|
|
|
|
|
|
seek :: BenchmarkGenerator -> BenchmarkOptions -> CommandSeek
|
2019-01-05 12:09:28 +00:00
|
|
|
#ifdef WITH_BENCHMARK
|
2019-01-04 17:43:53 +00:00
|
|
|
seek generator (BenchmarkOptions ps mode) = do
|
|
|
|
runner <- generator ps
|
|
|
|
liftIO $ runMode mode [ bench (unwords ps) $ nfIO runner ]
|
2019-11-21 21:25:20 +00:00
|
|
|
seek _ (BenchmarkDatabases mode n) = benchmarkDbs mode n
|
2019-01-05 12:09:28 +00:00
|
|
|
#else
|
|
|
|
seek _ _ = giveup "git-annex is not built with benchmarking support"
|
|
|
|
#endif
|