X-Git-Url: http://git.nguyen.vg/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Ftatoo.ml;h=e0f29ee8dff4b43df89e93eb4d5a095e59135523;hb=cfbd6490c8b03b820375f79ff4d009ed2d0252c3;hp=4d7e693c019b91dfb710bfac6cd77f4e0c40b059;hpb=398ce5dca1bee23f5137a3eba21df17d7aaaf1fa;p=tatoo.git
diff --git a/src/tatoo.ml b/src/tatoo.ml
index 4d7e693..e0f29ee 100644
--- a/src/tatoo.ml
+++ b/src/tatoo.ml
@@ -24,56 +24,134 @@ let time f arg msg =
r
+let compose_parallel run auto_list tree nodes () =
+ match auto_list with
+ [ auto ] -> [run auto tree nodes]
+ | _ -> assert false
+
+let compose_sequential run auto_list tree nodes () =
+ [ List.fold_left (fun acc auto ->
+ run auto tree acc) nodes auto_list ]
+
+
+let restart_parallel run auto_list tree nodes () =
+ match auto_list with
+ [ auto ] -> List.map snd (run auto tree nodes)
+ | _ -> assert false
+
+let restart_sequential run auto_list tree nodes () =
+ List.map (fun auto -> run auto tree nodes) auto_list
+
let main () =
let () = Options.parse () in
let doc =
let fd, close_fd = match !Options.input_file with
- None -> stdin, ignore
+ None | Some "-" | Some "/dev/stdin" -> stdin, ignore
| Some input ->
let fd = open_in input in fd, fun () -> close_in fd
in
let d = time Naive_tree.load_xml_file fd "parsing xml document" in
close_fd (); d
in
- let query =
+ let queries =
time
- Xpath.Parser.parse
- (Ulexing.from_latin1_string !Options.query)
- "parsing XPath query"
+ (fun l ->
+ List.map (fun q ->
+ Xpath.Parser.parse
+ (Ulexing.from_utf8_string q)) l)
+ !Options.queries
+ "parsing XPath queries"
in
- let auto =
- time Xpath.Compile.path query "compiling XPath query"
+ (* parallel, compose -> action
+ true, true -> Ata.concat of all automata and single run
+ true, false -> Ata.merge of all automata and single run
+ false, true -> Eval first, then run on results then ...
+ false, false -> Eval first on root, then second on root then ...
+ *)
+ let auto_list =
+ time
+ (fun l ->
+ List.map (fun query -> Xpath.Compile.path query) l)
+ queries
+ "compiling XPath queries"
+ in
+ let auto_list =
+ if !Options.parallel then
+ match auto_list with
+ fst :: rest ->
+ let f =
+ if !Options.compose then
+ Ata.concat
+ else
+ Ata.merge
+ in
+ let big_auto = List.fold_left f fst rest in
+ [big_auto]
+ | _ -> assert false
+
+ else
+ auto_list
in
- let auto = time Ata.copy auto "copying Automaton" in
let output =
match !Options.output_file with
| None | Some "-" | Some "/dev/stdout" -> stdout
| Some f -> open_out f
in
if !Options.stats then begin
- Logger.msg `STATS "Query: %a " Xpath.Ast.print_path query;
- Logger.msg `STATS "@[Automaton: @\n%a@]" Ata.print auto;
+ List.iter (fun query ->
+ Logger.msg `STATS "Query: %a " Xpath.Ast.print_path query) queries;
+ List.iter (fun auto ->
+ Logger.msg `STATS "@[Automaton: @\n%a@]" Ata.print auto) auto_list;
end;
- let module Naive = Run.Make(Naive_tree) in
- let results =
- time (Naive.eval auto doc) ([Naive_tree.root doc]) "evaluating query"
+ let module Naive = Run.Make(Naive_tree)(Naive_node_list) in
+ let result_list =
+ let root = Naive_node_list.create () in
+ let () = Naive_node_list.add (Naive_tree.root doc) root in
+ let f, msg =
+ match !Options.parallel, !Options.compose with
+ true, true ->
+ compose_parallel Naive.eval auto_list doc root, "parallel/compose"
+ | true, false ->
+ restart_parallel Naive.full_eval auto_list doc root, "parallel/restart"
+ | false, true ->
+ compose_sequential Naive.eval auto_list doc root , "sequential/compose"
+ | false, false ->
+ restart_sequential Naive.eval auto_list doc root, "sequential/restart"
+ in
+ time f () ("evaluating query in " ^ msg ^ " mode")
in
+ let s = Naive.stats () in
+ Run.(
+ Logger.msg `STATS
+ "@[tree size: %d@\ntraversals: %d@\ntransition fetch cache hit ratio: %f@\ntransition eval cache hit ratio: %f@\nNumber of visited nodes per pass: %a@]"
+ s.tree_size s.pass
+ (float s.fetch_trans_cache_hit /. float s.fetch_trans_cache_access)
+ (float s.eval_trans_cache_hit /. float s.eval_trans_cache_access)
+ (let i = ref 0 in
+ Pretty.print_list ~sep:"," (fun fmt n -> Format.fprintf fmt "%i: %i" !i n;incr i))
+ s.nodes_per_run);
time (fun () ->
- output_string output "\n";
- if !Options.count then begin
- output_string output (string_of_int (List.length results));
- output_char output '\n';
- end else
- List.iter (fun n ->
- Naive_tree.print_xml output doc n;
- output_char output '\n'
- ) results;
- output_string output "\n";
- flush output;
- if output != stdout then close_out output
+ let count = ref 1 in
+ List.iter (fun results ->
+ output_string output "\n";
+ if !Options.count then begin
+ output_string output (string_of_int (Naive_node_list.length results));
+ output_char output '\n';
+ end else
+ Naive_node_list.iter (fun n ->
+ Naive_tree.print_xml output doc n;
+ output_char output '\n'
+ ) results;
+ output_string output "\n";
+ incr count
+ ) result_list;
+ flush output;
+ if output != stdout then close_out output
-) () "serializing results"
+ ) () "serializing results"
let () =