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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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 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_ATS_Network_Type 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, int slaves)
253 struct GNUNET_DISK_FileHandle *f;
258 GNUNET_asprintf (&gfn, "gnuplot_throughput_%s",fn);
259 fprintf (stderr, "Writing throughput plot for master %u and %u slaves to `%s'\n",
260 lp->peer->no, slaves, gfn);
262 f = GNUNET_DISK_file_open (gfn,
263 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
264 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
265 GNUNET_DISK_PERM_USER_WRITE);
268 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
274 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE,
275 strlen(THROUGHPUT_TEMPLATE)))
276 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
277 "Cannot write data to plot file `%s'\n", gfn);
279 /* Write master data */
280 GNUNET_asprintf (&data,
281 "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \
282 "'%s' using 2:%u with lines title 'Master %u receive total', \\\n",
283 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no,
284 fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no);
285 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
286 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
289 for (c_s = 0; c_s < slaves; c_s++)
291 GNUNET_asprintf (&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \
292 "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n",
294 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT,
296 lp->peer->partners[c_s].dest->no,
298 LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV,
300 lp->peer->partners[c_s].dest->no,
301 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
302 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
303 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
307 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
308 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
309 "Cannot close gnuplot file `%s'\n", gfn);
311 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
312 "Data successfully written to plot file `%s'\n", gfn);
318 write_rtt_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves)
320 struct GNUNET_DISK_FileHandle *f;
325 GNUNET_asprintf (&gfn, "gnuplot_rtt_%s",fn);
326 fprintf (stderr, "Writing rtt plot for master %u to `%s'\n",
329 f = GNUNET_DISK_file_open (gfn,
330 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
331 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
332 GNUNET_DISK_PERM_USER_WRITE);
335 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
341 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE)))
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
344 for (c_s = 0; c_s < slaves; c_s++)
346 GNUNET_asprintf (&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n",
347 (0 == c_s) ? "plot " :"",
349 LOG_ITEMS_TIME + LOG_ITEM_APP_RTT,
351 lp->peer->partners[c_s].dest->no,
352 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
353 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
354 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
358 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
359 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
361 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
366 write_bw_gnuplot_script (char * fn, struct LoggingPeer *lp, char **fs, int slaves)
368 struct GNUNET_DISK_FileHandle *f;
373 GNUNET_asprintf (&gfn, "gnuplot_bw_%s",fn);
374 fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n",
377 f = GNUNET_DISK_file_open (gfn,
378 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
379 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ |
380 GNUNET_DISK_PERM_USER_WRITE);
383 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
389 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE)))
390 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
391 "Cannot write data to plot file `%s'\n", gfn);
393 for (c_s = 0; c_s < slaves; c_s++)
395 GNUNET_asprintf (&data, "%s"\
396 "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \
397 "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '"\
399 (0 == c_s) ? "plot " :"",
401 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT,
404 LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN,
406 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
407 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
408 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
412 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
413 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
415 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn);
421 GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l,
422 const char *experiment_name,
425 struct GNUNET_DISK_FileHandle *f[l->num_slaves];
426 struct GNUNET_DISK_FileHandle *f_m;
427 const char *tmp_exp_name;
428 char *filename_master;
429 char *filename_slaves[l->num_slaves];
431 struct PeerLoggingTimestep *cur_lt;
432 struct PartnerLoggingTimestep *plt;
433 struct GNUNET_TIME_Absolute timestamp;
438 timestamp = GNUNET_TIME_absolute_get();
440 tmp_exp_name = experiment_name;
441 for (c_m = 0; c_m < l->num_masters; c_m++)
443 GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s",
444 experiment_name, timestamp.abs_value_us, c_m, l->name);
445 fprintf (stderr, "Writing data for master %u to file `%s'\n",
446 c_m,filename_master);
448 f_m = GNUNET_DISK_file_open (filename_master,
449 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
450 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_master);
454 GNUNET_free (filename_master);
458 GNUNET_asprintf (&data, "# master %u; experiment : %s\n"
459 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n" ,
460 c_m, experiment_name);
461 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
462 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
463 "Cannot write data to log file `%s'\n",filename_master);
466 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
468 GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s",
469 tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name);
471 fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n",
472 c_m, c_s, filename_slaves[c_s]);
474 f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s],
475 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
476 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
479 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_slaves[c_s]);
480 GNUNET_free (filename_slaves[c_s]);
481 GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close(f_m));
482 GNUNET_free (filename_master);
487 GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n"
488 "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \
489 "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \
490 "pref bandwidth; pref delay\n",
491 c_m, c_s, experiment_name);
492 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
493 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
494 "Cannot write data to log file `%s'\n",filename_slaves[c_s]);
498 for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
502 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n",
504 (long long unsigned int) cur_lt->timestamp.abs_value_us,
505 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
506 cur_lt->timestamp).rel_value_us / 1000,
507 cur_lt->total_messages_sent,
508 cur_lt->total_bytes_sent,
509 cur_lt->total_throughput_send,
510 cur_lt->total_messages_received,
511 cur_lt->total_bytes_received,
512 cur_lt->total_throughput_recv);
514 /* Assembling master string */
515 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n",
516 (long long unsigned int) cur_lt->timestamp.abs_value_us,
517 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
518 cur_lt->timestamp).rel_value_us / 1000,
519 cur_lt->total_messages_sent,
520 cur_lt->total_bytes_sent,
521 cur_lt->total_throughput_send,
522 cur_lt->total_messages_received,
523 cur_lt->total_bytes_received,
524 cur_lt->total_throughput_recv);
526 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data)))
527 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
528 "Cannot write data to master file %u\n", c_m);
532 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
534 plt = &cur_lt->slaves_log[c_s];
537 /* Assembling slave string */
538 GNUNET_asprintf(&data,
539 "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n",
540 (long long unsigned int) cur_lt->timestamp.abs_value_us,
541 (long long unsigned int) GNUNET_TIME_absolute_get_difference(l->lp[c_m].start,
542 cur_lt->timestamp).rel_value_us / 1000,
543 plt->total_messages_sent,
544 plt->total_bytes_sent,
545 plt->throughput_sent,
546 plt->total_messages_received,
547 plt->total_bytes_received,
548 plt->throughput_recv,
549 (double) plt->app_rtt / 1000,
554 plt->ats_network_type,
555 plt->ats_utilization_out,
556 plt->ats_utilization_in,
562 "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n",
564 plt->total_messages_sent,
565 plt->total_bytes_sent,
566 plt->throughput_sent,
567 plt->total_messages_received,
568 plt->total_bytes_received,
569 plt->throughput_recv,
571 (long long unsigned int) plt->ats_delay.rel_value_us,
575 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data)))
576 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
577 "Cannot write data to log file `%s'\n", filename_slaves[c_s]);
583 for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++)
585 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f[c_s]))
587 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
588 "Cannot close log file for master[%u] slave[%u]\n", c_m, c_s);
591 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
592 "Data file successfully written to log file for `%s'\n",
593 filename_slaves[c_s]);
596 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f_m))
598 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
601 GNUNET_free (filename_master);
604 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
605 "Data file successfully written to log file for master `%s'\n", filename_master);
607 if (GNUNET_YES == plots)
609 write_throughput_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
610 write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
611 write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, l->num_slaves);
614 GNUNET_free (filename_master);
620 * @param l logging handle to use
623 GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l)
625 struct LoggingPeer *bp;
626 struct PeerLoggingTimestep *mlt;
627 struct PeerLoggingTimestep *prev_log_mlt;
628 struct PartnerLoggingTimestep *slt;
629 struct PartnerLoggingTimestep *prev_log_slt;
630 struct BenchmarkPartner *p;
631 struct GNUNET_TIME_Relative delta;
634 unsigned int app_rtt;
637 if (GNUNET_YES != l->running)
640 for (c_m = 0; c_m < l->num_masters; c_m++)
643 mlt = GNUNET_new (struct PeerLoggingTimestep);
644 GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt);
645 prev_log_mlt = mlt->prev;
648 /* Current master state */
649 mlt->timestamp = GNUNET_TIME_absolute_get();
650 mlt->total_bytes_sent = bp->peer->total_bytes_sent;
651 mlt->total_messages_sent = bp->peer->total_messages_sent;
652 mlt->total_bytes_received = bp->peer->total_bytes_received;
653 mlt->total_messages_received = bp->peer->total_messages_received;
656 if (NULL == prev_log_mlt)
658 /* Get difference to start */
659 delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start, mlt->timestamp);
663 /* Get difference to last timestep */
664 delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, mlt->timestamp);
667 /* Multiplication factor for throughput calculation */
668 mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us / (delta.rel_value_us);
670 /* Total throughput */
671 if (NULL != prev_log_mlt)
673 if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0)
675 mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent);
679 mlt->total_throughput_send = 0;
680 // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */
683 if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0)
685 mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received);
689 mlt->total_throughput_recv = 0;
690 //mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */
695 mlt->total_throughput_send = mult * mlt->total_bytes_sent;
696 mlt->total_throughput_recv = mult * mlt->total_bytes_received;
699 if (GNUNET_YES == l->verbose)
701 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
702 "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
704 (unsigned long long) delta.rel_value_us,
705 mlt->total_bytes_sent,
706 mlt->total_bytes_received,
707 mlt->total_throughput_send,
708 mlt->total_throughput_recv);
711 mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners *
712 sizeof (struct PartnerLoggingTimestep));
714 for (c_s = 0; c_s < bp->peer->num_partners; c_s++)
716 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
717 "Collect logging data master[%u] slave [%u]\n", c_m, c_s);
719 p = &bp->peer->partners[c_s];
720 slt = &mlt->slaves_log[c_s];
722 slt->slave = p->dest;
723 /* Bytes sent from master to this slave */
724 slt->total_bytes_sent = p->bytes_sent;
725 /* Messages sent from master to this slave */
726 slt->total_messages_sent = p->messages_sent;
727 /* Bytes master received from this slave */
728 slt->total_bytes_received = p->bytes_received;
729 /* Messages master received from this slave */
730 slt->total_messages_received = p->messages_received;
731 slt->total_app_rtt = p->total_app_rtt;
732 /* ats performance information */
733 slt->ats_delay = p->props.delay;
734 slt->ats_distance = p->props.distance;
735 slt->ats_network_type = p->props.scope;
736 slt->ats_utilization_in = p->props.utilization_out;
737 slt->ats_utilization_out = p->props.utilization_out;
738 slt->bandwidth_in = p->bandwidth_in;
739 slt->bandwidth_out = p->bandwidth_out;
740 slt->pref_bandwidth = p->pref_bandwidth;
741 slt->pref_delay = p->pref_delay;
743 /* Total application level rtt */
744 if (NULL == prev_log_mlt)
746 if (0 != slt->total_messages_sent)
747 app_rtt = slt->total_app_rtt / slt->total_messages_sent;
753 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
754 if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0)
755 app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) /
756 (slt->total_messages_sent - prev_log_slt->total_messages_sent);
759 app_rtt = prev_log_slt->app_rtt; /* No messages were */
762 slt->app_rtt = app_rtt;
764 /* Partner throughput */
765 if (NULL != prev_log_mlt)
767 prev_log_slt = &prev_log_mlt->slaves_log[c_s];
768 if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent)
769 slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent);
771 slt->throughput_sent = 0;
773 if (slt->total_bytes_received > prev_log_slt->total_bytes_received)
774 slt->throughput_recv = mult *
775 (slt->total_bytes_received - prev_log_slt->total_bytes_received);
777 slt->throughput_recv = 0;
781 slt->throughput_sent = mult * slt->total_bytes_sent;
782 slt->throughput_recv = mult * slt->total_bytes_received;
785 if (GNUNET_YES == l->verbose)
787 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
788 "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n",
790 (unsigned long long) delta.rel_value_us,
791 mlt->total_bytes_sent,
792 mlt->total_bytes_received,
793 slt->throughput_sent,
794 slt->throughput_recv);
797 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
798 "Master [%u]: slave [%u]\n",
799 bp->peer->no, p->dest->no);
806 collect_log_task (void *cls)
808 struct LoggingHandle *l = cls;
811 GNUNET_ATS_TEST_logging_now (l);
812 l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency,
821 * @param l the logging handle
824 GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l)
826 if (GNUNET_YES!= l->running)
829 if (NULL != l->log_task)
831 GNUNET_SCHEDULER_cancel (l->log_task);
834 l->running = GNUNET_NO;
836 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
837 _("Stop logging\n"));
841 * Clean up logging data
843 * @param l the logging handle
846 GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l)
849 struct PeerLoggingTimestep *cur;
851 if (GNUNET_YES == l->running)
852 GNUNET_ATS_TEST_logging_stop (l);
854 for (c_m = 0; c_m < l->num_masters; c_m++)
856 while (NULL != (cur = l->lp[c_m].head))
858 GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur);
859 GNUNET_free (cur->slaves_log);
872 * @param log_frequency the logging frequency
873 * @param testname the testname
874 * @param masters the master peers used for benchmarking
875 * @param num_masters the number of master peers
876 * @param num_slaves the number of slave peers
877 * @param verbose verbose logging
878 * @return the logging handle or NULL on error
880 struct LoggingHandle *
881 GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency,
882 const char *testname,
883 struct BenchmarkPeer *masters,
888 struct LoggingHandle *l;
891 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
892 _("Start logging `%s'\n"), testname);
894 l = GNUNET_new (struct LoggingHandle);
895 l->num_masters = num_masters;
896 l->num_slaves = num_slaves;
898 l->frequency = log_frequency;
899 l->verbose = verbose;
900 l->lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
902 for (c_m = 0; c_m < num_masters; c_m ++)
904 l->lp[c_m].peer = &masters[c_m];
905 l->lp[c_m].start = GNUNET_TIME_absolute_get();
908 /* Schedule logging task */
909 l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l);
910 l->running = GNUNET_YES;
914 /* end of file ats-testing-log.c */