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;;
24 let main v query output =
25 let _ = Tag.init (Tree.Binary.tag_pool v) in
26 Printf.eprintf "Parsing query : ";
29 XPath.Parser.parse_string query
31 Ulexer.Loc.Exc_located ((x,y),e) -> Printf.eprintf "character %i-%i %s\n" x y (Printexc.to_string e);exit 1
33 XPath.Ast.print Format.err_formatter query;
34 Format.fprintf Format.err_formatter "\n%!";
35 (* Printf.eprintf "Dummy iteration : ";
36 time (fill_hashtag) v;
37 Printf.eprintf "Dummy iteration (tag access cached) : ";
38 time (fill_hashtag) v;
40 Printf.eprintf "Compiling query : ";
41 let auto,ltags,contains = time XPath.Compile.compile query in
42 let _ = Ata.dump Format.err_formatter auto in
43 let _ = Printf.eprintf "%!" in
44 let _ = match contains with
46 | Some s -> Tree.Binary.init_contains v s
48 Printf.eprintf "Execution time %s : " (if !Options.count_only then "(counting only)" else "");
50 if !Options.count_only then
51 failwith "Count only not implemented in this version"
53 let _ = Gc.set ({ Gc.get() with Gc.max_overhead = 1000000; Gc.space_overhead = 100 }) in
54 let result = time (if !Options.time then run_time auto else run auto) v in
55 Printf.eprintf "Number of nodes in the result set : %i\n" (TS.length result);
56 Printf.eprintf "\n%!";
61 Printf.eprintf "Serializing results : ";
63 let oc = open_out f in
64 output_string oc "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
65 TS.rev_iter (fun t -> output_string oc "----------\n";
66 Tree.Binary.print_xml_fast oc t;
67 output_char oc '\n') result) ();
70 Printf.eprintf "Total running time : %fms\n%!" (total_time())
73 Options.parse_cmdline();;
76 if (Filename.check_suffix !Options.input_file ".srx")
79 Printf.eprintf "Loading from file : ";
80 time (Tree.Binary.load ~sample:!Options.sample_factor )
81 (Filename.chop_suffix !Options.input_file ".srx");
85 time (fun () -> let v = Tree.Binary.parse_xml_uri !Options.input_file;
86 in Printf.eprintf "Parsing document : %!";v
89 if !Options.save_file <> ""
91 Printf.eprintf "Writing file to disk : ";
92 time (Tree.Binary.save v) !Options.save_file;
96 main v !Options.query !Options.output_file;;
100 Printf.eprintf "\n=================================================\nDEBUGGING\n%!";
102 Tree.DEBUGTREE.print_stats Format.err_formatter;;