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/perf_ats_logging.c
22 * @brief ats benchmark: logging for performance tests
23 * @author Christian Grothoff
24 * @author Matthias Wachs
27 #include "gnunet_util_lib.h"
30 #define THROUGHPUT_TEMPLATE "#!/usr/bin/gnuplot \n" \
31 "set datafile separator ';' \n" \
32 "set title \"Throughput\" \n" \
33 "set xlabel \"Time in ms\" \n" \
34 "set ylabel \"Bytes/s\" \n"
39 static GNUNET_SCHEDULER_TaskIdentifier log_task;
42 * Reference to perf_ats' masters
47 static struct GNUNET_TIME_Relative frequency;
50 * A single logging time step for a partner
52 struct PartnerLoggingTimestep
57 struct BenchmarkPeer *slave;
60 * Total number of messages this peer has sent
62 unsigned int total_messages_sent;
65 * Total number of bytes this peer has sent
67 unsigned int total_bytes_sent;
70 * Total number of messages this peer has received
72 unsigned int total_messages_received;
75 * Total number of bytes this peer has received
77 unsigned int total_bytes_received;
82 * A single logging time step for a peer
84 struct PeerLoggingTimestep
89 struct PeerLoggingTimestep *next;
94 struct PeerLoggingTimestep *prev;
99 struct GNUNET_TIME_Absolute timestamp;
102 * Total number of messages this peer has sent
104 unsigned int total_messages_sent;
107 * Total number of bytes this peer has sent
109 unsigned int total_bytes_sent;
112 * Total number of messages this peer has received
114 unsigned int total_messages_received;
117 * Total number of bytes this peer has received
119 unsigned int total_bytes_received;
124 struct PartnerLoggingTimestep *slaves_log;
128 * Entry for a benchmark peer
135 struct BenchmarkPeer *peer;
140 struct GNUNET_TIME_Absolute start;
143 * DLL for logging entries: head
145 struct PeerLoggingTimestep *head;
148 * DLL for logging entries: tail
150 struct PeerLoggingTimestep *tail;
154 * Log structure of length num_peers
156 static struct LoggingPeer *lp;
160 write_gnuplot_script (char * fn, struct LoggingPeer *lp)
162 struct GNUNET_DISK_FileHandle *f;
168 GNUNET_asprintf (&gfn, "gnuplot_%s",fn);
169 f = GNUNET_DISK_file_open (gfn,
170 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
171 GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
174 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn);
181 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, strlen(THROUGHPUT_TEMPLATE)))
182 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
184 /* Write master data */
185 GNUNET_asprintf (&data, "plot '%s' using 2:%u with lines title 'Master %u send', \\\n" \
186 "'%s' using 2:%u with lines title 'Master %u receive', \\\n",
188 fn, 8, lp->peer->no);
189 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
190 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
194 for (c_s = 0; c_s < lp->peer->num_partners; c_s++)
196 GNUNET_asprintf (&data, "'%s' using 2:%u with lines title 'Slave %u send', \\\n" \
197 "'%s' using 2:%u with lines title 'Slave %u receive'%s\n",
198 fn, index, lp->peer->no,
199 fn, index+3, lp->peer->no,
200 (c_s < lp->peer->num_partners -1) ? ", \\" : "\n pause -1");
201 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
202 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn);
207 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
208 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn);
216 struct GNUNET_DISK_FileHandle *f;
220 char *slave_string_tmp;
221 struct PeerLoggingTimestep *cur_lt;
222 struct PartnerLoggingTimestep *plt;
225 unsigned int throughput_recv;
226 unsigned int throughput_send;
227 unsigned int throughput_recv_slave;
228 unsigned int throughput_send_slave;
231 for (c_m = 0; c_m < num_peers; c_m++)
233 GNUNET_asprintf (&filename, "%llu_master_%u_%s_%s.data", GNUNET_TIME_absolute_get().abs_value_us,
234 lp[c_m].peer->no, GNUNET_i2s(&lp[c_m].peer->id), name);
236 f = GNUNET_DISK_file_open (filename,
237 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
238 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
241 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
242 GNUNET_free (filename);
247 for (cur_lt = lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next)
249 mult = (1.0 * 1000 * 1000) / (LOGGING_FREQUENCY.rel_value_us);
250 if (NULL != cur_lt->prev)
252 throughput_send = cur_lt->total_bytes_sent - cur_lt->prev->total_bytes_sent;
253 throughput_recv = cur_lt->total_bytes_received - cur_lt->prev->total_bytes_received;
257 throughput_send = cur_lt->total_bytes_sent;
258 throughput_recv = cur_lt->total_bytes_received;
260 throughput_send *= mult;
261 throughput_recv *= mult;
264 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
265 "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
266 cur_lt->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
267 cur_lt->total_messages_sent, cur_lt->total_bytes_sent, throughput_send,
268 cur_lt->total_messages_received, cur_lt->total_bytes_received, throughput_recv);
270 slave_string = GNUNET_strdup (";");
271 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
274 plt = &cur_lt->slaves_log[c_s];
275 if (NULL != cur_lt->prev)
277 throughput_send_slave = plt->total_bytes_sent - cur_lt->prev->slaves_log[c_s].total_bytes_sent;
278 throughput_recv_slave = plt->total_bytes_received - cur_lt->prev->slaves_log[c_s].total_bytes_received;
282 throughput_send_slave = plt->total_bytes_sent;
283 throughput_recv_slave = plt->total_bytes_received;
285 throughput_send_slave *= mult;
286 throughput_recv_slave *= mult;
288 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
289 "\t Slave [%u]: %u %u %u ; %u %u %u \n", plt->slave->no,
290 plt->total_messages_sent, plt->total_bytes_sent, throughput_send_slave,
291 plt->total_messages_received, plt->total_bytes_received, throughput_recv_slave);
294 GNUNET_asprintf(&slave_string_tmp, "%s%u;%u;%u;%u;%u;%u;",slave_string,
295 plt->total_messages_sent, plt->total_bytes_sent, throughput_send_slave,
296 plt->total_messages_received, plt->total_bytes_received, throughput_recv_slave);
297 GNUNET_free (slave_string);
298 slave_string = slave_string_tmp;
301 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u%s\n",
303 GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur_lt->timestamp).rel_value_us / 1000,
304 cur_lt->total_messages_sent, cur_lt->total_bytes_sent, throughput_send,
305 cur_lt->total_messages_received, cur_lt->total_bytes_received, throughput_recv,
307 GNUNET_free (slave_string);
309 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
310 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
313 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
315 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
316 GNUNET_free (filename);
320 write_gnuplot_script (filename, lp);
322 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
323 GNUNET_free (filename);
328 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
332 struct PeerLoggingTimestep *mlt;
333 struct PartnerLoggingTimestep *slt;
334 struct BenchmarkPartner *p;
336 log_task = GNUNET_SCHEDULER_NO_TASK;
338 for (c_m = 0; c_m < num_peers; c_m++)
340 mlt = GNUNET_malloc (sizeof (struct PeerLoggingTimestep));
341 GNUNET_CONTAINER_DLL_insert_tail(lp[c_m].head, lp[c_m].tail, mlt);
344 mlt->timestamp = GNUNET_TIME_absolute_get();
345 mlt->total_bytes_sent = lp[c_m].peer->total_bytes_sent;
346 mlt->total_messages_sent = lp[c_m].peer->total_messages_sent;
347 mlt->total_bytes_received = lp[c_m].peer->total_bytes_received;
348 mlt->total_messages_received = lp[c_m].peer->total_messages_received;
350 mlt->slaves_log = GNUNET_malloc (lp[c_m].peer->num_partners *
351 sizeof (struct PartnerLoggingTimestep));
353 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
355 p = &lp[c_m].peer->partners[c_s];
356 slt = &mlt->slaves_log[c_s];
357 slt->slave = p->dest;
358 slt->total_bytes_sent = p->dest->total_bytes_sent;
359 slt->total_messages_sent = p->dest->total_messages_sent;
360 slt->total_bytes_received = p->dest->total_bytes_received;
361 slt->total_messages_received = p->dest->total_messages_received;
363 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
364 "Master [%u]: slave [%u]\n",
365 lp[c_m].peer->no, p->dest->no);
369 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
372 log_task = GNUNET_SCHEDULER_add_delayed (frequency,
373 &collect_log_task, NULL);
381 struct GNUNET_SCHEDULER_TaskContext tc;
382 struct PeerLoggingTimestep *cur;
384 if (GNUNET_YES!= running)
387 if (GNUNET_SCHEDULER_NO_TASK != log_task)
388 GNUNET_SCHEDULER_cancel (log_task);
389 log_task = GNUNET_SCHEDULER_NO_TASK;
390 tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
391 collect_log_task (NULL, &tc);
393 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
394 _("Stop logging\n"));
398 for (c_m = 0; c_m < num_peers; c_m++)
400 while (NULL != (cur = lp[c_m].head))
402 GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
403 GNUNET_free (cur->slaves_log);
412 perf_logging_start (struct GNUNET_TIME_Relative log_frequency,
413 char * testname, struct BenchmarkPeer *masters, int num_masters)
416 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
417 _("Start logging `%s'\n"), testname);
419 num_peers = num_masters;
421 frequency = log_frequency;
423 lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
425 for (c_m = 0; c_m < num_masters; c_m ++)
427 lp[c_m].peer = &masters[c_m];
428 lp[c_m].start = GNUNET_TIME_absolute_get();
431 /* Schedule logging task */
432 log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
433 running = GNUNET_YES;
435 /* end of file perf_ats_logging.c */