summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-06-24 16:17:15 +0000
committerthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-06-24 16:17:15 +0000
commit53d01038a4f7a22e442c254f60088f647a1d5a92 (patch)
treea301994f95c4e267757270b4b8e317af2dc97e1e /sources
parentf1dfeb216b97003c8dc3e50b783ecbea5ea7aece (diff)
downloadpacemaker-53d01038a4f7a22e442c254f60088f647a1d5a92.tar.gz
Export simulation data to a file to be plotted
git-svn-id: https://scm.gforge.inria.fr/svn/pacemaker@33 30fcff6e-8de6-41c7-acce-77ff6d1dd07b
Diffstat (limited to 'sources')
-rw-r--r--sources/thibaut/Makefile12
-rw-r--r--sources/thibaut/plot.py4
-rw-r--r--sources/thibaut/simulator.ml41
3 files changed, 35 insertions, 22 deletions
diff --git a/sources/thibaut/Makefile b/sources/thibaut/Makefile
index 6f1c6dc..6509a09 100644
--- a/sources/thibaut/Makefile
+++ b/sources/thibaut/Makefile
@@ -1,6 +1,6 @@
-OCAMLC=ocamlc.opt
-OCAMLOPT=ocamlopt.opt
-OCAMLDEP=ocamldep.opt
+OCAMLC=ocamlc
+OCAMLOPT=ocamlopt
+OCAMLDEP=ocamldep
INCLUDES=
OCAMLFLAGS=$(INCLUDES)
SRCS=map2.ml simulator.ml trace.ml gentrace.ml pacemaker.ml globals.ml compattrace.ml tracestats.ml mesh.ml graph.ml
@@ -13,13 +13,13 @@ $(BUILDDIR):
mkdir -p $(BUILDDIR)
tracestats.opt: $(BUILDDIR) tracestats.cmx
- $(OCAMLOPT) -o $(BUILDDIR)/tracestats $(OCAMLFLAGS) str.cmxa compattrace.cmx tracestats.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/tracestats $(OCAMLFLAGS) unix.cmxa str.cmxa compattrace.cmx tracestats.cmx
gentrace.opt: $(BUILDDIR) gentrace.cmx
- $(OCAMLOPT) -o $(BUILDDIR)/gentrace $(OCAMLFLAGS) str.cmxa map2.cmx globals.cmx pacemaker.cmx trace.cmx gentrace.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/gentrace $(OCAMLFLAGS) unix.cmxa str.cmxa map2.cmx globals.cmx pacemaker.cmx trace.cmx gentrace.cmx
simulator.opt : $(BUILDDIR) simulator.cmx
- $(OCAMLOPT) -o $(BUILDDIR)/simulator $(OCAMLFLAGS) str.cmxa map2.cmx globals.cmx graph.cmx pacemaker.cmx trace.cmx mesh.cmx simulator.cmx
+ $(OCAMLOPT) -o $(BUILDDIR)/simulator $(OCAMLFLAGS) unix.cmxa str.cmxa map2.cmx globals.cmx graph.cmx pacemaker.cmx trace.cmx mesh.cmx simulator.cmx
clean:
rm -f *.cm? *.cmx? *.o *~
diff --git a/sources/thibaut/plot.py b/sources/thibaut/plot.py
index a639bf7..3a30ad4 100644
--- a/sources/thibaut/plot.py
+++ b/sources/thibaut/plot.py
@@ -1,5 +1,7 @@
import numpy as np
import matplotlib.pyplot as plt
-a = np.loadtxt('test.data', unpack=True)
+import sys
+filename = sys.argv[1]
+a = np.loadtxt(filename, unpack=True, usecols=(1,))
plt.plot(a)
plt.show()
diff --git a/sources/thibaut/simulator.ml b/sources/thibaut/simulator.ml
index 4af40cf..9c4a3a5 100644
--- a/sources/thibaut/simulator.ml
+++ b/sources/thibaut/simulator.ml
@@ -8,14 +8,17 @@ let tpm = ref 3
let accuracy = ref 60
let duration = ref 24
let seed = ref 0
-let filename = ref ""
+let tracename = ref ""
+let datadir = ref "data"
+let outputdir = ref ""
let arg_list = [
"--degree", Arg.Set_int degree, " <n> maximum number of neighbours";
"--tpm", Arg.Set_int tpm, " <n> number of ticks per minute";
"--accuracy", Arg.Set_int accuracy, " <n> number of ticks between rounds";
"--duration", Arg.Set_int duration, " <n> number of ticks during seeding";
- "--seed", Arg.Set_int seed, " <n> random seed"
+ "--seed", Arg.Set_int seed, " <n> random seed";
+ "--datadir", Arg.Set_string datadir, " <path> the directory where the simulation data will be stored"
]
let anon =
@@ -23,22 +26,36 @@ let anon =
fun s ->
incr args;
match !args with
- | 1 -> filename := s
+ | 1 -> tracename := s
| _ -> raise (Arg.Bad "Too many arguments")
let usage = "usage: simul [OPTIONS] <tracefile>"
let _ =
+ Printf.printf "Pacemaker simulator\n";
if Array.length Sys.argv < 2 then begin
Arg.usage (Arg.align arg_list) usage;
exit 1
end else begin
Arg.parse (Arg.align arg_list) anon usage;
- Random.init !seed
+ Random.init !seed;
+ outputdir := Filename.concat !datadir (Filename.chop_extension (Filename.basename !tracename));
+ if not (Sys.file_exists !datadir) then
+ try
+ Unix.mkdir !datadir 0o755
+ with
+ Unix.Unix_error (e,_,_) -> failwith (Printf.sprintf "%s: Couldn't create data directory %s" (Unix.error_message e) !datadir)
+ else if not (Sys.is_directory !datadir) then
+ failwith (Printf.sprintf "%s is not a directory" !datadir);
+ if not (Sys.file_exists !outputdir) then
+ try
+ Unix.mkdir !outputdir 0o755
+ with
+ Unix.Unix_error (e,_,_) -> failwith (Printf.sprintf "%s: Couldn't create output directory %s" (Unix.error_message e) !outputdir)
end
-let ic = open_in !filename
-
+let ic = open_in !tracename
+let oc = open_out (Filename.concat !outputdir "rounds.data")
let npeers, days = Trace.read_info ic
let peers = Array.init npeers (fun i ->
@@ -63,6 +80,7 @@ let round = ref 0
let connected = ref 0
let _ =
+ Printf.fprintf oc "#minute connected messages asks askroots olds\n%!";
for i = 0 to (nticks-1) do
connected := 1;
Pacemaker.messages := 0;
@@ -94,17 +112,10 @@ let _ =
random_iter do_peer peers tracking_array;
if i mod !tpm = 0 then begin
- Printf.printf "Minute %d, " (i/(!tpm));
- Printf.printf "Connected: %d, " !connected;
- Printf.printf "Messages: %d, " !Pacemaker.messages;
- Printf.printf "Asks: %d, " !Mesh.ask;
- Printf.printf "Askroots: %d" !Mesh.askroot;
- print_newline ();
-
+ Printf.fprintf oc "%d %d %d %d %d " (i/(!tpm)) !connected !Pacemaker.messages !Mesh.ask !Mesh.askroot;
update_distances peers tracking_array;
let rep, old = repart (i/(!tpm)) peers in
- Printf.printf "Olds: %d" old;
- print_newline ();
+ Printf.fprintf oc "%d\n%!" old;
for i = 0 to Array.length rep - 1 do
Printf.printf "%d, " rep.(i)
done;