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;
26 Printf.eprintf "Number of nodes in the result set : %i\n%!"
27 (NodeSet.Mat.length r);
29 if !Options.verbose then Printf.eprintf "Size of result set: %i kb\n"
31 match !Options.output_file with
35 if f = "-" then Unix.stdout, ignore
37 Unix.openfile f [ Unix.O_WRONLY; Unix.O_TRUNC; Unix.O_CREAT ] 0o666,
41 time ~msg:"Serializing results"
42 (NodeSet.Mat.iter (fun node -> Tree.print_xml v node fd)) r
47 let mk_runtime run auto doc arg count print outfile =
49 let r = time ~count:1 ~msg:"Execution time" (run auto doc) arg in
50 Printf.eprintf "Number of results: %i\n%!" (count r);
54 time ~count:1 ~msg:"Serialization time" (print file doc) r
58 let main v query_string output =
59 Tag.init (Tree.tag_pool v);
61 time ~msg:"Parsing query" XPath.parse query_string
63 if !Options.verbose then begin
64 Printf.eprintf "Parsed query:\n%!";
65 XPath.Ast.print Format.err_formatter query;
66 Format.fprintf Format.err_formatter "\n%!"
69 time ~msg:"Compiling query" (Compile.compile) query
71 if !Options.verbose then Ata.print Format.err_formatter auto;
74 match !Options.bottom_up, bu_info with
76 | true, Some [ (query, pattern) ] ->
79 ~count:1 ~msg:"Computing full text query"
80 (Tree.full_text_query query v) pattern
82 let nodes = Array.to_list nodes in *)
83 if !Options.count_only then
84 let module R = ResJIT.Count in
85 let module M = Runtime.Make(R) in
86 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
88 let module R = ResJIT.Mat in
89 let module M = Runtime.Make(R) in
90 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
93 (* run the query top_down *)
95 if !Options.bottom_up then
96 Printf.eprintf "Cannot run the query in bottom-up mode, using top-down evaluator\n%!";
98 if !Options.count_only then
99 let module R = ResJIT.Count in
100 let module M = Runtime.Make(R) in
101 (* mk_runtime run auto doc arg count print outfile *)
102 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
104 let module R = ResJIT.Mat in
105 let module M = Runtime.Make(R) in
106 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
111 let () = Options.parse_cmdline()
115 if Filename.check_suffix !Options.input_file ".srx"
120 ~sample:!Options.sample_factor
126 ~msg:"Parsing document"
131 if !Options.save_file <> ""
134 ~msg:"Writing file to disk"
141 (*Printexc.record_backtrace true; *)
142 main document !Options.query !Options.output_file;
143 if !Options.verbose then Printf.eprintf "Maximum resident set size: %s\n" (read_procmem());
144 Profile.summary Format.err_formatter
146 | Ulexer.Loc.Exc_located ((x,y),e) ->
147 Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);
151 output_string stderr "\n";
153 Printexc.print_backtrace stderr;
154 Printf.eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e);
155 output_string stderr "\n";
157 (* Ptset.Int.stats(); *)