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 LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 100)
32 static GNUNET_SCHEDULER_TaskIdentifier log_task;
34 static struct BenchmarkPeer *peers;
38 struct LoggingTimestep
40 struct LoggingTimestep *next;
41 struct LoggingTimestep *prev;
43 struct GNUNET_TIME_Absolute timestamp;
46 * Total number of messages this peer has sent
48 unsigned int total_messages_sent;
51 * Total number of bytes this peer has sent
53 unsigned int total_bytes_sent;
56 * Total number of messages this peer has received
58 unsigned int total_messages_received;
61 * Total number of bytes this peer has received
63 unsigned int total_bytes_received;
68 struct BenchmarkPeer *peer;
70 struct GNUNET_TIME_Absolute start;
72 struct LoggingTimestep *head;
73 struct LoggingTimestep *tail;
77 * Log structure of length num_peers
79 static struct LoggingPeer *lp;
85 struct GNUNET_DISK_FileHandle *f;
88 struct LoggingTimestep *cur;
90 unsigned int throughput_recv;
91 unsigned int throughput_send;
94 GNUNET_asprintf (&filename, "%llu_%s.data", GNUNET_TIME_absolute_get().abs_value_us,name);
96 f = GNUNET_DISK_file_open (filename,
97 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
98 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
102 GNUNET_free (filename);
106 for (c_m = 0; c_m < num_peers; c_m++)
108 for (cur = lp[c_m].head; NULL != cur; cur = cur->next)
110 mult = (1.0 * 1000 * 1000) / (LOGGING_FREQUENCY.rel_value_us);
111 if (NULL != cur->prev)
113 throughput_send = cur->total_bytes_sent - cur->prev->total_bytes_sent;
114 throughput_recv = cur->total_bytes_received - cur->prev->total_bytes_received;
118 throughput_send = cur->total_bytes_sent;
119 throughput_recv = cur->total_bytes_received;
121 throughput_send *= mult;
122 throughput_recv *= mult;
125 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
126 "Master [%u]: timestamp %llu %llu %u %u %u ; %u %u %u\n", lp[c_m].peer->no,
127 cur->timestamp, GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur->timestamp).rel_value_us / 1000,
128 cur->total_messages_sent, cur->total_bytes_sent, throughput_send,
129 cur->total_messages_received, cur->total_bytes_received, throughput_recv);
131 GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u\n",
133 GNUNET_TIME_absolute_get_difference(lp[c_m].start,cur->timestamp).rel_value_us / 1000,
134 cur->total_messages_sent, cur->total_bytes_sent, throughput_send,
135 cur->total_messages_received, cur->total_bytes_received, throughput_recv);
137 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
138 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
143 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
145 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
146 GNUNET_free (filename);
150 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
151 GNUNET_free (filename);
155 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
159 struct LoggingTimestep *lt;
160 struct BenchmarkPartner *p;
162 log_task = GNUNET_SCHEDULER_NO_TASK;
164 for (c_m = 0; c_m < num_peers; c_m++)
166 lt = GNUNET_malloc (sizeof (struct LoggingTimestep));
167 GNUNET_CONTAINER_DLL_insert_tail(lp[c_m].head, lp[c_m].tail, lt);
170 lt->timestamp = GNUNET_TIME_absolute_get();
171 lt->total_bytes_sent = lp[c_m].peer->total_bytes_sent;
172 lt->total_messages_sent = lp[c_m].peer->total_messages_sent;
173 lt->total_bytes_received = lp[c_m].peer->total_bytes_received;
174 lt->total_messages_received = lp[c_m].peer->total_messages_received;
176 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
178 p = &peers[c_m].partners[c_s];
180 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
181 "Master [%u]: slave [%u]\n",
182 lp->peer->no, p->dest->no);
187 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
190 log_task = GNUNET_SCHEDULER_add_delayed (LOGGING_FREQUENCY,
191 &collect_log_task, NULL);
199 struct GNUNET_SCHEDULER_TaskContext tc;
200 struct LoggingTimestep *cur;
202 if (GNUNET_SCHEDULER_NO_TASK != log_task)
203 GNUNET_SCHEDULER_cancel (log_task);
204 log_task = GNUNET_SCHEDULER_NO_TASK;
205 tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
206 collect_log_task (NULL, &tc);
208 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
209 _("Stop logging\n"));
213 for (c_m = 0; c_m < num_peers; c_m++)
215 while (NULL != (cur = lp[c_m].head))
217 GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
226 perf_logging_start (char * testname, struct BenchmarkPeer *masters, int num_masters)
229 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
230 _("Start logging `%s'\n"), testname);
233 num_peers = num_masters;
236 lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
238 for (c_m = 0; c_m < num_masters; c_m ++)
240 lp[c_m].peer = &masters[c_m];
241 lp[c_m].start = GNUNET_TIME_absolute_get();
244 /* Schedule logging task */
245 log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
247 /* end of file perf_ats_logging.c */