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;
144 double pref_bandwidth;
150 * A single logging time step for a peer
152 struct PeerLoggingTimestep
157 struct PeerLoggingTimestep *next;
162 struct PeerLoggingTimestep *prev;
167 struct GNUNET_TIME_Absolute timestamp;
170 * Total number of messages this peer has sent
172 unsigned int total_messages_sent;
175 * Total number of bytes this peer has sent
177 unsigned int total_bytes_sent;
180 * Total number of messages this peer has received
182 unsigned int total_messages_received;
185 * Total number of bytes this peer has received
187 unsigned int total_bytes_received;
190 * Total outbound throughput for master in Bytes / s
192 unsigned int total_throughput_send;
195 * Total inbound throughput for master in Bytes / s
197 unsigned int total_throughput_recv;
202 struct PartnerLoggingTimestep *slaves_log;
206 * Entry for a benchmark peer
213 struct BenchmarkPeer *peer;
218 struct GNUNET_TIME_Absolute start;
221 * DLL for logging entries: head
223 struct PeerLoggingTimestep *head;
226 * DLL for logging entries: tail
228 struct PeerLoggingTimestep *tail;
236 GNUNET_SCHEDULER_TaskIdentifier log_task;
239 * Reference to perf_ats' masters
246 struct GNUNET_TIME_Relative frequency;
249 * Log structure of length num_peers
251 struct LoggingPeer *lp;
257 write_throughput_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves)
259 struct GNUNET_DISK_FileHandle *f;
264 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s",fn);
265 fprintf (stderr, "Writing throughput plot for master %u and %u slaves to `%s'\n",
266 lp->peer->no, slaves, gfn);
268 f = GNUNET_DISK_file_open (gfn,
269 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
270 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
271 GNUNET_DISK_PERM_USER_WRITE);
274 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
280 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE,
281 strlen(THROUGHPUT_TEMPLATE)))
282 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
283 "Cannot write data to plot file `%s'\n", gfn);
285 /* Write master data */
286 GNUNET_asprintf (&data,
287 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
288 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
289 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
290 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
291 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
295 for (c_s = 0; c_s < slaves; c_s++)
297 GNUNET_asprintf (&data, "'%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) ? ", \\" : "\n pause -1");
308 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
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);
324 write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves)
326 struct GNUNET_DISK_FileHandle *f;
331 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s",fn);
332 fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
335 f = GNUNET_DISK_file_open (gfn,
336 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
337 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
338 GNUNET_DISK_PERM_USER_WRITE);
341 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
347 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE)))
348 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
350 for (c_s = 0; c_s < slaves; c_s++)
352 GNUNET_asprintf (&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
353 (0 == c_s) ? "plot " :"",
355 LOG_ITEMS_TIME + LOG_ITEM_APP_RTT,
357 lp->peer->partners[c_s].dest->no,
358 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
359 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
360 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
364 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
365 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
367 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
372 write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves)
374 struct GNUNET_DISK_FileHandle *f;
379 GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn);
380 fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
383 f = GNUNET_DISK_file_open (gfn,
384 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
385 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
386 GNUNET_DISK_PERM_USER_WRITE);
389 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
395 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE)))
396 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
397 "Cannot write data to plot file `%s'\n", gfn);
399 for (c_s = 0; c_s < slaves; c_s++)
401 GNUNET_asprintf (&data, "%s"\
402 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
403 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\
405 (0 == c_s) ? "plot " :"",
407 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT,
410 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN,
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);
418 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
419 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
421 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
427 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
428 char *experiment_name, int plots)
430 struct GNUNET_DISK_FileHandle *f[l->num_slaves];
431 struct GNUNET_DISK_FileHandle *f_m;
433 char *filename_master;
434 char *filename_slaves[l->num_slaves];
436 struct PeerLoggingTimestep *cur_lt;
437 struct PartnerLoggingTimestep *plt;
438 struct GNUNET_TIME_Absolute timestamp;
443 timestamp = GNUNET_TIME_absolute_get();
445 tmp_exp_name = experiment_name;
446 for (c_m = 0; c_m < l->num_masters; c_m++)
448 GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s",
449 experiment_name, timestamp.abs_value_us, c_m, l->name);
450 fprintf (stderr, "Writing data for master %u to file `%s'\n",
451 c_m,filename_master);
453 f_m = GNUNET_DISK_file_open (filename_master,
454 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
455 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
458 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_master);
459 GNUNET_free (filename_master);
463 GNUNET_asprintf (&data, "# master %u; experiment : %s\n"
464 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n" ,
465 c_m, experiment_name);
466 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
467 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
468 "Cannot write data to log file `%s'\n",filename_master);
471 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
473 GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s",
474 tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name);
476 fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n",
477 c_m, c_s, filename_slaves[c_s]);
479 f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s],
480 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
481 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
484 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_slaves[c_s]);
485 GNUNET_free (filename_slaves[c_s]);
490 GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
491 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
492 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
493 "pref bandwidth; pref delay\n",
494 c_m, c_s, experiment_name);
495 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
496 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
497 "Cannot write data to log file `%s'\n",filename_slaves[c_s]);
501 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
505 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
507 (long long unsigned int) cur_lt->timestamp.abs_value_us,
508 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
509 cur_lt->timestamp).rel_value_us / 1000,
510 cur_lt->total_messages_sent,
511 cur_lt->total_bytes_sent,
512 cur_lt->total_throughput_send,
513 cur_lt->total_messages_received,
514 cur_lt->total_bytes_received,
515 cur_lt->total_throughput_recv);
517 /* Assembling master string */
518 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
519 (long long unsigned int) cur_lt->timestamp.abs_value_us,
520 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
521 cur_lt->timestamp).rel_value_us / 1000,
522 cur_lt->total_messages_sent,
523 cur_lt->total_bytes_sent,
524 cur_lt->total_throughput_send,
525 cur_lt->total_messages_received,
526 cur_lt->total_bytes_received,
527 cur_lt->total_throughput_recv);
529 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
530 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
531 "Cannot write data to master file %u\n", c_m);
535 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
537 plt = &cur_lt->slaves_log[c_s];
540 /* Assembling slave string */
541 GNUNET_asprintf(&data,
542 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
543 (long long unsigned int) cur_lt->timestamp.abs_value_us,
544 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
545 cur_lt->timestamp).rel_value_us / 1000,
546 plt->total_messages_sent,
547 plt->total_bytes_sent,
548 plt->throughput_sent,
549 plt->total_messages_received,
550 plt->total_bytes_received,
551 plt->throughput_recv,
552 (double) plt->app_rtt / 1000,
560 plt->ats_network_type,
561 plt->ats_utilization_up,
562 plt->ats_utilization_down,
568 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n",
570 plt->total_messages_sent,
571 plt->total_bytes_sent,
572 plt->throughput_sent,
573 plt->total_messages_received,
574 plt->total_bytes_received,
575 plt->throughput_recv,
581 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
582 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
583 "Cannot write data to log file `%s'\n", filename_slaves[c_s]);
589 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
591 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f[c_s]))
593 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
594 "Cannot close log file for master[%u] slave[%u]\n", c_m, c_s);
597 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
598 "Data file successfully written to log file for `%s'\n",
599 filename_slaves[c_s]);
602 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f_m))
604 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
605 "Cannot close log file `%s'\n", filename_master);
608 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
609 "Data file successfully written to log file for master `%s'\n", filename_master);
611 if (GNUNET_YES == plots)
613 write_throughput_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
614 write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
615 write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
618 GNUNET_free (filename_master);
624 * @param l logging handle to use
627 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
629 struct LoggingPeer *bp;
630 struct PeerLoggingTimestep *mlt;
631 struct PeerLoggingTimestep *prev_log_mlt;
632 struct PartnerLoggingTimestep *slt;
633 struct PartnerLoggingTimestep *prev_log_slt;
634 struct BenchmarkPartner *p;
635 struct GNUNET_TIME_Relative delta;
638 unsigned int app_rtt;
641 if (GNUNET_YES != l->running)
644 for (c_m = 0; c_m < l->num_masters; c_m++)
647 mlt = GNUNET_new (struct PeerLoggingTimestep);
648 GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt);
649 prev_log_mlt = mlt->prev;
652 /* Current master state */
653 mlt->timestamp = GNUNET_TIME_absolute_get();
654 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
655 mlt->total_messages_sent = bp->peer->total_messages_sent;
656 mlt->total_bytes_received = bp->peer->total_bytes_received;
657 mlt->total_messages_received = bp->peer->total_messages_received;
660 if (NULL == prev_log_mlt)
662 /* Get difference to start */
663 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start, mlt->timestamp);
667 /* Get difference to last timestep */
668 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
671 /* Multiplication factor for throughput calculation */
672 mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us / (delta.rel_value_us);
674 /* Total throughput */
675 if (NULL != prev_log_mlt)
677 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
679 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
683 mlt->total_throughput_send = 0;
684 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
687 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
689 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
693 mlt->total_throughput_send = 0;
694 //mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
699 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
700 mlt->total_throughput_send = mult * mlt->total_bytes_received;
703 if (GNUNET_YES == l->verbose)
705 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
706 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", c_m,
708 mlt->total_bytes_sent,
709 mlt->total_bytes_received,
710 mlt->total_throughput_send,
711 mlt->total_throughput_recv);
714 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
715 sizeof (struct PartnerLoggingTimestep));
717 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
719 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
720 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
722 p = &bp->peer->partners[c_s];
723 slt = &mlt->slaves_log[c_s];
725 slt->slave = p->dest;
726 /* Bytes sent from master to this slave */
727 slt->total_bytes_sent = p->bytes_sent;
728 /* Messages sent from master to this slave */
729 slt->total_messages_sent = p->messages_sent;
730 /* Bytes master received from this slave */
731 slt->total_bytes_received = p->bytes_received;
732 /* Messages master received from this slave */
733 slt->total_messages_received = p->messages_received;
734 slt->total_app_rtt = p->total_app_rtt;
735 /* ats performance information */
736 slt->ats_cost_lan = p->ats_cost_lan;
737 slt->ats_cost_wan = p->ats_cost_wan;
738 slt->ats_cost_wlan = p->ats_cost_wlan;
739 slt->ats_delay = p->ats_delay;
740 slt->ats_distance = p->ats_distance;
741 slt->ats_network_type = p->ats_network_type;
742 slt->ats_utilization_down = p->ats_utilization_down;
743 slt->ats_utilization_up = p->ats_utilization_up;
744 slt->bandwidth_in = p->bandwidth_in;
745 slt->bandwidth_out = p->bandwidth_out;
746 slt->pref_bandwidth = p->pref_bandwidth;
747 slt->pref_delay = p->pref_delay;
749 /* Total application level rtt */
750 if (NULL == prev_log_mlt)
752 if (0 != slt->total_messages_sent)
753 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
759 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
760 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
761 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
762 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
765 app_rtt = prev_log_slt->app_rtt; /* No messages were */
768 slt->app_rtt = app_rtt;
770 /* Partner throughput */
771 if (NULL != prev_log_mlt)
773 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
774 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
775 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
777 slt->throughput_sent = 0;
779 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
780 slt->throughput_recv = mult *
781 (slt->total_bytes_received - prev_log_slt->total_bytes_received);
783 slt->throughput_recv = 0;
787 slt->throughput_sent = mult * slt->total_bytes_sent;
788 slt->throughput_recv = mult * slt->total_bytes_received;
791 if (GNUNET_YES == l->verbose)
793 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
794 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
797 mlt->total_bytes_sent,
798 mlt->total_bytes_received,
799 slt->throughput_sent,
800 slt->throughput_recv);
803 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
804 "Master [%u]: slave [%u]\n",
805 bp->peer->no, p->dest->no);
811 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
813 struct LoggingHandle *l = cls;
814 l->log_task = GNUNET_SCHEDULER_NO_TASK;
816 GNUNET_ATS_TEST_logging_now (l);
818 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
821 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
822 &collect_log_task, l);
828 * @param l the logging handle
831 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
833 if (GNUNET_YES!= l->running)
836 if (GNUNET_SCHEDULER_NO_TASK != l->log_task)
837 GNUNET_SCHEDULER_cancel (l->log_task);
838 l->log_task = GNUNET_SCHEDULER_NO_TASK;
839 l->running = GNUNET_NO;
841 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
842 _("Stop logging\n"));
846 * Clean up logging data
848 * @param l the logging handle
851 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
854 struct PeerLoggingTimestep *cur;
856 if (GNUNET_YES == l->running)
857 GNUNET_ATS_TEST_logging_stop (l);
859 for (c_m = 0; c_m < l->num_masters; c_m++)
861 while (NULL != (cur = l->lp[c_m].head))
863 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
864 GNUNET_free (cur->slaves_log);
877 * @param log_frequency the logging frequency
878 * @param testname the testname
879 * @param masters the master peers used for benchmarking
880 * @param num_masters the number of master peers
881 * @param num_slaves the number of slave peers
882 * @param verbose verbose logging
883 * @return the logging handle or NULL on error
885 struct LoggingHandle *
886 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
887 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
890 struct LoggingHandle *l;
892 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
893 _("Start logging `%s'\n"), testname);
895 l = GNUNET_new (struct LoggingHandle);
896 l->num_masters = num_masters;
897 l->num_slaves = num_slaves;
899 l->frequency = log_frequency;
900 l->verbose = verbose;
901 l->lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
903 for (c_m = 0; c_m < num_masters; c_m ++)
905 l->lp[c_m].peer = &masters[c_m];
906 l->lp[c_m].start = GNUNET_TIME_absolute_get();
909 /* Schedule logging task */
910 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
911 l->running = GNUNET_YES;
915 /* end of file ats-testing-log.c */