diff options
author | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-11 14:12:00 +0000 |
---|---|---|
committer | Sree Harsha Totakura <totakura@in.tum.de> | 2012-09-11 14:12:00 +0000 |
commit | 48ea50123bc913b72a02293079f3f6d60af9c47d (patch) | |
tree | 514e75e9abd727fbf363de4f6ec68366b4869add /src/stream | |
parent | ed318284b8b6b48753fa50f8f138c9d44ec4aacb (diff) | |
download | gnunet-48ea50123bc913b72a02293079f3f6d60af9c47d.tar.gz gnunet-48ea50123bc913b72a02293079f3f6d60af9c47d.zip |
stub for stream performance tests
Diffstat (limited to 'src/stream')
-rw-r--r-- | src/stream/Makefile.am | 19 | ||||
-rw-r--r-- | src/stream/perf_stream_api.c | 184 |
2 files changed, 201 insertions, 2 deletions
diff --git a/src/stream/Makefile.am b/src/stream/Makefile.am index 6c9e82dea..a8afd93cb 100644 --- a/src/stream/Makefile.am +++ b/src/stream/Makefile.am | |||
@@ -20,12 +20,18 @@ libgnunetstream_la_LIBADD = \ | |||
20 | libgnunetstream_la_LDFLAGS = \ | 20 | libgnunetstream_la_LDFLAGS = \ |
21 | $(GN_LIB_LDFLAGS) | 21 | $(GN_LIB_LDFLAGS) |
22 | 22 | ||
23 | if HAVE_BENCHMARKS | ||
24 | STREAM_BENCHMARKS = \ | ||
25 | perf_stream_api | ||
26 | endif | ||
27 | |||
23 | check_PROGRAMS = \ | 28 | check_PROGRAMS = \ |
24 | test_stream_2peers \ | 29 | test_stream_2peers \ |
25 | test_stream_2peers_halfclose \ | 30 | test_stream_2peers_halfclose \ |
26 | test_stream_local \ | 31 | test_stream_local \ |
27 | test_stream_big \ | 32 | test_stream_big \ |
28 | test_stream_sequence_wraparound | 33 | test_stream_sequence_wraparound \ |
34 | $(STREAM_BENCHMARKS) | ||
29 | 35 | ||
30 | EXTRA_DIST = test_stream_local.conf | 36 | EXTRA_DIST = test_stream_local.conf |
31 | 37 | ||
@@ -35,7 +41,8 @@ TESTS = \ | |||
35 | test_stream_2peers_halfclose \ | 41 | test_stream_2peers_halfclose \ |
36 | test_stream_local \ | 42 | test_stream_local \ |
37 | test_stream_big \ | 43 | test_stream_big \ |
38 | test_stream_sequence_wraparound | 44 | test_stream_sequence_wraparound \ |
45 | $(STREAM_BENCHMARKS) | ||
39 | endif | 46 | endif |
40 | 47 | ||
41 | test_stream_2peers_SOURCES = \ | 48 | test_stream_2peers_SOURCES = \ |
@@ -73,3 +80,11 @@ test_stream_sequence_wraparound_LDADD = \ | |||
73 | $(top_builddir)/src/stream/libgnunetstream.la \ | 80 | $(top_builddir)/src/stream/libgnunetstream.la \ |
74 | $(top_builddir)/src/util/libgnunetutil.la \ | 81 | $(top_builddir)/src/util/libgnunetutil.la \ |
75 | $(top_builddir)/src/testing/libgnunettesting.la | 82 | $(top_builddir)/src/testing/libgnunettesting.la |
83 | |||
84 | perf_stream_api_SOURCES = \ | ||
85 | perf_stream_api.c | ||
86 | perf_stream_api_LDADD = \ | ||
87 | $(top_builddir)/src/stream/libgnunetstream.la \ | ||
88 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
89 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
90 | $(top_builddir)/src/testbed/libgnunettestbed.la \ No newline at end of file | ||
diff --git a/src/stream/perf_stream_api.c b/src/stream/perf_stream_api.c new file mode 100644 index 000000000..a805d62ab --- /dev/null +++ b/src/stream/perf_stream_api.c | |||
@@ -0,0 +1,184 @@ | |||
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 | } | ||