diff options
author | Omar Tarabai <tarabai@devegypt.com> | 2014-09-01 17:17:29 +0000 |
---|---|---|
committer | Omar Tarabai <tarabai@devegypt.com> | 2014-09-01 17:17:29 +0000 |
commit | 9ce41f5b2d0673bfe837651a4a5a83dec31b7fb2 (patch) | |
tree | 8a80a34137263099abe4bc05a084cc82cd0581e4 /src/sensor | |
parent | aedac3a94ffc0d4563964a591b5ed35a72857a23 (diff) | |
download | gnunet-9ce41f5b2d0673bfe837651a4a5a83dec31b7fb2.tar.gz gnunet-9ce41f5b2d0673bfe837651a4a5a83dec31b7fb2.zip |
sensor: towards profiler
Diffstat (limited to 'src/sensor')
-rw-r--r-- | src/sensor/gnunet-sensor-profiler.c | 43 | ||||
-rw-r--r-- | src/sensor/profiler.py | 57 |
2 files changed, 84 insertions, 16 deletions
diff --git a/src/sensor/gnunet-sensor-profiler.c b/src/sensor/gnunet-sensor-profiler.c index 814413ba1..e89e0f025 100644 --- a/src/sensor/gnunet-sensor-profiler.c +++ b/src/sensor/gnunet-sensor-profiler.c | |||
@@ -19,16 +19,6 @@ | |||
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * TODO: | ||
23 | * - Run X peers | ||
24 | * - Rewrite interval time (optional) | ||
25 | * - Run 1 dashboard | ||
26 | * - Monitor dashboard records | ||
27 | * - Prompt for anomalies when ready: | ||
28 | * -- Cut Y peers (remove their connections to other X-Y peers but not the connections among themselves) | ||
29 | */ | ||
30 | |||
31 | /** | ||
32 | * @file sensor/gnunet-sensor-profiler.c | 22 | * @file sensor/gnunet-sensor-profiler.c |
33 | * @brief Profiler for the sensor service | 23 | * @brief Profiler for the sensor service |
34 | * @author Omar Tarabai | 24 | * @author Omar Tarabai |
@@ -41,6 +31,11 @@ | |||
41 | #include "gnunet_sensor_util_lib.h" | 31 | #include "gnunet_sensor_util_lib.h" |
42 | 32 | ||
43 | /** | 33 | /** |
34 | * Time to wait for the peer to startup completely | ||
35 | */ | ||
36 | #define PEER_STARTUP_TIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1) | ||
37 | |||
38 | /** | ||
44 | * Information about a single peer | 39 | * Information about a single peer |
45 | */ | 40 | */ |
46 | struct PeerInfo | 41 | struct PeerInfo |
@@ -150,7 +145,7 @@ copy_dir (const char *src, const char *dst); | |||
150 | * Do clean up and shutdown scheduler | 145 | * Do clean up and shutdown scheduler |
151 | */ | 146 | */ |
152 | static void | 147 | static void |
153 | do_shutdown () // TODO: schedule timeout shutdown | 148 | do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
154 | { | 149 | { |
155 | int i; | 150 | int i; |
156 | 151 | ||
@@ -308,7 +303,6 @@ dashboard_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
308 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n"); | 303 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Dashboard service started.\n"); |
309 | GNUNET_TESTBED_operation_done (op); | 304 | GNUNET_TESTBED_operation_done (op); |
310 | dashboard_service_started = GNUNET_YES; | 305 | dashboard_service_started = GNUNET_YES; |
311 | //TODO: | ||
312 | } | 306 | } |
313 | 307 | ||
314 | 308 | ||
@@ -418,6 +412,18 @@ peerstore_disconnect_adapter (void *cls, void *op_result) | |||
418 | 412 | ||
419 | 413 | ||
420 | /** | 414 | /** |
415 | * This function is called after a delay which ensures that all peers are | ||
416 | * properly initialized | ||
417 | */ | ||
418 | static void | ||
419 | peers_ready (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
420 | { | ||
421 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "All peers are ready.\n"); | ||
422 | //TODO | ||
423 | } | ||
424 | |||
425 | |||
426 | /** | ||
421 | * Callback to be called when sensor service is started | 427 | * Callback to be called when sensor service is started |
422 | * | 428 | * |
423 | * @param cls the callback closure from functions generating an operation | 429 | * @param cls the callback closure from functions generating an operation |
@@ -440,9 +446,12 @@ sensor_service_started (void *cls, struct GNUNET_TESTBED_Operation *op, | |||
440 | GNUNET_i2s (&peer->peer_id)); | 446 | GNUNET_i2s (&peer->peer_id)); |
441 | GNUNET_TESTBED_operation_done (op); | 447 | GNUNET_TESTBED_operation_done (op); |
442 | sensor_services_started++; | 448 | sensor_services_started++; |
443 | if (sensor_services_started == num_peers) //TODO: remove | 449 | if (sensor_services_started == num_peers) |
444 | do_shutdown (); | 450 | { |
445 | //TODO | 451 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply |
452 | (PEER_STARTUP_TIME, num_peers), &peers_ready, | ||
453 | NULL); | ||
454 | } | ||
446 | } | 455 | } |
447 | 456 | ||
448 | 457 | ||
@@ -575,7 +584,7 @@ run (void *cls, char *const *args, const char *cf, | |||
575 | 584 | ||
576 | if (GNUNET_OK != verify_args ()) | 585 | if (GNUNET_OK != verify_args ()) |
577 | { | 586 | { |
578 | do_shutdown (); | 587 | do_shutdown (NULL, NULL); |
579 | return; | 588 | return; |
580 | } | 589 | } |
581 | cfg = GNUNET_CONFIGURATION_create (); | 590 | cfg = GNUNET_CONFIGURATION_create (); |
@@ -584,6 +593,8 @@ run (void *cls, char *const *args, const char *cf, | |||
584 | cfg, "TESTBED", | 593 | cfg, "TESTBED", |
585 | "OVERLAY_TOPOLOGY_FILE", | 594 | "OVERLAY_TOPOLOGY_FILE", |
586 | topology_file); | 595 | topology_file); |
596 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &do_shutdown, | ||
597 | NULL); | ||
587 | GNUNET_TESTBED_run (NULL, cfg, num_peers, 0, NULL, NULL, &test_master, NULL); | 598 | GNUNET_TESTBED_run (NULL, cfg, num_peers, 0, NULL, NULL, &test_master, NULL); |
588 | GNUNET_CONFIGURATION_destroy (cfg); | 599 | GNUNET_CONFIGURATION_destroy (cfg); |
589 | } | 600 | } |
diff --git a/src/sensor/profiler.py b/src/sensor/profiler.py new file mode 100644 index 000000000..ce3d6844c --- /dev/null +++ b/src/sensor/profiler.py | |||
@@ -0,0 +1,57 @@ | |||
1 | import argparse | ||
2 | import math | ||
3 | import networkx | ||
4 | import random | ||
5 | import tempfile | ||
6 | |||
7 | def get_args(): | ||
8 | parser = argparse.ArgumentParser(description="Sensor profiler") | ||
9 | parser.add_argument('-p', '--peers', action='store', type=int, required=True, | ||
10 | help='Number of peers to run') | ||
11 | return parser.parse_args() | ||
12 | |||
13 | def generate_topology(peers, links): | ||
14 | G = networkx.empty_graph(peers) | ||
15 | for i in range(0, links): | ||
16 | a = 0 | ||
17 | b = 0 | ||
18 | while a == b: | ||
19 | a = random.randint(0, peers) | ||
20 | b = random.randint(0, peers) | ||
21 | G.add_edge(a, b) | ||
22 | return G | ||
23 | |||
24 | def create_topology_file(graph): | ||
25 | nodes = list() | ||
26 | for i in range(len(graph.edge)): | ||
27 | nodes.append(list()) | ||
28 | for e in graph.edges(): | ||
29 | nodes[e[0]].append(e[1]) | ||
30 | print nodes | ||
31 | f = tempfile.NamedTemporaryFile(delete=False) | ||
32 | for i in range(len(nodes)): | ||
33 | if len(nodes[i]) == 0: | ||
34 | continue | ||
35 | f.write('%d:' % i) | ||
36 | f.write('|'.join(map(str,nodes[i]))) | ||
37 | f.write('\n') | ||
38 | #f.close() | ||
39 | return f.name | ||
40 | |||
41 | def main(): | ||
42 | args = vars(get_args()) | ||
43 | num_peers = args['peers'] | ||
44 | if num_peers < 3: | ||
45 | print 'Min number of peers is 3' | ||
46 | return | ||
47 | num_links = int(math.log(num_peers) * math.log(num_peers) * num_peers / 2) | ||
48 | # Generate random topology | ||
49 | graph = generate_topology(num_peers, num_links) | ||
50 | print 'Generated random topology with %d peers and %d links' % (num_peers, num_links) | ||
51 | # Create TESTBED topology file | ||
52 | top_file = create_topology_file(graph) | ||
53 | print 'Created TESTBED topology file %s' % top_file | ||
54 | # Run c profiler | ||
55 | |||
56 | if __name__ == "__main__": | ||
57 | main() | ||