aboutsummaryrefslogtreecommitdiff
path: root/src/sensor
diff options
context:
space:
mode:
authorOmar Tarabai <tarabai@devegypt.com>2014-09-02 12:16:47 +0000
committerOmar Tarabai <tarabai@devegypt.com>2014-09-02 12:16:47 +0000
commita8b8940817e70e105dcbc884b81ad3390c5a074c (patch)
tree4baf3fe1033c5bccce14f385701f18a11f2b492f /src/sensor
parent955ff4fab42b80bb8e508cabbf683ffe2d1ae768 (diff)
downloadgnunet-a8b8940817e70e105dcbc884b81ad3390c5a074c.tar.gz
gnunet-a8b8940817e70e105dcbc884b81ad3390c5a074c.zip
sensor: towards profiler
Diffstat (limited to 'src/sensor')
-rw-r--r--src/sensor/gnunet-sensor-profiler.c33
-rw-r--r--src/sensor/plugin_sensor_model_gaussian.c2
-rw-r--r--src/sensor/profiler.py28
3 files changed, 57 insertions, 6 deletions
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c
index 10e0789e0..ba9ba28dd 100644
--- a/src/sensor/gnunet-sensor-profiler.c
+++ b/src/sensor/gnunet-sensor-profiler.c
@@ -134,6 +134,11 @@ static char **sensor_names;
134 */ 134 */
135static unsigned int sensor_names_size = 0; 135static unsigned int sensor_names_size = 0;
136 136
137/**
138 * Task run after any waiting period
139 */
140static GNUNET_SCHEDULER_TaskIdentifier delayed_task = GNUNET_SCHEDULER_NO_TASK;
141
137 142
138/** 143/**
139 * Copy directory recursively 144 * Copy directory recursively
@@ -155,6 +160,11 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
155 int i; 160 int i;
156 161
157 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n"); 162 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down.\n");
163 if (GNUNET_SCHEDULER_NO_TASK != delayed_task)
164 {
165 GNUNET_SCHEDULER_cancel (delayed_task);
166 delayed_task = GNUNET_SCHEDULER_NO_TASK;
167 }
158 if (NULL != cfg) 168 if (NULL != cfg)
159 { 169 {
160 GNUNET_CONFIGURATION_destroy (cfg); 170 GNUNET_CONFIGURATION_destroy (cfg);
@@ -422,6 +432,18 @@ peerstore_disconnect_adapter (void *cls, void *op_result)
422 432
423 433
424/** 434/**
435 * This function is called after the estimated training period is over.
436 */
437static void
438simulate_anomalies (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
439{
440 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
441 "Training period over, simulating anomalies now.\n");
442 //TODO
443}
444
445
446/**
425 * This function is called after a delay which ensures that all peers are 447 * This function is called after a delay which ensures that all peers are
426 * properly initialized 448 * properly initialized
427 */ 449 */
@@ -431,6 +453,7 @@ peers_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
431 unsigned long long int training_points; 453 unsigned long long int training_points;
432 struct GNUNET_TIME_Relative training_period; 454 struct GNUNET_TIME_Relative training_period;
433 455
456 delayed_task = GNUNET_SCHEDULER_NO_TASK;
434 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers are ready.\n"); 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers are ready.\n");
435 GNUNET_assert (GNUNET_OK == 458 GNUNET_assert (GNUNET_OK ==
436 GNUNET_CONFIGURATION_get_value_number (cfg, 459 GNUNET_CONFIGURATION_get_value_number (cfg,
@@ -447,7 +470,8 @@ peers_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
447 "Sleeping for a training period of %s.\n", 470 "Sleeping for a training period of %s.\n",
448 GNUNET_STRINGS_relative_time_to_string (training_period, 471 GNUNET_STRINGS_relative_time_to_string (training_period,
449 GNUNET_NO)); 472 GNUNET_NO));
450 //TODO 473 delayed_task =
474 GNUNET_SCHEDULER_add_delayed (training_period, &simulate_anomalies, NULL);
451} 475}
452 476
453 477
@@ -476,9 +500,10 @@ sensor_service_started (void *cls, struct GNUNET_TESTBED_Operation *op,
476 sensor_services_started++; 500 sensor_services_started++;
477 if (sensor_services_started == num_peers) 501 if (sensor_services_started == num_peers)
478 { 502 {
479 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply 503 delayed_task =
480 (PEER_STARTUP_TIME, num_peers), &peers_ready, 504 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
481 NULL); 505 (PEER_STARTUP_TIME, num_peers),
506 &peers_ready, NULL);
482 } 507 }
483} 508}
484 509
diff --git a/src/sensor/plugin_sensor_model_gaussian.c b/src/sensor/plugin_sensor_model_gaussian.c
index d1ce77ea7..8b4b09089 100644
--- a/src/sensor/plugin_sensor_model_gaussian.c
+++ b/src/sensor/plugin_sensor_model_gaussian.c
@@ -118,6 +118,8 @@ sensor_gaussian_model_feed (void *cls, double val)
118 update_sums (model, val); 118 update_sums (model, val);
119 return GNUNET_NO; 119 return GNUNET_NO;
120 } 120 }
121 if (model->n == plugin->training_window)
122 LOG (GNUNET_ERROR_TYPE_DEBUG, "Gaussian model out of training period.\n");
121 mean = model->sum / model->n; 123 mean = model->sum / model->n;
122 stddev = 124 stddev =
123 sqrt ((model->sumsq - 2 * mean * model->sum + 125 sqrt ((model->sumsq - 2 * mean * model->sum +
diff --git a/src/sensor/profiler.py b/src/sensor/profiler.py
index ce3d6844c..55187db1c 100644
--- a/src/sensor/profiler.py
+++ b/src/sensor/profiler.py
@@ -3,6 +3,9 @@ import math
3import networkx 3import networkx
4import random 4import random
5import tempfile 5import tempfile
6import os
7import time
8from subprocess import Popen, PIPE, STDOUT
6 9
7def get_args(): 10def get_args():
8 parser = argparse.ArgumentParser(description="Sensor profiler") 11 parser = argparse.ArgumentParser(description="Sensor profiler")
@@ -33,11 +36,31 @@ def create_topology_file(graph):
33 if len(nodes[i]) == 0: 36 if len(nodes[i]) == 0:
34 continue 37 continue
35 f.write('%d:' % i) 38 f.write('%d:' % i)
36 f.write('|'.join(map(str,nodes[i]))) 39 f.write('|'.join(map(str, nodes[i])))
37 f.write('\n') 40 f.write('\n')
38 #f.close() 41 # f.close()
39 return f.name 42 return f.name
40 43
44def handle_profiler_line(line):
45 if not line:
46 return
47 print line
48
49def run_profiler(peers, topology_file):
50 cmd = "GNUNET_FORCE_LOG='gnunet-sensor-profiler;;;;DEBUG' gnunet-sensor-profiler -p %d -t %s > log 2>&1" % (peers, topology_file)
51 process = Popen([cmd], shell=True)
52 time.sleep(0.5)
53 line = ''
54 f = open('log')
55 while process.poll() is None:
56 for c in f.read():
57 if not c or c == '\n':
58 handle_profiler_line(line)
59 line = ''
60 else:
61 line += c
62 os.remove('log')
63
41def main(): 64def main():
42 args = vars(get_args()) 65 args = vars(get_args())
43 num_peers = args['peers'] 66 num_peers = args['peers']
@@ -52,6 +75,7 @@ def main():
52 top_file = create_topology_file(graph) 75 top_file = create_topology_file(graph)
53 print 'Created TESTBED topology file %s' % top_file 76 print 'Created TESTBED topology file %s' % top_file
54 # Run c profiler 77 # Run c profiler
78 run_profiler(num_peers, top_file)
55 79
56if __name__ == "__main__": 80if __name__ == "__main__":
57 main() 81 main()