2 This file is part of GNUnet.
3 Copyright (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 struct GNUNET_SCHEDULER_Task * 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]);
486 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close(f_m));
487 GNUNET_free (filename_master);
492 GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
493 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
494 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
495 "pref bandwidth; pref delay\n",
496 c_m, c_s, experiment_name);
497 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
498 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
499 "Cannot write data to log file `%s'\n",filename_slaves[c_s]);
503 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
507 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
509 (long long unsigned int) cur_lt->timestamp.abs_value_us,
510 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
511 cur_lt->timestamp).rel_value_us / 1000,
512 cur_lt->total_messages_sent,
513 cur_lt->total_bytes_sent,
514 cur_lt->total_throughput_send,
515 cur_lt->total_messages_received,
516 cur_lt->total_bytes_received,
517 cur_lt->total_throughput_recv);
519 /* Assembling master string */
520 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
521 (long long unsigned int) cur_lt->timestamp.abs_value_us,
522 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
523 cur_lt->timestamp).rel_value_us / 1000,
524 cur_lt->total_messages_sent,
525 cur_lt->total_bytes_sent,
526 cur_lt->total_throughput_send,
527 cur_lt->total_messages_received,
528 cur_lt->total_bytes_received,
529 cur_lt->total_throughput_recv);
531 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
532 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
533 "Cannot write data to master file %u\n", c_m);
537 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
539 plt = &cur_lt->slaves_log[c_s];
542 /* Assembling slave string */
543 GNUNET_asprintf(&data,
544 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
545 (long long unsigned int) cur_lt->timestamp.abs_value_us,
546 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
547 cur_lt->timestamp).rel_value_us / 1000,
548 plt->total_messages_sent,
549 plt->total_bytes_sent,
550 plt->throughput_sent,
551 plt->total_messages_received,
552 plt->total_bytes_received,
553 plt->throughput_recv,
554 (double) plt->app_rtt / 1000,
562 plt->ats_network_type,
563 plt->ats_utilization_up,
564 plt->ats_utilization_down,
570 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %u bw_in %u bw_out %u \n",
572 plt->total_messages_sent,
573 plt->total_bytes_sent,
574 plt->throughput_sent,
575 plt->total_messages_received,
576 plt->total_bytes_received,
577 plt->throughput_recv,
583 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
584 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
585 "Cannot write data to log file `%s'\n", filename_slaves[c_s]);
591 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
593 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f[c_s]))
595 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
596 "Cannot close log file for master[%u] slave[%u]\n", c_m, c_s);
599 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
600 "Data file successfully written to log file for `%s'\n",
601 filename_slaves[c_s]);
604 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f_m))
606 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
609 GNUNET_free (filename_master);
612 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
613 "Data file successfully written to log file for master `%s'\n", filename_master);
615 if (GNUNET_YES == plots)
617 write_throughput_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
618 write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
619 write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
622 GNUNET_free (filename_master);
628 * @param l logging handle to use
631 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
633 struct LoggingPeer *bp;
634 struct PeerLoggingTimestep *mlt;
635 struct PeerLoggingTimestep *prev_log_mlt;
636 struct PartnerLoggingTimestep *slt;
637 struct PartnerLoggingTimestep *prev_log_slt;
638 struct BenchmarkPartner *p;
639 struct GNUNET_TIME_Relative delta;
642 unsigned int app_rtt;
645 if (GNUNET_YES != l->running)
648 for (c_m = 0; c_m < l->num_masters; c_m++)
651 mlt = GNUNET_new (struct PeerLoggingTimestep);
652 GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt);
653 prev_log_mlt = mlt->prev;
656 /* Current master state */
657 mlt->timestamp = GNUNET_TIME_absolute_get();
658 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
659 mlt->total_messages_sent = bp->peer->total_messages_sent;
660 mlt->total_bytes_received = bp->peer->total_bytes_received;
661 mlt->total_messages_received = bp->peer->total_messages_received;
664 if (NULL == prev_log_mlt)
666 /* Get difference to start */
667 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start, mlt->timestamp);
671 /* Get difference to last timestep */
672 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
675 /* Multiplication factor for throughput calculation */
676 mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us / (delta.rel_value_us);
678 /* Total throughput */
679 if (NULL != prev_log_mlt)
681 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
683 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
687 mlt->total_throughput_send = 0;
688 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
691 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
693 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
697 mlt->total_throughput_send = 0;
698 //mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
703 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
704 mlt->total_throughput_send = mult * mlt->total_bytes_received;
707 if (GNUNET_YES == l->verbose)
709 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
710 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", c_m,
712 mlt->total_bytes_sent,
713 mlt->total_bytes_received,
714 mlt->total_throughput_send,
715 mlt->total_throughput_recv);
718 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
719 sizeof (struct PartnerLoggingTimestep));
721 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
723 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
724 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
726 p = &bp->peer->partners[c_s];
727 slt = &mlt->slaves_log[c_s];
729 slt->slave = p->dest;
730 /* Bytes sent from master to this slave */
731 slt->total_bytes_sent = p->bytes_sent;
732 /* Messages sent from master to this slave */
733 slt->total_messages_sent = p->messages_sent;
734 /* Bytes master received from this slave */
735 slt->total_bytes_received = p->bytes_received;
736 /* Messages master received from this slave */
737 slt->total_messages_received = p->messages_received;
738 slt->total_app_rtt = p->total_app_rtt;
739 /* ats performance information */
740 slt->ats_cost_lan = p->ats_cost_lan;
741 slt->ats_cost_wan = p->ats_cost_wan;
742 slt->ats_cost_wlan = p->ats_cost_wlan;
743 slt->ats_delay = p->ats_delay;
744 slt->ats_distance = p->ats_distance;
745 slt->ats_network_type = p->ats_network_type;
746 slt->ats_utilization_down = p->ats_utilization_down;
747 slt->ats_utilization_up = p->ats_utilization_up;
748 slt->bandwidth_in = p->bandwidth_in;
749 slt->bandwidth_out = p->bandwidth_out;
750 slt->pref_bandwidth = p->pref_bandwidth;
751 slt->pref_delay = p->pref_delay;
753 /* Total application level rtt */
754 if (NULL == prev_log_mlt)
756 if (0 != slt->total_messages_sent)
757 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
763 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
764 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
765 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
766 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
769 app_rtt = prev_log_slt->app_rtt; /* No messages were */
772 slt->app_rtt = app_rtt;
774 /* Partner throughput */
775 if (NULL != prev_log_mlt)
777 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
778 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
779 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
781 slt->throughput_sent = 0;
783 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
784 slt->throughput_recv = mult *
785 (slt->total_bytes_received - prev_log_slt->total_bytes_received);
787 slt->throughput_recv = 0;
791 slt->throughput_sent = mult * slt->total_bytes_sent;
792 slt->throughput_recv = mult * slt->total_bytes_received;
795 if (GNUNET_YES == l->verbose)
797 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
798 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
801 mlt->total_bytes_sent,
802 mlt->total_bytes_received,
803 slt->throughput_sent,
804 slt->throughput_recv);
807 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
808 "Master [%u]: slave [%u]\n",
809 bp->peer->no, p->dest->no);
815 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
817 struct LoggingHandle *l = cls;
820 GNUNET_ATS_TEST_logging_now (l);
822 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
825 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
826 &collect_log_task, l);
832 * @param l the logging handle
835 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
837 if (GNUNET_YES!= l->running)
840 if (NULL != l->log_task)
841 GNUNET_SCHEDULER_cancel (l->log_task);
843 l->running = GNUNET_NO;
845 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
846 _("Stop logging\n"));
850 * Clean up logging data
852 * @param l the logging handle
855 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
858 struct PeerLoggingTimestep *cur;
860 if (GNUNET_YES == l->running)
861 GNUNET_ATS_TEST_logging_stop (l);
863 for (c_m = 0; c_m < l->num_masters; c_m++)
865 while (NULL != (cur = l->lp[c_m].head))
867 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
868 GNUNET_free (cur->slaves_log);
881 * @param log_frequency the logging frequency
882 * @param testname the testname
883 * @param masters the master peers used for benchmarking
884 * @param num_masters the number of master peers
885 * @param num_slaves the number of slave peers
886 * @param verbose verbose logging
887 * @return the logging handle or NULL on error
889 struct LoggingHandle *
890 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
891 char *testname, struct BenchmarkPeer *masters, int num_masters, int num_slaves,
894 struct LoggingHandle *l;
896 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
897 _("Start logging `%s'\n"), testname);
899 l = GNUNET_new (struct LoggingHandle);
900 l->num_masters = num_masters;
901 l->num_slaves = num_slaves;
903 l->frequency = log_frequency;
904 l->verbose = verbose;
905 l->lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
907 for (c_m = 0; c_m < num_masters; c_m ++)
909 l->lp[c_m].peer = &masters[c_m];
910 l->lp[c_m].start = GNUNET_TIME_absolute_get();
913 /* Schedule logging task */
914 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
915 l->running = GNUNET_YES;
919 /* end of file ats-testing-log.c */