2017-10-10 09:39:58 +02:00
|
|
|
open Core
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
2016-01-18 20:17:37 +01:00
|
|
|
let run ~t ezfio_filename=
|
2015-12-19 02:35:13 +01:00
|
|
|
|
2016-01-18 20:17:37 +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
|
|
|
|
|
2016-01-18 20:17:37 +01:00
|
|
|
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 ()
|
|
|
|
|> String.rsplit2 ~on:':' )
|
|
|
|
with
|
|
|
|
| Some (a,p) -> a^":"^( (Int.of_string p)+4 |> Int.to_string )
|
|
|
|
| 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 =
|
|
|
|
ref (Byte_units.create `Bytes 0.)
|
|
|
|
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 :: _ ->
|
|
|
|
(socket, Byte_units.create `Bytes (Float.of_string bytes))
|
|
|
|
| _ -> (print_endline msg ; ("", Byte_units.create `Bytes 0.))
|
|
|
|
in
|
|
|
|
tot_size := Byte_units.create `Bytes ((Byte_units.bytes !tot_size) +. (Byte_units.bytes bytes));
|
|
|
|
Printf.printf "%s\n%!" (Byte_units.to_string !tot_size);
|
2017-10-10 09:39:58 +02:00
|
|
|
Time.pause (Time.Span.of_sec 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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let spec =
|
|
|
|
let open Command.Spec in
|
|
|
|
empty
|
|
|
|
+> flag "t" no_arg
|
|
|
|
~doc:"Measure the throughput"
|
2016-01-18 20:17:37 +01:00
|
|
|
+> anon ("ezfio_file" %: string)
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
let command =
|
2018-03-14 17:02:52 +01:00
|
|
|
Command.basic_spec
|
2015-12-19 02:35:13 +01:00
|
|
|
~summary: "Debug ZeroMQ communications"
|
2018-06-04 10:26:49 +02:00
|
|
|
~readme:(fun () -> "Gets debug information from the Zmq debug sockets.")
|
2015-12-19 02:35:13 +01:00
|
|
|
spec
|
2016-01-18 20:17:37 +01:00
|
|
|
(fun t ezfio_file () -> run t ezfio_file)
|
2015-12-19 02:35:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
|