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, 500)
32 static GNUNET_SCHEDULER_TaskIdentifier log_task;
34 static struct BenchmarkPeer *peers;
38 struct LoggingTimestep
40 struct GNUNET_TIME_Absolute timestamp;
42 struct LoggingTimestep *next;
43 struct LoggingTimestep *prev;
48 struct BenchmarkPeer *peer;
50 struct GNUNET_TIME_Absolute start;
52 struct LoggingTimestep *head;
53 struct LoggingTimestep *tail;
57 * Log structure of length num_peers
59 static struct LoggingPeer *lp;
65 struct GNUNET_DISK_FileHandle *f;
68 struct LoggingTimestep *cur;
71 GNUNET_asprintf (&filename, "%llu_%s.data", GNUNET_TIME_absolute_get().abs_value_us,name);
73 f = GNUNET_DISK_file_open (filename,
74 GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE,
75 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE);
78 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename);
79 GNUNET_free (filename);
83 for (c_m = 0; c_m < num_peers; c_m++)
85 for (cur = lp[c_m].head; NULL != cur; cur = cur->next)
87 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
88 "Master [%u]: timestamp %llu \n", lp[c_m].peer->no, cur->timestamp);
90 GNUNET_asprintf (&data, "%llu;\n", cur->timestamp);
92 if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data)))
93 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to log file `%s'\n", filename);
99 if (GNUNET_SYSERR == GNUNET_DISK_file_close(f))
101 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close log file `%s'\n", filename);
102 GNUNET_free (filename);
106 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Data file successfully written to log file `%s'\n", filename);
107 GNUNET_free (filename);
111 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
115 struct LoggingTimestep *lt;
116 struct BenchmarkPartner *p;
118 log_task = GNUNET_SCHEDULER_NO_TASK;
120 for (c_m = 0; c_m < num_peers; c_m++)
122 lt = GNUNET_malloc (sizeof (struct LoggingTimestep));
123 GNUNET_CONTAINER_DLL_insert_tail(lp[c_m].head, lp[c_m].tail, lt);
124 lt->timestamp = GNUNET_TIME_absolute_get();
126 for (c_s = 0; c_s < lp[c_m].peer->num_partners; c_s++)
128 p = &peers[c_m].partners[c_s];
130 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
131 "Master [%u]: slave [%u]\n",
132 lp->peer->no, p->dest->no);
136 if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
139 log_task = GNUNET_SCHEDULER_add_delayed (LOGGING_FREQUENCY,
140 &collect_log_task, NULL);
148 struct GNUNET_SCHEDULER_TaskContext tc;
149 struct LoggingTimestep *cur;
151 if (GNUNET_SCHEDULER_NO_TASK != log_task)
152 GNUNET_SCHEDULER_cancel (log_task);
153 log_task = GNUNET_SCHEDULER_NO_TASK;
154 tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
155 collect_log_task (NULL, &tc);
157 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
158 _("Stop logging\n"));
162 for (c_m = 0; c_m < num_peers; c_m++)
164 while (NULL != (cur = lp[c_m].head))
166 GNUNET_CONTAINER_DLL_remove (lp[c_m].head, lp[c_m].tail, cur);
175 perf_logging_start (char * testname, struct BenchmarkPeer *masters, int num_masters)
178 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
179 _("Start logging `%s'\n"), testname);
182 num_peers = num_masters;
185 lp = GNUNET_malloc (num_masters * sizeof (struct LoggingPeer));
187 for (c_m = 0; c_m < num_masters; c_m ++)
189 lp[c_m].peer = &masters[c_m];
190 lp[c_m].start = GNUNET_TIME_absolute_get();
193 /* Schedule logging task */
194 log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
196 /* end of file perf_ats_logging.c */