stub for stream performance tests
[oweals/gnunet.git] / src / stream / perf_stream_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011, 2012 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 /**
22  * @file stream/perf_stream_api.c
23  * @brief performance benchmarks for stream api
24  * @author Sree Harsha Totakura
25  */
26
27 /****************************************************************************************/
28 /* Test is setup into the following major steps:                                        */
29 /*    1. Measurements over loopback (1 hop). i.e. we use only one peer and open         */
30 /*       stream connections over loopback. Messages will go through                     */
31 /*       STREAM_API->MESH_API->MESH_SERVICE->MESH_API->STREAM_API.                      */
32 /*    2. Measurements over 2 peers (2 hops). We use testbed to create 2 peers,          */
33 /*       connect them and then create stream connections. Messages will go through      */
34 /*       STREAM_API->MESH_API->MESH_SERVICE->CORE1.....CORE2->MESH_API->STREAM_API      */
35 /*    3. Measurements over 3 peers (3 hops). We use testbed to create 3 peers,          */
36 /*       connect them in a line topology: peer1->peer2->peer3. Messages will go         */
37 /*       through                                                                        */
38 /*       STREAM_API->MESH_API->MESH_SERVICE->CORE1..CORE2..CORE3->MESH_API->STREAM_API. */
39 /****************************************************************************************/
40
41 #include "platform.h"
42 #include "gnunet_common.h"
43 #include "gnunet_util_lib.h"
44 #include "gnunet_testbed_service.h"
45
46   
47 /**
48  * Simple struct to keep track of progress, and print a
49  * nice little percentage meter for long running tasks.
50  */
51 struct ProgressMeter
52 {
53   unsigned int total;
54
55   unsigned int modnum;
56
57   unsigned int dotnum;
58
59   unsigned int completed;
60
61   int print;
62
63   char *startup_string;
64 };
65
66 #define DATA_SIZE 65536      /* 64KB */
67
68 static uint32_t data[DATA_SIZE / 4];     /* 64KB array */
69
70 static uint16_t payload_size[] = 
71 { 20, 500, 2000, 7000, 13000, 25000, 56000, 64000 };
72
73
74 /**
75  * Create a meter to keep track of the progress of some task.
76  *
77  * @param total the total number of items to complete
78  * @param start_string a string to prefix the meter with (if printing)
79  * @param print GNUNET_YES to print the meter, GNUNET_NO to count
80  *              internally only
81  *
82  * @return the progress meter
83  */
84 static struct ProgressMeter *
85 create_meter (unsigned int total, char *start_string, int print)
86 {
87   struct ProgressMeter *ret;
88
89   ret = GNUNET_malloc (sizeof (struct ProgressMeter));
90   ret->print = print;
91   ret->total = total;
92   ret->modnum = total / 4;
93   if (ret->modnum == 0)         /* Divide by zero check */
94     ret->modnum = 1;
95   ret->dotnum = (total / 50) + 1;
96   if (start_string != NULL)
97     ret->startup_string = GNUNET_strdup (start_string);
98   else
99     ret->startup_string = GNUNET_strdup ("");
100
101   return ret;
102 }
103
104
105 /**
106  * Update progress meter (increment by one).
107  *
108  * @param meter the meter to update and print info for
109  *
110  * @return GNUNET_YES if called the total requested,
111  *         GNUNET_NO if more items expected
112  */
113 static int
114 update_meter (struct ProgressMeter *meter)
115 {
116   if (meter->print == GNUNET_YES)
117   {
118     if (meter->completed % meter->modnum == 0)
119     {
120       if (meter->completed == 0)
121       {
122         FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
123       }
124       else
125         FPRINTF (stdout, "%d%%",
126                  (int) (((float) meter->completed / meter->total) * 100));
127     }
128     else if (meter->completed % meter->dotnum == 0)
129       FPRINTF (stdout, "%s",  ".");
130
131     if (meter->completed + 1 == meter->total)
132       FPRINTF (stdout, "%d%%]\n", 100);
133     fflush (stdout);
134   }
135   meter->completed++;
136
137   if (meter->completed == meter->total)
138     return GNUNET_YES;
139   if (meter->completed > meter->total)
140     GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
141   return GNUNET_NO;
142 }
143
144
145 /**
146  * Reset progress meter.
147  *
148  * @param meter the meter to reset
149  *
150  * @return GNUNET_YES if meter reset,
151  *         GNUNET_SYSERR on error
152  */
153 static int
154 reset_meter (struct ProgressMeter *meter)
155 {
156   if (meter == NULL)
157     return GNUNET_SYSERR;
158
159   meter->completed = 0;
160   return GNUNET_YES;
161 }
162
163
164 /**
165  * Release resources for meter
166  *
167  * @param meter the meter to free
168  */
169 static void
170 free_meter (struct ProgressMeter *meter)
171 {
172   GNUNET_free_non_null (meter->startup_string);
173   GNUNET_free (meter);
174 }
175
176
177 /**
178  * Main function
179  */
180 int main (int argc, char **argv)
181 {
182   PRINTF ("Performance measurements for STREAM\n");
183   return 0;
184 }