File tree Expand file tree Collapse file tree 2 files changed +10
-18
lines changed
Expand file tree Collapse file tree 2 files changed +10
-18
lines changed Original file line number Diff line number Diff line change @@ -101,17 +101,9 @@ module Ops = struct
101101 read_key (module Db ) db key
102102end
103103
104- (* Temporary directory management *)
105- let make_temp_dir prefix =
106- let pid = Unix. getpid () |> Pid. to_int in
107- let dir_name = Printf. sprintf " %s_%d" prefix pid in
108- Unix. mkdir_p dir_name ; dir_name
109-
110- let cleanup_temp_dir dir =
111- match Sys. file_exists dir with
112- | `Yes ->
113- ignore
114- ( Core_unix. system (Printf. sprintf " rm -rf %s" (Filename. quote dir))
115- : Core_unix.Exit_or_signal. t )
116- | _ ->
117- ()
104+ let with_temp_dir prefix ~f =
105+ let dir_name = Unix. mkdtemp prefix in
106+ try f dir_name
107+ with e ->
108+ Mina_stdlib_unix.File_system. rmrf dir_name ;
109+ raise e
Original file line number Diff line number Diff line change @@ -10,9 +10,8 @@ module Single_file_db = Single_file_impl.Make ()
1010
1111module Multi_file_db = Multi_file_impl. Make ()
1212
13- let init_db (type db ) (module Db : Common.Database with type t = db ) name =
13+ let init_db (type db ) ~ dir (module Db : Common.Database with type t = db ) name =
1414 (* Initialization: create DB and warmup *)
15- let dir = Common. make_temp_dir (Printf. sprintf " db_bench_%s" name) in
1615 let db = Db. create dir in
1716 Common.Ops. warmup (module Db ) db ;
1817 eprintf " Warmup complete for %s\n " name ;
@@ -37,8 +36,9 @@ let make_read_bench (type db) (module Db : Common.Database with type t = db)
3736
3837let test ~name (type db ) (module Db : Common.Database with type t = db )
3938 (f : (module Common.Database with type t = db) -> db -> unit -> unit ) =
40- Bench.Test. create_with_initialization ~name (fun `init ->
41- init_db (module Db ) name |> f (module Db ) )
39+ Common. with_temp_dir name ~f: (fun dir ->
40+ Bench.Test. create_with_initialization ~name (fun `init () ->
41+ init_db ~dir (module Db ) name |> f (module Db ) ) )
4242
4343(* Create all benchmarks *)
4444let all_benchmarks () =
You can’t perform that action at this time.
0 commit comments