2 This file is part of GNUnet.
3 (C) 2011, 2012 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.
22 * @file stream/perf_stream_api.c
23 * @brief performance benchmarks for stream api
24 * @author Sree Harsha Totakura
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 */
38 /* STREAM_API->MESH_API->MESH_SERVICE->CORE1..CORE2..CORE3->MESH_API->STREAM_API. */
39 /****************************************************************************************/
42 #include "gnunet_common.h"
43 #include "gnunet_util_lib.h"
44 #include "gnunet_testbed_service.h"
48 * Simple struct to keep track of progress, and print a
49 * nice little percentage meter for long running tasks.
59 unsigned int completed;
66 #define DATA_SIZE 65536 /* 64KB */
68 static uint32_t data[DATA_SIZE / 4]; /* 64KB array */
70 static uint16_t payload_size[] =
71 { 20, 500, 2000, 7000, 13000, 25000, 56000, 64000 };
75 * Create a meter to keep track of the progress of some task.
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
82 * @return the progress meter
84 static struct ProgressMeter *
85 create_meter (unsigned int total, char *start_string, int print)
87 struct ProgressMeter *ret;
89 ret = GNUNET_malloc (sizeof (struct ProgressMeter));
92 ret->modnum = total / 4;
93 if (ret->modnum == 0) /* Divide by zero check */
95 ret->dotnum = (total / 50) + 1;
96 if (start_string != NULL)
97 ret->startup_string = GNUNET_strdup (start_string);
99 ret->startup_string = GNUNET_strdup ("");
106 * Update progress meter (increment by one).
108 * @param meter the meter to update and print info for
110 * @return GNUNET_YES if called the total requested,
111 * GNUNET_NO if more items expected
114 update_meter (struct ProgressMeter *meter)
116 if (meter->print == GNUNET_YES)
118 if (meter->completed % meter->modnum == 0)
120 if (meter->completed == 0)
122 FPRINTF (stdout, "%sProgress: [0%%", meter->startup_string);
125 FPRINTF (stdout, "%d%%",
126 (int) (((float) meter->completed / meter->total) * 100));
128 else if (meter->completed % meter->dotnum == 0)
129 FPRINTF (stdout, "%s", ".");
131 if (meter->completed + 1 == meter->total)
132 FPRINTF (stdout, "%d%%]\n", 100);
137 if (meter->completed == meter->total)
139 if (meter->completed > meter->total)
140 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Progress meter overflow!!\n");
146 * Reset progress meter.
148 * @param meter the meter to reset
150 * @return GNUNET_YES if meter reset,
151 * GNUNET_SYSERR on error
154 reset_meter (struct ProgressMeter *meter)
157 return GNUNET_SYSERR;
159 meter->completed = 0;
165 * Release resources for meter
167 * @param meter the meter to free
170 free_meter (struct ProgressMeter *meter)
172 GNUNET_free_non_null (meter->startup_string);
180 int main (int argc, char **argv)
182 PRINTF ("Performance measurements for STREAM\n");