10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-15 02:23:38 +01:00
qmcchem/ocaml/Qmcchem_debug.ml

91 lines
2.0 KiB
OCaml
Raw Normal View History

let run ~t ezfio_filename=
2015-12-19 02:35:13 +01:00
Qputils.set_ezfio_filename ezfio_filename;
2015-12-19 02:35:13 +01:00
if (not (Ezfio.has_simulation_http_server ())) then
failwith "QMC=Chem is not running"
;
let zmq_context =
2018-06-04 10:26:49 +02:00
Zmq.Context.create ()
2015-12-19 02:35:13 +01:00
in
Printf.printf "Debugging %s\n%!" ezfio_filename;
2015-12-19 02:35:13 +01:00
let socket =
2018-06-04 10:26:49 +02:00
Zmq.Socket.create zmq_context Zmq.Socket.sub
2015-12-19 02:35:13 +01:00
in
let address =
match (Ezfio.get_simulation_http_server ()
2019-07-19 17:06:01 +02:00
|> String_ext.rsplit2 ~on:':' )
2015-12-19 02:35:13 +01:00
with
2019-07-22 11:31:16 +02:00
| Some (a,p) -> a^":"^( (int_of_string p)+4 |> string_of_int )
2015-12-19 02:35:13 +01:00
| None -> failwith "Badly formed address"
in
2018-06-04 10:26:49 +02:00
Zmq.Socket.connect socket address;
Zmq.Socket.subscribe socket "";
2015-12-19 02:35:13 +01:00
if t then
begin
let re_split =
Str.regexp " *: *"
in
let tot_size =
2019-07-22 11:31:16 +02:00
ref 0.
2015-12-19 02:35:13 +01:00
in
while true
do
let msg =
2018-06-04 10:26:49 +02:00
Zmq.Socket.recv socket
2015-12-19 02:35:13 +01:00
in
let (socket, bytes) =
match Str.split re_split msg with
| socket :: bytes :: _ ->
2019-07-22 11:31:16 +02:00
(socket, float_of_string bytes)
| _ -> (print_endline msg ; ("", 0.))
2015-12-19 02:35:13 +01:00
in
2019-07-22 11:31:16 +02:00
tot_size := !tot_size +. bytes;
Printf.printf "%f\n%!" !tot_size;
Unix.sleep 1
2015-12-19 02:35:13 +01:00
done
end
else
begin
while true
do
let msg =
2018-06-04 10:26:49 +02:00
Zmq.Socket.recv socket
2015-12-19 02:35:13 +01:00
in
Printf.printf "%s\n%!" msg;
done
end
2019-07-22 12:19:12 +02:00
let command () =
2019-07-22 11:31:16 +02:00
let open Command_line in
begin
set_header_doc (Sys.argv.(0) ^ " - QMC=Chem command");
set_description_doc "Debug ZeroMQ communications";
[ { short='t' ; long="traffic" ; opt=Optional ;
doc="Print traffic in bytes" ;
arg=Without_arg } ;
anonymous "EZFIO_DIR" Mandatory "EZFIO directory" ]
|> set_specs
end;
let t = Command_line.get_bool "traffic" in
let ezfio_file =
match Command_line.anon_args () with
| ezfio_file :: [] -> ezfio_file
| _ -> (Command_line.help () ; failwith "Inconsistent command line")
in
run t ezfio_file
2015-12-19 02:35:13 +01:00