File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1884,6 +1884,7 @@ library bench-lib
18841884 BenchDB
18851885 build-depends:
18861886 glean:backend-api,
1887+ glean:bench-util,
18871888 glean:client-hs,
18881889 glean:core,
18891890 glean:db,
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ import qualified Data.Text as Text
1616
1717import Glean
1818import Glean.Backend.Types (loadPredicates )
19- import Glean.Database.Test ( withEmptyTestDB , completeTestDB )
19+ import Glean.Database.Test
2020import Glean.Database.Open
2121import Glean.Database.Write.Batch
2222import qualified Glean.Schema.Sys.Types as Sys
@@ -26,9 +26,20 @@ import qualified Glean.Schema.Sys as Sys
2626import qualified Glean.Schema.Cxx1 as Cxx
2727import qualified Glean.Schema.GleanTest as Glean.Test
2828import Glean.Typed
29+ import Glean.Util.Benchmark
2930
30- withBenchDB :: Int -> (forall b . Backend b => b -> Repo -> IO a ) -> IO a
31- withBenchDB num act = withEmptyTestDB [] $ \ env repo -> do
31+ withBenchDB
32+ :: GleanBenchConfig
33+ -> Int
34+ -> (forall b . Backend b => b -> Repo -> IO a )
35+ -> IO a
36+ withBenchDB conf num act = do
37+ let
38+ settings
39+ | useLMDB conf = [setLMDBStorage]
40+ | otherwise = []
41+
42+ withEmptyTestDB settings $ \ env repo -> do
3243 withOpenDatabase env repo $ \ odb ->
3344 void $ return odb
3445
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ import Glean.Util.Benchmark
2121import Glean.Typed
2222
2323main :: IO ()
24- main = benchmarkMain $ \ run -> do
24+ main = benchmarkMain $ \ _conf run -> do
2525 withEmptyTestDB [] $ \ env repo -> do
2626 predicates <- Backend. loadPredicates env repo
2727 [ Cxx. allPredicates
Original file line number Diff line number Diff line change @@ -29,7 +29,8 @@ import Glean.Util.Benchmark
2929import BenchDB
3030
3131main :: IO ()
32- main = benchmarkMain $ \ run -> withBenchDB 10000 $ \ env repo -> do
32+ main = benchmarkMain $ \ conf run ->
33+ withBenchDB conf 10000 $ \ env repo -> do
3334 let
3435 nestedAngle :: Query Cxx. FunctionName
3536 nestedAngle = angle " cxx1.FunctionName { name = \" x1\" }"
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ import Glean.Util.Benchmark
2222import TestBatch
2323
2424main :: IO ()
25- main = benchmarkMain $ \ run ->
25+ main = benchmarkMain $ \ _conf run ->
2626 withEmptyTestDB [] $ \ env repo -> do
2727 schema <- loadDbSchema env repo
2828 batch <- testBatch 500000 env repo
Original file line number Diff line number Diff line change 99module Glean.Util.Benchmark
1010 ( BenchmarkRunner
1111 , benchmarkMain
12+ , GleanBenchConfig (.. )
1213 ) where
1314
1415import Criterion.Main
1516import Criterion.Main.Options
17+ import Data.Default
18+ import Options.Applicative
1619
1720import Glean.Init
1821
1922type BenchmarkRunner = [Benchmark ] -> IO ()
2023
21- benchmarkMain :: (BenchmarkRunner -> IO () ) -> IO ()
22- benchmarkMain exec = withOptions (describe defaultConfig) $
23- exec . runMode
24+ benchmarkMain :: (GleanBenchConfig -> BenchmarkRunner -> IO () ) -> IO ()
25+ benchmarkMain exec =
26+ withOptions
27+ (describeWith ((,) <$> opts <*> parseWith defaultConfig)) $ \ (conf, crit) ->
28+ exec conf (runMode crit)
29+
30+ data GleanBenchConfig = GleanBenchConfig {
31+ useLMDB :: Bool
32+ }
33+
34+ instance Default GleanBenchConfig where
35+ def = GleanBenchConfig { useLMDB = False }
36+
37+ opts :: Parser GleanBenchConfig
38+ opts = GleanBenchConfig
39+ <$> switch (long " lmdb" <> help " use LMDB (otherwise use RocksDB)" )
Original file line number Diff line number Diff line change 99{-# LANGUAGE QuasiQuotes #-}
1010module TimeoutTest (main ) where
1111
12+ import Data.Default
1213import Test.HUnit
1314
1415import TestRunner
@@ -21,7 +22,7 @@ import qualified Glean.Schema.GleanTest.Types as Glean.Test
2122import BenchDB
2223
2324timeoutTest :: Test
24- timeoutTest = TestCase $ withBenchDB 10000 $ \ env repo -> do
25+ timeoutTest = TestCase $ withBenchDB def 10000 $ \ env repo -> do
2526 -- The test spends most of its time building the DB (withBenchDB above),
2627 -- so to keep things reasonable in debug mode we limit the number of
2728 -- facts to 10K and set the time limit to 1ms which is as low as we
You can’t perform that action at this time.
0 commit comments