2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats-tests/ats-testing-log.c
22 * @brief ats benchmark: logging for performance tests
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
28 #include "ats-testing.h"
30 #define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
31 "set datafile separator ';' \n" \
32 "set title \"Throughput between Master and Slaves\" \n" \
33 "set xlabel \"Time in ms\" \n" \
34 "set ylabel \"Bytes/s\" \n" \
37 #define RTT_TEMPLATE "#!/usr/bin/gnuplot \n" \
38 "set datafile separator ';' \n" \
39 "set title \"Application level roundtrip time between Master and Slaves\" \n" \
40 "set xlabel \"Time in ms\" \n" \
41 "set ylabel \"ms\" \n" \
44 #define BW_TEMPLATE "#!/usr/bin/gnuplot \n" \
45 "set datafile separator ';' \n" \
46 "set title \"Bandwidth inbound and outbound between Master and Slaves\" \n" \
47 "set xlabel \"Time in ms\" \n" \
48 "set ylabel \"Bytes / s \" \n" \
51 #define LOG_ITEMS_TIME 2
52 #define LOG_ITEMS_PER_PEER 17
54 #define LOG_ITEM_BYTES_SENT 1
55 #define LOG_ITEM_MSGS_SENT 2
56 #define LOG_ITEM_THROUGHPUT_SENT 3
57 #define LOG_ITEM_BYTES_RECV 4
58 #define LOG_ITEM_MSGS_RECV 5
59 #define LOG_ITEM_THROUGHPUT_RECV 6
60 #define LOG_ITEM_APP_RTT 7
61 #define LOG_ITEM_ATS_BW_IN 8
62 #define LOG_ITEM_ATS_BW_OUT 9
63 #define LOG_ITEM_ATS_COSTS_LAN 10
64 #define LOG_ITEM_ATS_WAN 11
65 #define LOG_ITEM_ATS_WLAN 12
66 #define LOG_ITEM_ATS_DELAY 13
67 #define LOG_ITEM_ATS_DISTANCE 14
68 #define LOG_ITEM_ATS_NETWORKTYPE 15
69 #define LOG_ITEM_ATS_UTIL_UP 16
70 #define LOG_ITEM_ATS_UTIL_DOWN 17
73 * A single logging time step for a partner
75 struct PartnerLoggingTimestep
80 struct BenchmarkPeer *slave;
83 * Total number of messages this peer has sent
85 unsigned int total_messages_sent;
88 * Total number of bytes this peer has sent
90 unsigned int total_bytes_sent;
93 * Total number of messages this peer has received
95 unsigned int total_messages_received;
98 * Total number of bytes this peer has received
100 unsigned int total_bytes_received;
103 * Total outbound throughput for master in Bytes / s
105 unsigned int throughput_sent;
108 * Total inbound throughput for master in Bytes / s
110 unsigned int throughput_recv;
113 * Accumulated RTT for all messages
115 unsigned int total_app_rtt;
118 * Current application level delay
120 unsigned int app_rtt;
122 /* Current ATS properties */
124 uint32_t ats_distance;
128 uint32_t bandwidth_in;
130 uint32_t bandwidth_out;
132 uint32_t ats_utilization_up;
134 uint32_t ats_utilization_down;
136 uint32_t ats_network_type;
138 uint32_t ats_cost_wan;
140 uint32_t ats_cost_lan;
142 uint32_t ats_cost_wlan;
147 * A single logging time step for a peer
149 struct PeerLoggingTimestep
154 struct PeerLoggingTimestep *next;
159 struct PeerLoggingTimestep *prev;
164 struct GNUNET_TIME_Absolute timestamp;
167 * Total number of messages this peer has sent
169 unsigned int total_messages_sent;
172 * Total number of bytes this peer has sent
174 unsigned int total_bytes_sent;
177 * Total number of messages this peer has received
179 unsigned int total_messages_received;
182 * Total number of bytes this peer has received
184 unsigned int total_bytes_received;
187 * Total outbound throughput for master in Bytes / s
189 unsigned int total_throughput_send;
192 * Total inbound throughput for master in Bytes / s
194 unsigned int total_throughput_recv;
199 struct PartnerLoggingTimestep *slaves_log;
203 * Entry for a benchmark peer
210 struct BenchmarkPeer *peer;
215 struct GNUNET_TIME_Absolute start;
218 * DLL for logging entries: head
220 struct PeerLoggingTimestep *head;
223 * DLL for logging entries: tail
225 struct PeerLoggingTimestep *tail;
233 GNUNET_SCHEDULER_TaskIdentifier log_task;
236 * Reference to perf_ats' masters
241 struct GNUNET_TIME_Relative frequency;
244 * Log structure of length num_peers
246 struct LoggingPeer *lp;
252 write_throughput_gnuplot_script (char * fn, struct LoggingPeer *lp)
254 struct GNUNET_DISK_FileHandle *f;
260 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s",fn);
261 fprintf (stderr, "Writing throughput plot for master %u to `%s'\n",
264 f = GNUNET_DISK_file_open (gfn,
265 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
266 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
267 GNUNET_DISK_PERM_USER_WRITE);
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
277 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE,
278 strlen(THROUGHPUT_TEMPLATE)))
279 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
280 "Cannot write data to plot file `%s'\n", gfn);
282 /* Write master data */
283 peer_index = LOG_ITEMS_TIME;
284 GNUNET_asprintf (&data,
285 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
286 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
287 fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
288 fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
289 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
290 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
293 peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER ;
294 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
296 GNUNET_asprintf (&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
297 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
299 peer_index + LOG_ITEM_THROUGHPUT_SENT,
301 lp->peer->partners[c_s].dest->no,
303 peer_index + LOG_ITEM_THROUGHPUT_RECV,
305 lp->peer->partners[c_s].dest->no,
306 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
307 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
310 peer_index += LOG_ITEMS_PER_PEER;
313 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
314 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
315 "Cannot close gnuplot file `%s'\n", gfn);
317 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
318 "Data successfully written to plot file `%s'\n", gfn);
325 write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp)
327 struct GNUNET_DISK_FileHandle *f;
333 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s",fn);
334 fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
337 f = GNUNET_DISK_file_open (gfn,
338 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
339 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
340 GNUNET_DISK_PERM_USER_WRITE);
343 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
350 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE)))
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
353 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
354 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
356 GNUNET_asprintf (&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
357 (0 == c_s) ? "plot " :"",
358 fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no,
359 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
360 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
361 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
363 index += LOG_ITEMS_PER_PEER;
366 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
367 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
369 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
374 write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp)
376 struct GNUNET_DISK_FileHandle *f;
382 GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn);
383 fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
386 f = GNUNET_DISK_file_open (gfn,
387 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
388 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
389 GNUNET_DISK_PERM_USER_WRITE);
392 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
398 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE)))
399 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
400 "Cannot write data to plot file `%s'\n", gfn);
402 index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER;
403 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
405 GNUNET_asprintf (&data, "%s"\
406 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
407 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\
409 (0 == c_s) ? "plot " :"",
410 fn, index + LOG_ITEM_ATS_BW_OUT, lp->peer->no, lp->peer->partners[c_s].dest->no,
411 fn, index + LOG_ITEM_ATS_BW_IN, lp->peer->no, lp->peer->partners[c_s].dest->no,
412 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
413 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
414 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
416 index += LOG_ITEMS_PER_PEER;
419 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
420 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
422 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
428 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
429 char *experiment_name, int plots)
431 struct GNUNET_DISK_FileHandle *f;
436 char *slave_string_tmp;
437 struct PeerLoggingTimestep *cur_lt;
438 struct PartnerLoggingTimestep *plt;
439 struct GNUNET_TIME_Absolute timestamp;
444 timestamp = GNUNET_TIME_absolute_get();
446 tmp_exp_name = experiment_name;
447 if (NULL != strchr (experiment_name, '/'));
449 tmp_exp_name = strchr (experiment_name, '/');
453 for (c_m = 0; c_m < l->num_peers; c_m++)
455 GNUNET_asprintf (&filename_data, "%s_%llu_master_%u_%s_%s", tmp_exp_name,
456 timestamp.abs_value_us,
457 l->lp[c_m].peer->no, GNUNET_i2s(&l->lp[c_m].peer->id), l->name);
459 fprintf (stderr, "Writing master %u to file `%s'\n", c_m, filename_data);
461 f = GNUNET_DISK_file_open (filename_data,
462 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
463 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
466 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_data);
467 GNUNET_free (filename_data);
471 GNUNET_asprintf (&data, "# master peers: %u ; slave peers: %u ; experiment : %s\n",
472 l->num_peers, l->lp[c_m].peer->num_partners, experiment_name);
473 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
474 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
475 "Cannot write data to log file `%s'\n", filename_data);
478 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
480 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
481 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
484 GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
485 cur_lt->timestamp).rel_value_us / 1000,
486 cur_lt->total_messages_sent,
487 cur_lt->total_bytes_sent,
488 cur_lt->total_throughput_send,
489 cur_lt->total_messages_received,
490 cur_lt->total_bytes_received,
491 cur_lt->total_throughput_recv);
493 slave_string = GNUNET_strdup (";");
494 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
496 plt = &cur_lt->slaves_log[c_s];
499 /* Assembling slave string */
500 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
501 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n",
503 plt->total_messages_sent,
504 plt->total_bytes_sent,
505 plt->throughput_sent,
506 plt->total_messages_received,
507 plt->total_bytes_received,
508 plt->throughput_recv,
514 GNUNET_asprintf(&slave_string_tmp,
515 "%s%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;",
517 plt->total_messages_sent,
518 plt->total_bytes_sent,
519 plt->throughput_sent,
520 plt->total_messages_received,
521 plt->total_bytes_received,
522 plt->throughput_sent,
523 (double) plt->app_rtt / 1000,
531 plt->ats_network_type,
532 plt->ats_utilization_up,
533 plt->ats_utilization_down);
534 GNUNET_free (slave_string);
535 slave_string = slave_string_tmp;
537 /* Assembling master string */
538 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;;;;;;;;;;;%s\n",
540 GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
541 cur_lt->timestamp).rel_value_us / 1000,
542 cur_lt->total_messages_sent,
543 cur_lt->total_bytes_sent,
544 cur_lt->total_throughput_send,
545 cur_lt->total_messages_received,
546 cur_lt->total_bytes_received,
547 cur_lt->total_throughput_recv,
549 GNUNET_free (slave_string);
551 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
552 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
553 "Cannot write data to log file `%s'\n", filename_data);
556 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
558 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
559 "Cannot close log file `%s'\n", filename_data);
560 GNUNET_free (filename_data);
564 if (GNUNET_YES == plots)
566 write_throughput_gnuplot_script (filename_data, &l->lp[c_m]);
567 write_rtt_gnuplot_script (filename_data, &l->lp[c_m]);
568 write_bw_gnuplot_script (filename_data, &l->lp[c_m]);
571 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
572 "Data file successfully written to log file `%s'\n", filename_data);
573 GNUNET_free (filename_data);
580 * @param l logging handle to use
583 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
585 struct LoggingPeer *bp;
586 struct PeerLoggingTimestep *mlt;
587 struct PeerLoggingTimestep *prev_log_mlt;
588 struct PartnerLoggingTimestep *slt;
589 struct PartnerLoggingTimestep *prev_log_slt;
590 struct BenchmarkPartner *p;
591 struct GNUNET_TIME_Relative delta;
594 unsigned int app_rtt;
597 if (GNUNET_YES != l->running)
600 for (c_m = 0; c_m < l->num_peers; c_m++)
603 mlt = GNUNET_new (struct PeerLoggingTimestep);
604 GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt);
605 prev_log_mlt = mlt->prev;
608 /* Current master state */
609 mlt->timestamp = GNUNET_TIME_absolute_get();
610 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
611 mlt->total_messages_sent = bp->peer->total_messages_sent;
612 mlt->total_bytes_received = bp->peer->total_bytes_received;
613 mlt->total_messages_received = bp->peer->total_messages_received;
616 if (NULL == prev_log_mlt)
618 /* Get difference to start */
619 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start, mlt->timestamp);
623 /* Get difference to last timestep */
624 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
627 /* Multiplication factor for throughput calculation */
628 mult = (1.0 * 1000 * 1000) / (delta.rel_value_us);
630 /* Total throughput */
631 if (NULL != prev_log_mlt)
633 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
634 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
636 mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
638 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
639 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
641 mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
645 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
646 mlt->total_throughput_send = mult * mlt->total_bytes_received;
649 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
650 sizeof (struct PartnerLoggingTimestep));
652 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
655 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
656 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
658 p = &bp->peer->partners[c_s];
659 slt = &mlt->slaves_log[c_s];
661 slt->slave = p->dest;
662 /* Bytes sent from master to this slave */
663 slt->total_bytes_sent = p->bytes_sent;
664 /* Messages sent from master to this slave */
665 slt->total_messages_sent = p->messages_sent;
666 /* Bytes master received from this slave */
667 slt->total_bytes_received = p->bytes_received;
668 /* Messages master received from this slave */
669 slt->total_messages_received = p->messages_received;
670 slt->total_app_rtt = p->total_app_rtt;
671 /* ats performance information */
672 slt->ats_cost_lan = p->ats_cost_lan;
673 slt->ats_cost_wan = p->ats_cost_wan;
674 slt->ats_cost_wlan = p->ats_cost_wlan;
675 slt->ats_delay = p->ats_delay;
676 slt->ats_distance = p->ats_distance;
677 slt->ats_network_type = p->ats_network_type;
678 slt->ats_utilization_down = p->ats_utilization_down;
679 slt->ats_utilization_up = p->ats_utilization_up;
680 slt->bandwidth_in = p->bandwidth_in;
681 slt->bandwidth_out = p->bandwidth_out;
683 /* Total application level rtt */
684 if (NULL == prev_log_mlt)
686 if (0 != slt->total_messages_sent)
687 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
693 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
694 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
695 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
696 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
698 app_rtt = prev_log_slt->app_rtt; /* No messages were */
700 slt->app_rtt = app_rtt;
702 /* Partner throughput */
703 if (NULL != prev_log_mlt)
705 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
706 if (slt->total_bytes_sent - prev_log_slt->total_bytes_sent > 0)
707 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
709 slt->throughput_sent = prev_log_slt->throughput_sent; /* no msgs send */
711 if (slt->total_bytes_received - prev_log_slt->total_bytes_received > 0)
712 slt->throughput_recv = mult * (slt->total_bytes_received - prev_log_slt->total_bytes_received);
714 slt->throughput_recv = prev_log_slt->throughput_recv; /* no msgs received */
718 slt->throughput_sent = mult * slt->total_bytes_sent;
719 slt->throughput_sent = mult * slt->total_bytes_received;
722 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
723 "Master [%u]: slave [%u]\n",
724 bp->peer->no, p->dest->no);
730 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
732 struct LoggingHandle *l = cls;
733 l->log_task = GNUNET_SCHEDULER_NO_TASK;
735 GNUNET_ATS_TEST_logging_now (l);
737 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
740 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
741 &collect_log_task, l);
747 * @param l the logging handle
750 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
752 struct GNUNET_SCHEDULER_TaskContext tc;
753 if (GNUNET_YES!= l->running)
756 if (GNUNET_SCHEDULER_NO_TASK != l->log_task)
757 GNUNET_SCHEDULER_cancel (l->log_task);
758 l->log_task = GNUNET_SCHEDULER_NO_TASK;
759 tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
760 collect_log_task (l, &tc);
761 l->running = GNUNET_NO;
763 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
764 _("Stop logging\n"));
768 * Clean up logging data
770 * @param l the logging handle
773 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
776 struct PeerLoggingTimestep *cur;
778 if (GNUNET_YES == l->running)
779 GNUNET_ATS_TEST_logging_stop (l);
781 for (c_m = 0; c_m < l->num_peers; c_m++)
783 while (NULL != (cur = l->lp[c_m].head))
785 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
786 GNUNET_free (cur->slaves_log);
799 * @param log_frequency the logging frequency
800 * @param testname the testname
801 * @param masters the master peers used for benchmarking
802 * @param num_masters the number of master peers
803 * @return the logging handle or NULL on error
805 struct LoggingHandle *
806 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
807 char *testname, struct BenchmarkPeer *masters, int num_masters)
809 struct LoggingHandle *l;
811 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
812 _("Start logging `%s'\n"), testname);
814 l = GNUNET_new (struct LoggingHandle);
815 l->num_peers = num_masters;
817 l->frequency = log_frequency;
818 l->lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
820 for (c_m = 0; c_m < num_masters; c_m ++)
822 l->lp[c_m].peer = &masters[c_m];
823 l->lp[c_m].start = GNUNET_TIME_absolute_get();
826 /* Schedule logging task */
827 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
828 l->running = GNUNET_YES;
832 /* end of file ats-testing-log.c */