1 (******************************************************************************)
2 (* SXSI : XPath evaluator *)
3 (* Kim Nguyen (Kim.Nguyen@nicta.com.au) *)
4 (* Copyright NICTA 2008 *)
5 (* Distributed under the terms of the LGPL (see LICENCE) *)
6 (******************************************************************************)
11 let () = init_timer();;
14 let default_gc = Gc.get()
15 let tuned_gc = { default_gc with
16 Gc.minor_heap_size = 32*1024*1024;
17 Gc.major_heap_increment = 8*1024*1024;
18 Gc.max_overhead = 1000000;
19 Gc.space_overhead = 100;
22 let mk_runtime run auto doc arg count print outfile =
24 if !Options.do_perf then start_perf ();
25 let r = time ~count:1 ~msg:"Execution time" (run auto doc) arg in
26 if !Options.do_perf then stop_perf ();
27 Printf.eprintf "Number of results: %i\n%!" (count r);
31 time ~count:1 ~msg:"Serialization time" (print file doc) r
35 let main v query_string output =
36 Tag.init (Tree.tag_operations v);
38 time ~msg:"Parsing query" XPath.parse query_string
40 if !Options.verbose then begin
41 Printf.eprintf "Parsed query:\n%!";
42 XPath.Ast.print Format.err_formatter query;
43 Format.fprintf Format.err_formatter "\n%!"
46 time ~msg:"Compiling query" (Compile.compile) query
48 if !Options.verbose then Ata.print Format.err_formatter auto;
53 match !Options.bottom_up, bu_info with
55 | true, Some [ (query, pattern) ] ->
58 ~count:1 ~msg:"Computing full text query"
59 (Tree.full_text_query query v) pattern
61 let nodes = Array.to_list nodes in *)
62 if !Options.count_only then
63 let module R = ResJIT.Count in
64 let module M = Runtime.Make(R) in
65 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
67 let module R = ResJIT.Mat in
68 let module M = Runtime.Make(R) in
69 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
72 (* run the query top_down *)
74 if !Options.bottom_up then
75 Printf.eprintf "Cannot run the query in bottom-up mode, using top-down evaluator\n%!";
77 if !Options.count_only then
78 let module R = ResJIT.Count in
79 let module M = Runtime.Make(R) in
80 (* mk_runtime run auto doc arg count print outfile *)
81 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
83 let module R = ResJIT.Mat in
84 let module M = Runtime.Make(R) in
85 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
90 let () = Options.parse_cmdline()
94 if Filename.check_suffix !Options.input_file ".g.bin" then
95 let g = time ~msg:"Loading grammar" (Grammar.load !Options.input_file) true in
98 Unix.sleep 10; (* Leave monitoring process the time to read the HWM *)
101 else if Filename.check_suffix !Options.input_file ".srx"
106 ~sample:!Options.sample_factor
112 ~msg:"Parsing document"
117 if !Options.save_file <> ""
120 ~msg:"Writing file to disk"
127 (*Printexc.record_backtrace true; *)
128 main document !Options.query !Options.output_file;
129 if !Options.verbose then Printf.eprintf "Maximum resident set size: %s\n" (read_procmem());
131 Profile.summary Format.err_formatter
133 | Ulexer.Loc.Exc_located ((x,y),e) ->
134 Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);
138 output_string stderr "\n";
140 Printexc.print_backtrace stderr;
141 Printf.eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e);
142 output_string stderr "\n";
144 (* Ptset.Int.stats(); *)