diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-14 08:45:19 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-10-14 08:45:19 +0000 |
commit | 1f4ae04f7b05d0d471f2338e3da20e60b44d2f81 (patch) | |
tree | 904332484b01e67d6a7bce7055cfc7798b940c9a /src/testbed/gnunet-testbed-profiler.c | |
parent | 55dc3775de2049df85ce51f722c5b002094524b2 (diff) | |
download | gnunet-1f4ae04f7b05d0d471f2338e3da20e60b44d2f81.tar.gz gnunet-1f4ae04f7b05d0d471f2338e3da20e60b44d2f81.zip |
peer create
Diffstat (limited to 'src/testbed/gnunet-testbed-profiler.c')
-rw-r--r-- | src/testbed/gnunet-testbed-profiler.c | 92 |
1 files changed, 88 insertions, 4 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index 6bfc15728..bd973a9c0 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c | |||
@@ -75,7 +75,12 @@ enum State | |||
75 | /** | 75 | /** |
76 | * Starting slaves | 76 | * Starting slaves |
77 | */ | 77 | */ |
78 | STATE_SLAVES_STARTING | 78 | STATE_SLAVES_STARTING, |
79 | |||
80 | /** | ||
81 | * Creating peers | ||
82 | */ | ||
83 | STATE_PEERS_CREATING | ||
79 | }; | 84 | }; |
80 | 85 | ||
81 | 86 | ||
@@ -140,6 +145,16 @@ static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task; | |||
140 | uint64_t event_mask; | 145 | uint64_t event_mask; |
141 | 146 | ||
142 | /** | 147 | /** |
148 | * The starting time of a profiling step | ||
149 | */ | ||
150 | struct GNUNET_TIME_Absolute prof_start_time; | ||
151 | |||
152 | /** | ||
153 | * Duration profiling step has taken | ||
154 | */ | ||
155 | struct GNUNET_TIME_Relative prof_time; | ||
156 | |||
157 | /** | ||
143 | * Current peer id | 158 | * Current peer id |
144 | */ | 159 | */ |
145 | unsigned int peer_id; | 160 | unsigned int peer_id; |
@@ -176,12 +191,19 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
176 | { | 191 | { |
177 | struct DLLOperation *dll_op; | 192 | struct DLLOperation *dll_op; |
178 | unsigned int nhost; | 193 | unsigned int nhost; |
194 | unsigned int peer_cnt; | ||
179 | 195 | ||
180 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) | 196 | if (GNUNET_SCHEDULER_NO_TASK != abort_task) |
181 | GNUNET_SCHEDULER_cancel (abort_task); | 197 | GNUNET_SCHEDULER_cancel (abort_task); |
182 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) | 198 | if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task) |
183 | GNUNET_SCHEDULER_cancel (register_hosts_task); | 199 | GNUNET_SCHEDULER_cancel (register_hosts_task); |
184 | GNUNET_free_non_null (peers); | 200 | while (NULL != peers) |
201 | { | ||
202 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
203 | if (NULL != peers[peer_cnt]) | ||
204 | GNUNET_TESTBED_peer_destroy (peers[peer_cnt]); | ||
205 | GNUNET_free (peers); | ||
206 | } | ||
185 | if (NULL != reg_handle) | 207 | if (NULL != reg_handle) |
186 | GNUNET_TESTBED_cancel_registration (reg_handle); | 208 | GNUNET_TESTBED_cancel_registration (reg_handle); |
187 | for (nhost = 0; nhost < num_hosts; nhost++) | 209 | for (nhost = 0; nhost < num_hosts; nhost++) |
@@ -222,6 +244,49 @@ do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
222 | 244 | ||
223 | 245 | ||
224 | /** | 246 | /** |
247 | * Functions of this signature are called when a peer has been successfully | ||
248 | * created | ||
249 | * | ||
250 | * @param cls the closure from GNUNET_TESTBED_peer_create() | ||
251 | * @param peer the handle for the created peer; NULL on any error during | ||
252 | * creation | ||
253 | * @param emsg NULL if peer is not NULL; else MAY contain the error description | ||
254 | */ | ||
255 | static void | ||
256 | peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg) | ||
257 | { | ||
258 | struct DLLOperation *dll_op = cls; | ||
259 | struct GNUNET_TESTBED_Peer **peer_ptr; | ||
260 | static unsigned int created_peers; | ||
261 | |||
262 | if (NULL != emsg) | ||
263 | { | ||
264 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
265 | _("Creating a peer failed. Error: %s\n"), emsg); | ||
266 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
267 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
268 | GNUNET_free (dll_op); | ||
269 | GNUNET_SCHEDULER_cancel (abort_task); | ||
270 | abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL); | ||
271 | return; | ||
272 | } | ||
273 | peer_ptr = dll_op->cls; | ||
274 | GNUNET_assert (NULL == *peer_ptr); | ||
275 | *peer_ptr = peer; | ||
276 | GNUNET_TESTBED_operation_done (dll_op->op); | ||
277 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | ||
278 | GNUNET_free (dll_op); | ||
279 | if (++created_peers == num_peers) | ||
280 | { | ||
281 | prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time); | ||
282 | printf ("All peers created successfully in %.2f seconds\n", | ||
283 | ((double) prof_time.rel_value) / 1000.00); | ||
284 | /* Now peers are to be started */ | ||
285 | } | ||
286 | } | ||
287 | |||
288 | |||
289 | /** | ||
225 | * Controller event callback | 290 | * Controller event callback |
226 | * | 291 | * |
227 | * @param cls NULL | 292 | * @param cls NULL |
@@ -242,7 +307,8 @@ controller_event_cb (void *cls, | |||
242 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | 307 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
243 | { | 308 | { |
244 | static unsigned int slaves_started; | 309 | static unsigned int slaves_started; |
245 | 310 | unsigned int peer_cnt; | |
311 | |||
246 | dll_op = event->details.operation_finished.op_cls; | 312 | dll_op = event->details.operation_finished.op_cls; |
247 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); | 313 | GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op); |
248 | GNUNET_free (dll_op); | 314 | GNUNET_free (dll_op); |
@@ -259,7 +325,25 @@ controller_event_cb (void *cls, | |||
259 | GNUNET_TESTBED_operation_done (op); | 325 | GNUNET_TESTBED_operation_done (op); |
260 | /* Proceed to start peers */ | 326 | /* Proceed to start peers */ |
261 | if (++slaves_started == num_hosts - 1) | 327 | if (++slaves_started == num_hosts - 1) |
262 | printf ("All slaves started successfully\n"); | 328 | { |
329 | printf ("All slaves started successfully\n"); | ||
330 | state = STATE_PEERS_CREATING; | ||
331 | prof_start_time = GNUNET_TIME_absolute_get (); | ||
332 | peers = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *) | ||
333 | * num_peers); | ||
334 | for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++) | ||
335 | { | ||
336 | dll_op = GNUNET_malloc (sizeof (struct DLLOperation)); | ||
337 | dll_op->cls = &peers[peer_cnt]; | ||
338 | dll_op->op = GNUNET_TESTBED_peer_create (mc, | ||
339 | hosts | ||
340 | [peer_cnt % num_peers], | ||
341 | cfg, | ||
342 | &peer_create_cb, | ||
343 | dll_op); | ||
344 | GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op); | ||
345 | } | ||
346 | } | ||
263 | } | 347 | } |
264 | break; | 348 | break; |
265 | default: | 349 | default: |