2 This file is part of GNUnet.
3 Copyright (C) 2010-2013 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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 unsigned int ats_distance;
126 struct GNUNET_TIME_Relative ats_delay;
128 uint32_t bandwidth_in;
130 uint32_t bandwidth_out;
132 uint32_t ats_utilization_out;
134 uint32_t ats_utilization_in;
136 enum GNUNET_NetworkType ats_network_type;
138 double pref_bandwidth;
144 * A single logging time step for a peer
146 struct PeerLoggingTimestep
151 struct PeerLoggingTimestep *next;
156 struct PeerLoggingTimestep *prev;
161 struct GNUNET_TIME_Absolute timestamp;
164 * Total number of messages this peer has sent
166 unsigned int total_messages_sent;
169 * Total number of bytes this peer has sent
171 unsigned int total_bytes_sent;
174 * Total number of messages this peer has received
176 unsigned int total_messages_received;
179 * Total number of bytes this peer has received
181 unsigned int total_bytes_received;
184 * Total outbound throughput for master in Bytes / s
186 unsigned int total_throughput_send;
189 * Total inbound throughput for master in Bytes / s
191 unsigned int total_throughput_recv;
196 struct PartnerLoggingTimestep *slaves_log;
200 * Entry for a benchmark peer
207 struct BenchmarkPeer *peer;
212 struct GNUNET_TIME_Absolute start;
215 * DLL for logging entries: head
217 struct PeerLoggingTimestep *head;
220 * DLL for logging entries: tail
222 struct PeerLoggingTimestep *tail;
230 struct GNUNET_SCHEDULER_Task *log_task;
233 * Reference to perf_ats' masters
240 struct GNUNET_TIME_Relative frequency;
243 * Log structure of length num_peers
245 struct LoggingPeer *lp;
251 write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs,
254 struct GNUNET_DISK_FileHandle *f;
259 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn);
261 "Writing throughput plot for master %u and %u slaves to `%s'\n",
262 lp->peer->no, slaves, gfn);
264 f = GNUNET_DISK_file_open (gfn,
265 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
266 GNUNET_DISK_PERM_USER_EXEC
267 | GNUNET_DISK_PERM_USER_READ
268 | GNUNET_DISK_PERM_USER_WRITE);
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
278 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE,
279 strlen (THROUGHPUT_TEMPLATE)))
280 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
281 "Cannot write data to plot file `%s'\n", gfn);
283 /* Write master data */
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, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
288 fn, LOG_ITEMS_TIME + 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,
291 "Cannot write data to plot file `%s'\n", gfn);
294 for (c_s = 0; c_s < slaves; c_s++)
296 GNUNET_asprintf (&data,
297 "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
298 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
300 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT,
302 lp->peer->partners[c_s].dest->no,
304 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV,
306 lp->peer->partners[c_s].dest->no,
307 (c_s < lp->peer->num_partners - 1) ? ", \\" :
309 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
311 "Cannot write data to plot file `%s'\n", gfn);
315 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
316 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
317 "Cannot close gnuplot file `%s'\n", gfn);
319 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
320 "Data successfully written to plot file `%s'\n", gfn);
326 write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
329 struct GNUNET_DISK_FileHandle *f;
334 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn);
335 fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
338 f = GNUNET_DISK_file_open (gfn,
339 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
340 GNUNET_DISK_PERM_USER_EXEC
341 | GNUNET_DISK_PERM_USER_READ
342 | GNUNET_DISK_PERM_USER_WRITE);
345 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
352 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen (
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
355 "Cannot write data to plot file `%s'\n", gfn);
357 for (c_s = 0; c_s < slaves; c_s++)
359 GNUNET_asprintf (&data,
360 "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
361 (0 == c_s) ? "plot " : "",
363 LOG_ITEMS_TIME + LOG_ITEM_APP_RTT,
365 lp->peer->partners[c_s].dest->no,
366 (c_s < lp->peer->num_partners - 1) ? ", \\" :
368 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
369 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
370 "Cannot write data to plot file `%s'\n", gfn);
374 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
378 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
379 "Data successfully written to plot file `%s'\n", gfn);
384 write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int
387 struct GNUNET_DISK_FileHandle *f;
392 GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn);
393 fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
396 f = GNUNET_DISK_file_open (gfn,
397 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
398 GNUNET_DISK_PERM_USER_EXEC
399 | GNUNET_DISK_PERM_USER_READ
400 | GNUNET_DISK_PERM_USER_WRITE);
403 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n",
410 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen (
412 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
413 "Cannot write data to plot file `%s'\n", gfn);
415 for (c_s = 0; c_s < slaves; c_s++)
417 GNUNET_asprintf (&data, "%s" \
418 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
419 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \
421 (0 == c_s) ? "plot " : "",
423 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT,
426 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN,
428 (c_s < lp->peer->num_partners - 1) ? ", \\" :
430 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data)))
431 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
432 "Cannot write data to plot file `%s'\n", gfn);
436 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f))
437 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n",
440 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
441 "Data successfully written to plot file `%s'\n", gfn);
447 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
448 const char *experiment_name,
451 struct GNUNET_DISK_FileHandle *f[l->num_slaves];
452 struct GNUNET_DISK_FileHandle *f_m;
453 const char *tmp_exp_name;
454 char *filename_master;
455 char *filename_slaves[l->num_slaves];
457 struct PeerLoggingTimestep *cur_lt;
458 struct PartnerLoggingTimestep *plt;
459 struct GNUNET_TIME_Absolute timestamp;
464 timestamp = GNUNET_TIME_absolute_get ();
466 tmp_exp_name = experiment_name;
467 for (c_m = 0; c_m < l->num_masters; c_m++)
469 GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s",
470 experiment_name, timestamp.abs_value_us, c_m, l->name);
471 fprintf (stderr, "Writing data for master %u to file `%s'\n",
472 c_m, filename_master);
474 f_m = GNUNET_DISK_file_open (filename_master,
475 GNUNET_DISK_OPEN_WRITE
476 | GNUNET_DISK_OPEN_CREATE,
477 GNUNET_DISK_PERM_USER_READ
478 | GNUNET_DISK_PERM_USER_WRITE);
481 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
483 GNUNET_free (filename_master);
487 GNUNET_asprintf (&data, "# master %u; experiment : %s\n"
488 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n",
489 c_m, experiment_name);
490 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
491 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
492 "Cannot write data to log file `%s'\n", filename_master);
495 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
497 GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s",
498 tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name);
500 fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n",
501 c_m, c_s, filename_slaves[c_s]);
503 f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s],
504 GNUNET_DISK_OPEN_WRITE
505 | GNUNET_DISK_OPEN_CREATE,
506 GNUNET_DISK_PERM_USER_READ
507 | GNUNET_DISK_PERM_USER_WRITE);
510 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n",
511 filename_slaves[c_s]);
512 GNUNET_free (filename_slaves[c_s]);
513 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (f_m));
514 GNUNET_free (filename_master);
519 GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
520 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
521 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
522 "pref bandwidth; pref delay\n",
523 c_m, c_s, experiment_name);
524 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (data)))
525 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
526 "Cannot write data to log file `%s'\n",
527 filename_slaves[c_s]);
531 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
535 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
537 (long long unsigned int) cur_lt->timestamp.abs_value_us,
538 (long long unsigned int) GNUNET_TIME_absolute_get_difference (
541 ->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 /* Assembling master string */
550 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
551 (long long unsigned int) cur_lt->timestamp.abs_value_us,
553 int) GNUNET_TIME_absolute_get_difference (
558 cur_lt->total_messages_sent,
559 cur_lt->total_bytes_sent,
560 cur_lt->total_throughput_send,
561 cur_lt->total_messages_received,
562 cur_lt->total_bytes_received,
563 cur_lt->total_throughput_recv);
565 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data)))
566 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
567 "Cannot write data to master file %u\n", c_m);
571 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
573 plt = &cur_lt->slaves_log[c_s];
576 /* Assembling slave string */
577 GNUNET_asprintf (&data,
578 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
580 int) cur_lt->timestamp.abs_value_us,
582 int) GNUNET_TIME_absolute_get_difference (
586 .rel_value_us / 1000,
587 plt->total_messages_sent,
588 plt->total_bytes_sent,
589 plt->throughput_sent,
590 plt->total_messages_received,
591 plt->total_bytes_received,
592 plt->throughput_recv,
593 (double) plt->app_rtt / 1000,
598 plt->ats_network_type,
599 plt->ats_utilization_out,
600 plt->ats_utilization_in,
606 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n",
608 plt->total_messages_sent,
609 plt->total_bytes_sent,
610 plt->throughput_sent,
611 plt->total_messages_received,
612 plt->total_bytes_received,
613 plt->throughput_recv,
615 (long long unsigned int) plt->ats_delay.rel_value_us,
619 if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (
621 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
622 "Cannot write data to log file `%s'\n",
623 filename_slaves[c_s]);
628 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
630 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f[c_s]))
632 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
633 "Cannot close log file for master[%u] slave[%u]\n", c_m,
637 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
638 "Data file successfully written to log file for `%s'\n",
639 filename_slaves[c_s]);
642 if (GNUNET_SYSERR == GNUNET_DISK_file_close (f_m))
644 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
647 GNUNET_free (filename_master);
650 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
651 "Data file successfully written to log file for master `%s'\n",
654 if (GNUNET_YES == plots)
656 write_throughput_gnuplot_script (filename_master, &l->lp[c_m],
657 filename_slaves, l->num_slaves);
658 write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
660 write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves,
664 GNUNET_free (filename_master);
670 * @param l logging handle to use
673 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
675 struct LoggingPeer *bp;
676 struct PeerLoggingTimestep *mlt;
677 struct PeerLoggingTimestep *prev_log_mlt;
678 struct PartnerLoggingTimestep *slt;
679 struct PartnerLoggingTimestep *prev_log_slt;
680 struct BenchmarkPartner *p;
681 struct GNUNET_TIME_Relative delta;
684 unsigned int app_rtt;
687 if (GNUNET_YES != l->running)
690 for (c_m = 0; c_m < l->num_masters; c_m++)
693 mlt = GNUNET_new (struct PeerLoggingTimestep);
694 GNUNET_CONTAINER_DLL_insert_tail (l->lp[c_m].head, l->lp[c_m].tail, mlt);
695 prev_log_mlt = mlt->prev;
698 /* Current master state */
699 mlt->timestamp = GNUNET_TIME_absolute_get ();
700 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
701 mlt->total_messages_sent = bp->peer->total_messages_sent;
702 mlt->total_bytes_received = bp->peer->total_bytes_received;
703 mlt->total_messages_received = bp->peer->total_messages_received;
706 if (NULL == prev_log_mlt)
708 /* Get difference to start */
709 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start,
714 /* Get difference to last timestep */
715 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp,
719 /* Multiplication factor for throughput calculation */
720 mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us
721 / (delta.rel_value_us);
723 /* Total throughput */
724 if (NULL != prev_log_mlt)
726 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
728 mlt->total_throughput_send = mult * (mlt->total_bytes_sent
729 - mlt->prev->total_bytes_sent);
733 mlt->total_throughput_send = 0;
734 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
737 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
739 mlt->total_throughput_recv = mult * (mlt->total_bytes_received
740 - mlt->prev->total_bytes_received);
744 mlt->total_throughput_recv = 0;
745 // mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
750 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
751 mlt->total_throughput_recv = mult * mlt->total_bytes_received;
754 if (GNUNET_YES == l->verbose)
756 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
757 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
759 (unsigned long long) delta.rel_value_us,
760 mlt->total_bytes_sent,
761 mlt->total_bytes_received,
762 mlt->total_throughput_send,
763 mlt->total_throughput_recv);
766 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners
767 * sizeof(struct PartnerLoggingTimestep));
769 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
771 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
772 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
774 p = &bp->peer->partners[c_s];
775 slt = &mlt->slaves_log[c_s];
777 slt->slave = p->dest;
778 /* Bytes sent from master to this slave */
779 slt->total_bytes_sent = p->bytes_sent;
780 /* Messages sent from master to this slave */
781 slt->total_messages_sent = p->messages_sent;
782 /* Bytes master received from this slave */
783 slt->total_bytes_received = p->bytes_received;
784 /* Messages master received from this slave */
785 slt->total_messages_received = p->messages_received;
786 slt->total_app_rtt = p->total_app_rtt;
787 /* ats performance information */
788 slt->ats_delay = p->props.delay;
789 slt->ats_distance = p->props.distance;
790 slt->ats_network_type = p->props.scope;
791 slt->ats_utilization_in = p->props.utilization_out;
792 slt->ats_utilization_out = p->props.utilization_out;
793 slt->bandwidth_in = p->bandwidth_in;
794 slt->bandwidth_out = p->bandwidth_out;
795 slt->pref_bandwidth = p->pref_bandwidth;
796 slt->pref_delay = p->pref_delay;
798 /* Total application level rtt */
799 if (NULL == prev_log_mlt)
801 if (0 != slt->total_messages_sent)
802 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
808 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
809 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
810 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt)
811 / (slt->total_messages_sent
812 - prev_log_slt->total_messages_sent);
815 app_rtt = prev_log_slt->app_rtt; /* No messages were */
818 slt->app_rtt = app_rtt;
820 /* Partner throughput */
821 if (NULL != prev_log_mlt)
823 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
824 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
825 slt->throughput_sent = mult * (slt->total_bytes_sent
826 - prev_log_slt->total_bytes_sent);
828 slt->throughput_sent = 0;
830 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
831 slt->throughput_recv = mult
832 * (slt->total_bytes_received
833 - prev_log_slt->total_bytes_received);
835 slt->throughput_recv = 0;
839 slt->throughput_sent = mult * slt->total_bytes_sent;
840 slt->throughput_recv = mult * slt->total_bytes_received;
843 if (GNUNET_YES == l->verbose)
845 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
846 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
848 (unsigned long long) delta.rel_value_us,
849 mlt->total_bytes_sent,
850 mlt->total_bytes_received,
851 slt->throughput_sent,
852 slt->throughput_recv);
855 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856 "Master [%u]: slave [%u]\n",
857 bp->peer->no, p->dest->no);
864 collect_log_task (void *cls)
866 struct LoggingHandle *l = cls;
869 GNUNET_ATS_TEST_logging_now (l);
870 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
879 * @param l the logging handle
882 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
884 if (GNUNET_YES != l->running)
887 if (NULL != l->log_task)
889 GNUNET_SCHEDULER_cancel (l->log_task);
892 l->running = GNUNET_NO;
894 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
895 _ ("Stop logging\n"));
899 * Clean up logging data
901 * @param l the logging handle
904 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
907 struct PeerLoggingTimestep *cur;
909 if (GNUNET_YES == l->running)
910 GNUNET_ATS_TEST_logging_stop (l);
912 for (c_m = 0; c_m < l->num_masters; c_m++)
914 while (NULL != (cur = l->lp[c_m].head))
916 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
917 GNUNET_free (cur->slaves_log);
930 * @param log_frequency the logging frequency
931 * @param testname the testname
932 * @param masters the master peers used for benchmarking
933 * @param num_masters the number of master peers
934 * @param num_slaves the number of slave peers
935 * @param verbose verbose logging
936 * @return the logging handle or NULL on error
938 struct LoggingHandle *
939 GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency,
940 const char *testname,
941 struct BenchmarkPeer *masters,
946 struct LoggingHandle *l;
949 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
950 _ ("Start logging `%s'\n"), testname);
952 l = GNUNET_new (struct LoggingHandle);
953 l->num_masters = num_masters;
954 l->num_slaves = num_slaves;
956 l->frequency = log_frequency;
957 l->verbose = verbose;
958 l->lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer));
960 for (c_m = 0; c_m < num_masters; c_m++)
962 l->lp[c_m].peer = &masters[c_m];
963 l->lp[c_m].start = GNUNET_TIME_absolute_get ();
966 /* Schedule logging task */
967 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
968 l->running = GNUNET_YES;
972 /* end of file ats-testing-log.c */