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 (******************************************************************************)
13 let t1 = Unix.gettimeofday () in
15 let t2 = Unix.gettimeofday () in
16 let t = (1000. *. (t2 -. t1)) in
18 Printf.eprintf " %fms\n%!" t ;
21 let total_time () = List.fold_left (+.) 0. !l;;
22 let enabled_gc = Gc.get()
23 let disabled_gc = { Gc.get() with
24 Gc.max_overhead = 1000000;
25 Gc.space_overhead = 100 }
27 let main v query output =
28 let _ = Tag.init (Tree.tag_pool v) in
29 Printf.eprintf "Parsing query : ";
32 XPath.Parser.parse_string query
34 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
36 XPath.Ast.print Format.err_formatter query;
37 Format.fprintf Format.err_formatter "\n%!";
38 Printf.eprintf "Compiling query : ";
39 let auto,ltags,contains = time XPath.Compile.compile query in
40 let _ = Ata.dump Format.err_formatter auto in
41 let _ = Printf.eprintf "%!" in
43 let do_contains = match contains with
46 let r = Tree.count v s
48 Printf.eprintf "%i documents in the TextCollection\n" (Tree.text_size v);
49 Printf.eprintf "Global count is %i, using " r;
50 if r < !Options.tc_threshold then begin
51 Printf.eprintf "TextCollection contains\nTiming call to raw global contains (1st time): ";
52 time (Tree.unsorted_contains v) s;
53 Printf.eprintf "Calling global contains : ";
54 time (Tree.init_contains v) s;
55 Printf.eprintf "Timing call to global count contains : ";
56 let r = time (Tree.count_contains v) s
58 Printf.eprintf " number of matching nodes %i \n%!" r;
59 Printf.eprintf "Timing call to raw global contains (2nd time): ";
60 time (Tree.unsorted_contains v) s;
63 Printf.eprintf "Naive contains\nCalling global contains : ";
64 time (Tree.init_naive_contains v) s
67 Printf.eprintf "Execution time %s : "
68 (if !Options.count_only then "(counting only)" else if !Options.backward then "(bottomup)" else "");
70 let _ = Gc.full_major();Gc.compact() in
71 let _ = Gc.set (disabled_gc) in
72 if !Options.backward then
73 let tag,set = List.hd ltags in
74 let r = if do_contains
75 then time (bottom_up_count_contains auto) v
76 else time (bottom_up_count auto v) tag in
77 let _ = Printf.eprintf "Number of nodes in the result set : %i\n%!" r
80 if !Options.count_only then
81 let r = time ( top_down_count auto ) v in (* not clean *)
82 let _ = Printf.eprintf "Number of nodes in the result set : %i\n%!" r
85 let result = time (top_down auto) v in
86 let rcount = IdSet.length result in
87 Printf.eprintf "Number of nodes in the result set : %i\n" rcount;
88 Printf.eprintf "\n%!";
93 Printf.eprintf "Serializing results : ";
95 let oc = open_out f in
96 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
98 Tree.print_xml_fast oc t;
100 output_string oc "----------\n";
104 let _ = Gc.set enabled_gc in
105 (* let _ = Ata.dump Format.err_formatter auto in *)
106 Printf.eprintf "Total running time : %fms\n%!" (total_time())
109 Options.parse_cmdline();;
112 if (Filename.check_suffix !Options.input_file ".srx")
115 Printf.eprintf "Loading from file : ";
116 time (Tree.load ~sample:!Options.sample_factor )
117 (Filename.chop_suffix !Options.input_file ".srx");
121 time (fun () -> let v = Tree.parse_xml_uri !Options.input_file;
122 in Printf.eprintf "Parsing document : %!";v
125 if !Options.save_file <> ""
127 Printf.eprintf "Writing file to disk : ";
128 time (Tree.save v) !Options.save_file;
132 main v !Options.query !Options.output_file;;
136 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
138 Tree.DEBUGTREE.print_stats Format.err_formatter;;