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.verbose Format.err_formatter "Number of results: %i@\n" (count r);
31 Utils.time ~count:1 ~msg:"Serialization time" (print file !Config.no_wrap_results doc) r
34 let main v query_string output =
35 Tag.init (Tree.tag_operations v);
36 if !Config.docstats then Tree.stats v;
38 Utils.time ~msg:"Parsing query" XPath.parse query_string
40 Logger.verbose Format.err_formatter "Parsed query:%a@\n"
41 XPath.Ast.print query;
43 Utils.time ~msg:"Compiling query" Compile.compile query
45 if !Config.verbose then Ata.print Format.err_formatter auto;
50 match !Config.bottom_up, bu_info with
52 | true, Some [ (query, pattern) ] ->
53 if !Config.count_only then
54 let module R = ResJIT.Count in
55 let module M = Runtime.Make(R) in
56 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file
58 let module R = ResJIT.Mat in
59 let module M = Runtime.Make(R) in
60 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Config.output_file
63 (* run the query top_down *)
65 if !Config.bottom_up then
66 Logger.verbose Format.err_formatter "Cannot run the query in bottom-up mode, using top-down evaluator@\n@?";
67 if !Config.count_only then
68 let module R = ResJIT.Count in
69 let module M = Runtime.Make(R) in
70 if !Config.twopass then
71 mk_runtime M.twopass_top_down_run auto v Tree.root R.NS.length R.NS.serialize None
73 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file
75 let module R = ResJIT.Mat in
76 let module M = Runtime.Make(R) in
77 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Config.output_file
82 let () = Options.parse_cmdline()
86 Printexc.record_backtrace true;
88 if Filename.check_suffix !Config.input_file ".srx"
91 ~msg:"Loading Index file"
93 ~sample:!Config.sample_factor
94 ~load_text:(not !Config.disable_text_collection))
99 ~msg:"Loading XML file"
104 if !Config.save_file <> ""
107 ~msg:"Writing file to disk"
113 main document !Config.query !Config.output_file;
114 Logger.verbose Format.err_formatter "Maximum resident set size: %s @\n" (read_procmem());
116 Profile.summary Format.err_formatter
118 | Ulexer.Loc.Exc_located ((x,y),e) ->
119 Logger.print Format.err_formatter "character %i-%i %s@\n" x y (Printexc.to_string e);
123 Logger.print Format.err_formatter "BACKTRACE: %s@\n@?" (Printexc.get_backtrace());
124 Logger.print Format.err_formatter "FATAL ERROR: %s@\n@?" (Printexc.to_string e);