X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;f=src%2Fmain.ml;h=bfbdff93014e50bdc55938e34c98ff469678d67f;hb=1975eef2d0933da3c01faec1cd14bc8fbf6bf146;hp=3932be697bb3255ed49c3caa5e82f0c119c4c6e7;hpb=4b52da1a20a4fe031930bb96d2ca46bec06dc529;p=SXSI%2Fxpathcomp.git diff --git a/src/main.ml b/src/main.ml index 3932be6..bfbdff9 100644 --- a/src/main.ml +++ b/src/main.ml @@ -13,40 +13,17 @@ let () = init_timer();; let default_gc = Gc.get() let tuned_gc = { default_gc with - Gc.minor_heap_size = 32*1024*1024; - Gc.major_heap_increment = 8*1024*1024; - Gc.max_overhead = 1000000; - Gc.space_overhead = 100; + Gc.minor_heap_size = 32*1024*1024; + Gc.major_heap_increment = 8*1024*1024; + Gc.max_overhead = 1000000; + Gc.space_overhead = 100; } - - -let pr_mat v r = - let () = - Printf.eprintf "Number of nodes in the result set : %i\n%!" - (NodeSet.Mat.length r); - in - if !Options.verbose then Printf.eprintf "Size of result set: %i kb\n" - (Ocaml.size_w r); - match !Options.output_file with - | None -> () - | Some f -> - let fd, finish = - if f = "-" then Unix.stdout, ignore - else - Unix.openfile f [ Unix.O_WRONLY; Unix.O_TRUNC; Unix.O_CREAT ] 0o666, - Unix.close - in - let () = - time ~msg:"Serializing results" - (NodeSet.Mat.iter (fun node -> Tree.print_xml v node fd)) r - in - Tree.flush v fd; - finish fd - let mk_runtime run auto doc arg count print outfile = fun () -> + if !Options.do_perf then start_perf (); let r = time ~count:1 ~msg:"Execution time" (run auto doc) arg in + if !Options.do_perf then stop_perf (); Printf.eprintf "Number of results: %i\n%!" (count r); match outfile with None -> () @@ -56,7 +33,7 @@ let mk_runtime run auto doc arg count print outfile = let main v query_string output = - Tag.init (Tree.tag_pool v); + Tag.init (Tree.tag_operations v); let query = time ~msg:"Parsing query" XPath.parse query_string in @@ -69,6 +46,8 @@ let main v query_string output = time ~msg:"Compiling query" (Compile.compile) query in if !Options.verbose then Ata.print Format.err_formatter auto; + Gc.full_major(); + Gc.compact(); Gc.set (tuned_gc); let runtime = match !Options.bottom_up, bu_info with @@ -112,7 +91,43 @@ let () = Options.parse_cmdline() ;; let document = - if Filename.check_suffix !Options.input_file ".srx" + if Filename.check_suffix !Options.input_file ".g" then + let g = Grammar2.parse !Options.input_file in + let () = Grammar2.save g "/tmp/test.g" in + let g = Grammar2.load "/tmp/test.g" in + ignore g; + exit 3 + + else if Filename.check_suffix !Options.input_file ".g.bin" then + let g = time ~msg:"Loading grammar" (Grammar.load !Options.input_file) true in + begin + (* Todo Factorise with main *) + Tag.init (Grammar.tag_operations g); + let query = + time ~msg:"Parsing query" XPath.parse !Options.query + in + if !Options.verbose then begin + Printf.eprintf "Parsed query:\n%!"; + XPath.Ast.print Format.err_formatter query; + Format.fprintf Format.err_formatter "\n%!" + end; + let auto, bu_info = + time ~msg:"Compiling query" (Compile.compile) query + in + if !Options.verbose then Ata.print Format.err_formatter auto; + Gc.full_major(); + Gc.compact(); + Gc.set (tuned_gc); + let runtime = + let module R = ResJIT.Count in + let module M = Runtime.Make(R) in + (* mk_runtime run auto doc arg count print outfile *) + mk_runtime M.grammar_run auto (Obj.magic g) () R.NS.length (Obj.magic R.NS.serialize) None + in + runtime (); + exit 0 + end + else if Filename.check_suffix !Options.input_file ".srx" then time ~msg:"Loading file" @@ -141,6 +156,7 @@ in (*Printexc.record_backtrace true; *) main document !Options.query !Options.output_file; if !Options.verbose then Printf.eprintf "Maximum resident set size: %s\n" (read_procmem()); + Gc.full_major(); Profile.summary Format.err_formatter with | Ulexer.Loc.Exc_located ((x,y),e) ->