summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sources/thibaut/Makefile7
-rw-r--r--sources/thibaut/compattrace.ml108
-rw-r--r--sources/thibaut/trace.ml10
-rw-r--r--sources/thibaut/tracestats.ml48
4 files changed, 165 insertions, 8 deletions
diff --git a/sources/thibaut/Makefile b/sources/thibaut/Makefile
index 187aa22..152966d 100644
--- a/sources/thibaut/Makefile
+++ b/sources/thibaut/Makefile
@@ -3,14 +3,17 @@ OCAMLOPT=ocamlopt.opt
OCAMLDEP=ocamldep.opt
INCLUDES=
OCAMLFLAGS=$(INCLUDES)
-SRCS=map2.ml simulator.ml trace.ml gentrace.ml pacemaker.ml globals.ml
+SRCS=map2.ml simulator.ml trace.ml gentrace.ml pacemaker.ml globals.ml compattrace.ml tracestats.ml
BUILDDIR=build
-all: gentrace.opt simulator.opt
+all: gentrace.opt simulator.opt tracestats.opt
builddir:
mkdir -p $(BUILDDIR)
+tracestats.opt: builddir tracestats.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/tracestats $(OCAMLFLAGS) str.cmxa compattrace.cmx tracestats.cmx
+
gentrace.opt: builddir gentrace.cmx
$(OCAMLOPT) -o $(BUILDDIR)/gentrace $(OCAMLFLAGS) map2.cmx str.cmxa globals.cmx pacemaker.cmx trace.cmx gentrace.cmx
diff --git a/sources/thibaut/compattrace.ml b/sources/thibaut/compattrace.ml
new file mode 100644
index 0000000..5617282
--- /dev/null
+++ b/sources/thibaut/compattrace.ml
@@ -0,0 +1,108 @@
+type trace_event =
+ Peers of int
+| Days of int * int
+| Peer of int * float * string
+| Round of int
+| On of int
+| Off of int
+| Dead of int
+| End
+| Exponential
+
+type state = ON | OFF | DEAD
+
+type peer = {
+ i : int;
+ descr : string;
+ avail : float;
+ mutable state : state;
+ mutable real_avail : int;
+ mutable session : int;
+ }
+
+let trace_input ic =
+ let line = input_line ic in
+ let space = Str.regexp " " in
+ match Str.split space line with
+ ["Peers"; npeers] -> Peers (int_of_string npeers)
+ | ["Days"; ndays] -> Days (int_of_string ndays, 24 * 60)
+ | ["Days"; ndays; day] -> Days (int_of_string ndays, int_of_string day)
+ | "Peer" :: i :: avail :: tail ->
+ Peer (int_of_string i, float_of_string avail, String.concat " " tail)
+ | ["End"] -> End
+ | ["Exponential"] -> Exponential
+ | ["Round"; round] -> Round (int_of_string round)
+ | ["On"; i] -> On (int_of_string i)
+ | ["Dead"; i] -> Dead (int_of_string i)
+ | ["Off"; i] -> Off (int_of_string i)
+ | _ -> failwith (Printf.sprintf "Bad line [%s]" (String.escaped line))
+
+let trace_read filename =
+ let exponential = ref false in
+ let ic = open_in filename in
+ let npeers = match trace_input ic with
+ Peers npeers -> npeers
+ | _ -> assert false
+ in
+ let (ndays, day) = match trace_input ic with
+ Days (ndays, day) -> ndays, day
+ | _ -> assert false
+ in
+
+ let rec read_peer ii =
+ match trace_input ic with
+ Exponential -> exponential := true;
+ read_peer ii
+ | Peer (i, avail, s) ->
+ let p = {
+ i = i;
+ avail = avail;
+ descr = s;
+ state = OFF;
+ real_avail = 0;
+ session = 0
+ } in
+ p
+ | _ -> assert false
+ in
+ let peers = Array.init npeers read_peer in
+ let event = ref None in
+ let get_event () =
+ let ev = trace_input ic in
+ event := Some ev
+ in
+
+ let rec iter_round round =
+ match !event with
+ None ->
+ next_event round
+ | Some ev ->
+ match ev with
+ Round rr ->
+ if rr = round then next_event round
+ | On i ->
+ event := None;
+ let p = peers.(i) in
+ p.state <- ON;
+ next_event round
+ | Off i ->
+ event := None;
+ let p = peers.(i) in
+ p.state <- OFF;
+ next_event round
+ | Dead i ->
+ event := None;
+ let p = peers.(i) in
+ p.state <- DEAD;
+ peers.(i) <- {
+ p with state = OFF;
+ };
+ next_event round
+ | End -> ()
+ | _ -> assert false
+
+ and next_event round =
+ get_event ();
+ iter_round round
+ in
+ peers, ndays * day, iter_round
diff --git a/sources/thibaut/trace.ml b/sources/thibaut/trace.ml
index aa74285..d47e576 100644
--- a/sources/thibaut/trace.ml
+++ b/sources/thibaut/trace.ml
@@ -9,7 +9,6 @@ type event =
| On of int
| Off of int
| End
- | Exponential
type peer = {
id : int;
@@ -30,16 +29,15 @@ let output oc trace_event =
| On i -> print "On %d\n" i
| Off i -> print "Off %d\n" i
| End -> print "End\n"
- | _ -> failwith "Invalid event"
let input ic =
let line = input_line ic in
let space = Str.regexp " " in
match Str.split space line with
| ["Peers"; npeers] -> Peers (int_of_string npeers)
- | ["Peer"; id; avail; state] -> Peer (int_of_string id,
- float_of_string avail,
- state_of_string state)
+ | ["Peer"; id; avail; state] ->
+ Peer (int_of_string id, float_of_string avail,
+ state_of_string state)
| ["Days"; ndays] -> Days (int_of_string ndays)
| ["End"] -> End
| ["Round"; round] -> Round (int_of_string round)
@@ -59,7 +57,7 @@ let read_info ic =
npeers, ndays
let read ic peers npeers =
- for i = 0 to (npeers-1) do
+ for i = 0 to (npeers-1) do
match input ic with
| Peer (i, avail, state) -> peers.(i).con_state <- state
| _ -> failwith "Not enough peers"
diff --git a/sources/thibaut/tracestats.ml b/sources/thibaut/tracestats.ml
new file mode 100644
index 0000000..94f254d
--- /dev/null
+++ b/sources/thibaut/tracestats.ml
@@ -0,0 +1,48 @@
+open Compattrace
+
+let usage = "tracestats <input> <output>"
+let inputfile = ref ""
+let outputfile = ref ""
+
+let anon =
+ let args = ref 0 in
+ fun s ->
+ incr args;
+ match !args with
+ | 1 -> inputfile := s
+ | 2 -> outputfile := s
+ | _ -> raise (Arg.Bad "Too many arguments")
+
+let _ =
+ if (Array.length Sys.argv) < 3 then begin
+ Printf.printf "Missing arguments.\n";
+ Arg.usage [] usage;
+ exit 1
+ end
+ else begin
+ Arg.parse [] anon usage
+ end;
+ let oc = open_out !outputfile in
+ let peers, nrounds, iter_round = Compattrace.trace_read !inputfile in
+ let npeers = Array.length peers in
+ let sessions = Array.make 100000 0 in
+ for i = 0 to (nrounds-1) do
+ iter_round i;
+ let nconnected = ref 0 in
+ for i = 0 to (npeers-1) do
+ let p = peers.(i) in
+ if p.state = ON then begin
+ p.real_avail <- p.real_avail + 1;
+ p.session <- p.session + 1;
+ incr nconnected
+ end
+ else if p.state = OFF then begin
+ if p.session > 0 then begin
+ sessions.(p.session) <- sessions.(p.session) + 1;
+ p.session <- 0;
+ end
+ end
+ done
+ done;
+ Array.iter (Printf.fprintf oc "%d\n") sessions
+