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;
23 let mk_runtime run auto doc arg count print outfile =
25 let r = time ~count:1 ~msg:"Execution time" (run auto doc) arg in
26 Printf.eprintf "Number of results: %i\n%!" (count r);
30 time ~count:1 ~msg:"Serialization time" (print file doc) r
34 let main v query_string output =
35 Tag.init (Tree.tag_pool v);
37 time ~msg:"Parsing query" XPath.parse query_string
39 if !Options.verbose then begin
40 Printf.eprintf "Parsed query:\n%!";
41 XPath.Ast.print Format.err_formatter query;
42 Format.fprintf Format.err_formatter "\n%!"
45 time ~msg:"Compiling query" (Compile.compile) query
47 if !Options.verbose then Ata.print Format.err_formatter auto;
50 match !Options.bottom_up, bu_info with
52 | true, Some [ (query, pattern) ] ->
55 ~count:1 ~msg:"Computing full text query"
56 (Tree.full_text_query query v) pattern
58 let nodes = Array.to_list nodes in *)
59 if !Options.count_only then
60 let module R = ResJIT.Count in
61 let module M = Runtime.Make(R) in
62 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize None
64 let module R = ResJIT.Mat in
65 let module M = Runtime.Make(R) in
66 mk_runtime M.bottom_up_run auto v (query, pattern) R.NS.length R.NS.serialize !Options.output_file
69 (* run the query top_down *)
71 if !Options.bottom_up then
72 Printf.eprintf "Cannot run the query in bottom-up mode, using top-down evaluator\n%!";
74 if !Options.count_only then
75 let module R = ResJIT.Count in
76 let module M = Runtime.Make(R) in
77 (* mk_runtime run auto doc arg count print outfile *)
78 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize None
80 let module R = ResJIT.Mat in
81 let module M = Runtime.Make(R) in
82 mk_runtime M.top_down_run auto v Tree.root R.NS.length R.NS.serialize !Options.output_file
87 let () = Options.parse_cmdline()
91 if Filename.check_suffix !Options.input_file ".srx"
96 ~sample:!Options.sample_factor
102 ~msg:"Parsing document"
107 if !Options.save_file <> ""
110 ~msg:"Writing file to disk"
117 (*Printexc.record_backtrace true; *)
118 main document !Options.query !Options.output_file;
119 if !Options.verbose then Printf.eprintf "Maximum resident set size: %s\n" (read_procmem());
120 Profile.summary Format.err_formatter
122 | Ulexer.Loc.Exc_located ((x,y),e) ->
123 Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);
127 output_string stderr "\n";
129 Printexc.print_backtrace stderr;
130 Printf.eprintf "FATAL ERROR: %s\n%!" (Printexc.to_string e);
131 output_string stderr "\n";
133 (* Ptset.Int.stats(); *)