summaryrefslogtreecommitdiffstats
path: root/sources
diff options
context:
space:
mode:
authorthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-07-26 16:23:29 +0000
committerthibauth <thibauth@30fcff6e-8de6-41c7-acce-77ff6d1dd07b>2011-07-26 16:23:29 +0000
commit53fa8ee6cf50567765fd1a10d5689ad0e5970a67 (patch)
tree4fc64960707690a53545486e54184ae1c574087c /sources
parenta8b2b37331c7867798da8236fee816d44bf02b45 (diff)
downloadpacemaker-53fa8ee6cf50567765fd1a10d5689ad0e5970a67.tar.gz
Add some logging.
git-svn-id: https://scm.gforge.inria.fr/svn/pacemaker@48 30fcff6e-8de6-41c7-acce-77ff6d1dd07b
Diffstat (limited to 'sources')
-rw-r--r--sources/thibaut/Makefile3
-rw-r--r--sources/thibaut/client.ml22
-rw-r--r--sources/thibaut/clientArg.ml2
-rw-r--r--sources/thibaut/clientGlobals.ml39
-rw-r--r--sources/thibaut/clientMessages.ml6
5 files changed, 64 insertions, 8 deletions
diff --git a/sources/thibaut/Makefile b/sources/thibaut/Makefile
index 4c65bc3..2f6d482 100644
--- a/sources/thibaut/Makefile
+++ b/sources/thibaut/Makefile
@@ -36,8 +36,9 @@ $(BUILDDIR)/simulator: simulator.cmx
$(OCAMLOPT) -o $@ $(OCAMLFLAGS) $(LIBSOPT) globals.cmx graph.cmx pacemaker.cmx trace.cmx mesh.cmx simulator.cmx
clean:
- rm -f *.cm? *.cmx? *.o *~ *.annot \#*\#
+ rm -f *.cm? *.cmt? *.cmx? *.o *~ *.annot \#*\#
rm -f $(DEPEND)
+ rm -f *backup_*
depend: $(SRCS)
$(OCAMLDEP) $(SRCS) > $(DEPEND)
diff --git a/sources/thibaut/client.ml b/sources/thibaut/client.ml
index e4fae78..78e6fed 100644
--- a/sources/thibaut/client.ml
+++ b/sources/thibaut/client.ml
@@ -8,6 +8,7 @@ let round = ref 0
let reply_tick = 30.
let mesh_tick = 30.
let seed_tick = !accuracy/.2.
+let log_tick = 60.
let disconnect () = send_to_all Close
@@ -96,11 +97,27 @@ let next_round = ref (time +. !accuracy)
let next_pulse = ref (!next_round +. seed_tick)
let next_seed = ref (time +. reply_tick)
let next_mesh = ref (time +. mesh_tick)
+let next_log = ref (time +. log_tick)
let _ =
while true do
let time = Unix.gettimeofday() in
+ let tm = Unix.gmtime(time) in
+
+ if tm.tm_mday <> !currentday then begin
+ currentday := tm.tm_mday;
+ let a, b = lognames_of_time tm in
+ close_out !netlog_ic;
+ close_out !protlog_ic;
+ netlog_ic := open_out_gen [Open_append; Open_creat] 0o644 a;
+ protlog_ic := open_out_gen [Open_append; Open_creat] 0o644 b;
+ end;
+
+ if (time > !next_log) then begin
+ next_log := time +. log_tick;
+ Printf.fprintf !netlog_ic "%.0f %d\n%!" time (ClientSlots.length slots)
+ end;
if !server && (time > !next_round) then begin
init_round time;
@@ -131,4 +148,7 @@ let _ =
let len, addr = recvfrom t buff 0 max_length [] in
let s = String.sub buff 0 len in
process_message time s addr;
- done
+ done;
+ close_out !netlog_ic;
+ close_out !protlog_ic;
+
diff --git a/sources/thibaut/clientArg.ml b/sources/thibaut/clientArg.ml
index 1d092c1..43fdb5f 100644
--- a/sources/thibaut/clientArg.ml
+++ b/sources/thibaut/clientArg.ml
@@ -7,6 +7,7 @@ let id_file = ref "id.conf"
let generate = ref false
let degree = ref 10
let accuracy = ref 125.
+let logdir = ref "log"
let arg_list = Arg.align [
"--port", Arg.Set_int port, " <n> listening port";
@@ -16,6 +17,7 @@ let arg_list = Arg.align [
"--genid", Arg.Set generate, " generate the id file";
"--degree", Arg.Set_int degree, " <n> number of neighbours";
"--accuracy", Arg.Set_float accuracy, " <n> number of minutes between rounds";
+ "--log", Arg.Set_string logdir, " <directory> log directory"
]
let usage = Printf.sprintf "usage: %s [OPTIONS]" Sys.argv.(0)
diff --git a/sources/thibaut/clientGlobals.ml b/sources/thibaut/clientGlobals.ml
index 6ded853..72645d3 100644
--- a/sources/thibaut/clientGlobals.ml
+++ b/sources/thibaut/clientGlobals.ml
@@ -75,21 +75,52 @@ let safe_open f filename =
| Sys_error s -> Printf.eprintf "Could not open file: %s.\n" s; exit 1
let _ =
+ Random.self_init ();
Printf.printf "Pacemaker client v%s\n%!" version;
if !generate then begin
let id_oc = safe_open open_out !id_file in
- Random.self_init ();
Printf.fprintf id_oc "%d" (Random.int 500000000);
Printf.printf "Id generated in file %s\n%!" !id_file;
close_out id_oc;
exit 0
- end
+ end;
+ try
+ if not (Sys.file_exists !logdir) then
+ Unix.mkdir !logdir 0o755
+ else if not (Sys.is_directory !logdir) then begin
+ Printf.eprintf "%s is not a directory\n" !logdir;
+ exit 1
+ end;
+ with
+ | Unix.Unix_error (e,_,s) ->
+ Printf.eprintf "%s: Couldn't create output directory '%s'\n"
+ (Unix.error_message e) s;
+ exit 1
+
+let lognames_of_time tm =
+ (Filename.concat !logdir
+ (Printf.sprintf "%02d-%02d.net" tm.tm_mday tm.tm_mon),
+ Filename.concat !logdir
+ (Printf.sprintf "%02d-%02d.prot" tm.tm_mday tm.tm_mon)
+ )
+
+let network_logname, protocol_logname, currentday =
+ let tm = Unix.gmtime(Unix.gettimeofday()) in
+ let a, b = lognames_of_time tm in
+ a,b, (ref tm.tm_mday)
+
+let netlog_ic = ref (open_out_gen [Open_append; Open_creat] 0o644
+ network_logname)
+let protlog_ic = ref (open_out_gen [Open_append; Open_creat] 0o644
+ protocol_logname)
let id_ic = safe_open open_in !id_file
let my_id = Scanf.fscanf id_ic "%d" (fun x -> x)
let conf_ic = safe_open open_in !config_file
let root_addr, root_port = Scanf.fscanf conf_ic "%s\n%d" (fun a b -> a,b)
-let _ = close_in conf_ic; close_in id_ic
+let _ =
+ close_in conf_ic;
+ close_in id_ic
let my_addr = (gethostbyname(gethostname())).h_addr_list.(0)
let socketfd = socket PF_INET SOCK_DGRAM 0
@@ -114,7 +145,7 @@ let _ =
exit 1
let _ =
- Printf.printf "Now listening on UDP port %d\n%!" !port
+ Printf.printf "Now listening on UDP %s\n%!" (string_of_sockaddr addr)
let slots = ClientSlots.make !degree
diff --git a/sources/thibaut/clientMessages.ml b/sources/thibaut/clientMessages.ml
index 1fd86d0..b4147c0 100644
--- a/sources/thibaut/clientMessages.ml
+++ b/sources/thibaut/clientMessages.ml
@@ -39,7 +39,8 @@ let peer_init_round time round seed duration =
hmap = UserMap.add my_id (Hashtbl.hash seed) UserMap.empty;
replies = Queue.create()
} in
- rounds_data := RoundMap.add round data !rounds_data
+ Printf.fprintf !protlog_ic "%.0f Round %d\n%!" time round;
+ rounds_data := RoundMap.add round data !rounds_data
exception Found
@@ -108,7 +109,6 @@ let process_message time s addr =
| Pong -> update_time time message.id;
| Mesh ->
- update_time time message.id;
if !server then
process_mesh_server time message.id addr
else if (ClientSlots.mem message.id slots) then begin
@@ -176,6 +176,8 @@ let process_message time s addr =
let hash = UserMap.find my_id h in
let hmap = find_reply hash data.replies in
if verify_branch branch then begin
+ Printf.fprintf !protlog_ic "%.0f Proof %d\n%!"
+ time round;
let branch2 = hmap::branch in
let message = Pulse(round,seed,branch2) in
if data.phase = SEEDING then begin