collecting log functionality
[oweals/gnunet.git] / src / ats-tests / perf_ats_logging.c
1 /*
2  This file is part of GNUnet.
3  (C) 2010-2013 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19  */
20 /**
21  * @file ats/perf_ats_logging.c
22  * @brief ats benchmark: logging for performance tests
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25  */
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "perf_ats.h"
29
30 #define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 500)
31
32 static GNUNET_SCHEDULER_TaskIdentifier log_task;
33
34 static struct BenchmarkPeer *peers;
35 static int num_peers;
36
37 static void
38 write_to_file ()
39 {
40
41 }
42
43 static void
44 collect_log_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
45 {
46   int c_m;
47   int c_s;
48   log_task = GNUNET_SCHEDULER_NO_TASK;
49
50   struct BenchmarkPeer *m;
51   struct BenchmarkPartner *p;
52
53   for (c_m = 0; c_m < num_peers; c_m++)
54   {
55     m = &peers[c_m];
56     for (c_s = 0; c_s < m->num_partners; c_s++)
57     {
58       p = &peers[c_m].partners[c_s];
59       GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
60           "Master [%u]: slave [%u]\n",
61           m->no, p->dest->no);
62     }
63   }
64
65   if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
66     return;
67
68   log_task = GNUNET_SCHEDULER_add_delayed (LOGGING_FREQUENCY,
69       &collect_log_task, NULL);
70 }
71
72
73 void
74 perf_logging_stop ()
75 {
76   struct GNUNET_SCHEDULER_TaskContext tc;
77
78   if (GNUNET_SCHEDULER_NO_TASK != log_task)
79     GNUNET_SCHEDULER_cancel (log_task);
80   log_task = GNUNET_SCHEDULER_NO_TASK;
81   tc.reason = GNUNET_SCHEDULER_REASON_SHUTDOWN;
82   collect_log_task (NULL, &tc);
83
84   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
85       _("Stop logging\n"));
86
87   write_to_file ();
88 }
89
90 void
91 perf_logging_start (struct BenchmarkPeer *masters, int num_masters)
92 {
93   GNUNET_log(GNUNET_ERROR_TYPE_INFO,
94       _("Start logging\n"));
95
96   peers = masters;
97   num_peers = num_masters;
98
99   /* Schedule logging task */
100   log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, NULL);
101 }
102 /* end of file perf_ats_logging.c */
103