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 !Config.do_perf then start_perf ();
25 let r = Utils.time ~count:!Config.repeat ~msg:"Execution time" (run auto doc) arg in
26 if !Config.do_perf then stop_perf ();
27 Logger.start_msg Format.err_formatter "[Debug] Number of results: ";
28 Logger.msg Format.err_formatter "%i" (count r);
29 Logger.end_msg Format.err_formatter "\n";
33 Utils.time ~count:1 ~msg:"Serialization time" (print file !Config.no_wrap_results doc) r
36 let main v query_string output =
37 Tag.init (Tree.tag_operations v);
38 if !Config.docstats then Tree.stats v;
40 Utils.time ~msg:"Parsing query" XPath.parse query_string
42 Logger.start_msg Format.err_formatter "[Debug]";
43 Logger.msg Format.err_formatter " Parsed query: @\n @[<v 0> {";
44 Logger.msg Format.err_formatter " %a }@]" XPath.Ast.print query;
45 Logger.end_msg Format.err_formatter "\n\n";
47 Utils.time ~msg:"Compiling query" Compile.compile query
49 Logger.start_msg Format.err_formatter "[Debug] Automaton: ";
50 Logger.msg Format.err_formatter "@\n @[<v 0>";
51 Logger.msg Format.err_formatter "%a" Ata.print auto;
52 Logger.end_msg Format.err_formatter "\n\n";
57 match !Config.bottom_up, bu_info with
59 | true, Some [ (query, pattern) ] ->
60 if !Config.count_only then
61 let module R = ResJIT.Count in
62 let module M = Runtime.Make(R) in
63 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file
65 let module R = ResJIT.Mat in
66 let module M = Runtime.Make(R) in
67 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file
70 (* run the query top_down *)
72 if !Config.bottom_up then
73 Logger.verbose Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?";
74 if !Config.count_only then
75 let module R = ResJIT.Count in
76 let module M = Runtime.Make(R) in
77 if !Config.twopass then
78 mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None
80 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file
82 let module R = ResJIT.Mat in
83 let module M = Runtime.Make(R) in
84 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file
89 let () = Options.parse_cmdline()
93 Printexc.record_backtrace true;
95 if Filename.check_suffix !Config.input_file ".srx"
98 ~msg:"Loading Index file"
100 ~sample:!Config.sample_factor
101 ~load_text:(not !Config.disable_text_collection))
106 ~msg:"Loading XML file"
111 if !Config.save_file <> ""
114 ~msg:"Writing file to disk"
120 main document !Config.query !Config.output_file;
123 Profile.summary Format.err_formatter
127 | Ulexer.Loc.Exc_located ((x,y),e) ->
128 Logger.print Format.err_formatter "character %i-%i %s@\n" x y (Printexc.to_string e);
132 Logger.print Format.err_formatter "BACKTRACE: %s@\n@?" (Printexc.get_backtrace());
133 Logger.print Format.err_formatter "FATAL ERROR: %s@\n@?" (Printexc.to_string e);