gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r34259 - gnunet/src/sensor


From: gnunet
Subject: [GNUnet-SVN] r34259 - gnunet/src/sensor
Date: Tue, 2 Sep 2014 14:16:47 +0200

Author: otarabai
Date: 2014-09-02 14:16:47 +0200 (Tue, 02 Sep 2014)
New Revision: 34259

Modified:
   gnunet/src/sensor/gnunet-sensor-profiler.c
   gnunet/src/sensor/plugin_sensor_model_gaussian.c
   gnunet/src/sensor/profiler.py
Log:
sensor: towards profiler


Modified: gnunet/src/sensor/gnunet-sensor-profiler.c
===================================================================
--- gnunet/src/sensor/gnunet-sensor-profiler.c  2014-09-02 11:43:29 UTC (rev 
34258)
+++ gnunet/src/sensor/gnunet-sensor-profiler.c  2014-09-02 12:16:47 UTC (rev 
34259)
@@ -134,7 +134,12 @@
  */
 static unsigned int sensor_names_size = 0;
 
+/**
+ * Task run after any waiting period
+ */
+static GNUNET_SCHEDULER_TaskIdentifier delayed_task = GNUNET_SCHEDULER_NO_TASK;
 
+
 /**
  * Copy directory recursively
  *
@@ -155,6 +160,11 @@
   int i;
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n");
+  if (GNUNET_SCHEDULER_NO_TASK != delayed_task)
+  {
+    GNUNET_SCHEDULER_cancel (delayed_task);
+    delayed_task = GNUNET_SCHEDULER_NO_TASK;
+  }
   if (NULL != cfg)
   {
     GNUNET_CONFIGURATION_destroy (cfg);
@@ -422,6 +432,18 @@
 
 
 /**
+ * This function is called after the estimated training period is over.
+ */
+static void
+simulate_anomalies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Training period over, simulating anomalies now.\n");
+  //TODO
+}
+
+
+/**
  * This function is called after a delay which ensures that all peers are
  * properly initialized
  */
@@ -431,6 +453,7 @@
   unsigned long long int training_points;
   struct GNUNET_TIME_Relative training_period;
 
+  delayed_task = GNUNET_SCHEDULER_NO_TASK;
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers are ready.\n");
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CONFIGURATION_get_value_number (cfg,
@@ -447,7 +470,8 @@
               "Sleeping for a training period of %s.\n",
               GNUNET_STRINGS_relative_time_to_string (training_period,
                                                       GNUNET_NO));
-  //TODO
+  delayed_task =
+      GNUNET_SCHEDULER_add_delayed (training_period, &simulate_anomalies, 
NULL);
 }
 
 
@@ -476,9 +500,10 @@
   sensor_services_started++;
   if (sensor_services_started == num_peers)
   {
-    GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
-                                  (PEER_STARTUP_TIME, num_peers), &peers_ready,
-                                  NULL);
+    delayed_task =
+        GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
+                                      (PEER_STARTUP_TIME, num_peers),
+                                      &peers_ready, NULL);
   }
 }
 

Modified: gnunet/src/sensor/plugin_sensor_model_gaussian.c
===================================================================
--- gnunet/src/sensor/plugin_sensor_model_gaussian.c    2014-09-02 11:43:29 UTC 
(rev 34258)
+++ gnunet/src/sensor/plugin_sensor_model_gaussian.c    2014-09-02 12:16:47 UTC 
(rev 34259)
@@ -118,6 +118,8 @@
     update_sums (model, val);
     return GNUNET_NO;
   }
+  if (model->n == plugin->training_window)
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Gaussian model out of training period.\n");
   mean = model->sum / model->n;
   stddev =
       sqrt ((model->sumsq - 2 * mean * model->sum +

Modified: gnunet/src/sensor/profiler.py
===================================================================
--- gnunet/src/sensor/profiler.py       2014-09-02 11:43:29 UTC (rev 34258)
+++ gnunet/src/sensor/profiler.py       2014-09-02 12:16:47 UTC (rev 34259)
@@ -3,6 +3,9 @@
 import networkx
 import random
 import tempfile
+import os
+import time
+from subprocess import Popen, PIPE, STDOUT
 
 def get_args():
   parser = argparse.ArgumentParser(description="Sensor profiler")
@@ -33,11 +36,31 @@
     if len(nodes[i]) == 0:
       continue
     f.write('%d:' % i)
-    f.write('|'.join(map(str,nodes[i])))
+    f.write('|'.join(map(str, nodes[i])))
     f.write('\n')
-  #f.close()
+  # f.close()
   return f.name
 
+def handle_profiler_line(line):
+  if not line:
+    return
+  print line
+
+def run_profiler(peers, topology_file):
+  cmd = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' 
gnunet-sensor-profiler -p %d -t %s > log 2>&1" % (peers, topology_file)
+  process = Popen([cmd], shell=True)
+  time.sleep(0.5)
+  line = ''
+  f = open('log')
+  while process.poll() is None:
+    for c in f.read():
+      if not c or c == '\n':
+        handle_profiler_line(line)
+        line = ''
+      else:
+        line += c
+  os.remove('log')
+
 def main():
   args = vars(get_args())
   num_peers = args['peers']
@@ -52,6 +75,7 @@
   top_file = create_topology_file(graph)
   print 'Created TESTBED topology file %s' % top_file
   # Run c profiler
+  run_profiler(num_peers, top_file)
   
 if __name__ == "__main__":
   main()




reply via email to

[Prev in Thread] Current Thread [Next in Thread]