diff options
Diffstat (limited to 'src/testbed/gnunet-testbed-profiler.c')
-rw-r--r-- | src/testbed/gnunet-testbed-profiler.c | 222 |
1 files changed, 112 insertions, 110 deletions
diff --git a/src/testbed/gnunet-testbed-profiler.c b/src/testbed/gnunet-testbed-profiler.c index d9401286c..e65ae6202 100644 --- a/src/testbed/gnunet-testbed-profiler.c +++ b/src/testbed/gnunet-testbed-profiler.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file testbed/gnunet-testbed-profiler.c | 22 | * @file testbed/gnunet-testbed-profiler.c |
@@ -32,8 +32,8 @@ | |||
32 | /** | 32 | /** |
33 | * Generic loggins shorthand | 33 | * Generic loggins shorthand |
34 | */ | 34 | */ |
35 | #define LOG(kind,...) \ | 35 | #define LOG(kind, ...) \ |
36 | GNUNET_log (kind, __VA_ARGS__) | 36 | GNUNET_log(kind, __VA_ARGS__) |
37 | 37 | ||
38 | 38 | ||
39 | /** | 39 | /** |
@@ -104,18 +104,18 @@ static int noninteractive; | |||
104 | * @param cls NULL | 104 | * @param cls NULL |
105 | */ | 105 | */ |
106 | static void | 106 | static void |
107 | do_shutdown (void *cls) | 107 | do_shutdown(void *cls) |
108 | { | 108 | { |
109 | if (NULL != abort_task) | 109 | if (NULL != abort_task) |
110 | { | 110 | { |
111 | GNUNET_SCHEDULER_cancel (abort_task); | 111 | GNUNET_SCHEDULER_cancel(abort_task); |
112 | abort_task = NULL; | 112 | abort_task = NULL; |
113 | } | 113 | } |
114 | if (NULL != cfg) | 114 | if (NULL != cfg) |
115 | { | 115 | { |
116 | GNUNET_CONFIGURATION_destroy (cfg); | 116 | GNUNET_CONFIGURATION_destroy(cfg); |
117 | cfg = NULL; | 117 | cfg = NULL; |
118 | } | 118 | } |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
@@ -125,13 +125,13 @@ do_shutdown (void *cls) | |||
125 | * @param cls NULL | 125 | * @param cls NULL |
126 | */ | 126 | */ |
127 | static void | 127 | static void |
128 | do_abort (void *cls) | 128 | do_abort(void *cls) |
129 | { | 129 | { |
130 | abort_task = NULL; | 130 | abort_task = NULL; |
131 | LOG (GNUNET_ERROR_TYPE_WARNING, | 131 | LOG(GNUNET_ERROR_TYPE_WARNING, |
132 | "Aborting\n"); | 132 | "Aborting\n"); |
133 | result = GNUNET_SYSERR; | 133 | result = GNUNET_SYSERR; |
134 | GNUNET_SCHEDULER_shutdown (); | 134 | GNUNET_SCHEDULER_shutdown(); |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
@@ -140,15 +140,15 @@ do_abort (void *cls) | |||
140 | * many failed | 140 | * many failed |
141 | */ | 141 | */ |
142 | static void | 142 | static void |
143 | print_overlay_links_summary () | 143 | print_overlay_links_summary() |
144 | { | 144 | { |
145 | static int printed_already; | 145 | static int printed_already; |
146 | 146 | ||
147 | if (GNUNET_YES == printed_already) | 147 | if (GNUNET_YES == printed_already) |
148 | return; | 148 | return; |
149 | printed_already = GNUNET_YES; | 149 | printed_already = GNUNET_YES; |
150 | printf ("%u links succeeded\n", established_links); | 150 | printf("%u links succeeded\n", established_links); |
151 | printf ("%u links failed due to timeouts\n", failed_links); | 151 | printf("%u links failed due to timeouts\n", failed_links); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
@@ -159,41 +159,43 @@ print_overlay_links_summary () | |||
159 | * @param event the controller event | 159 | * @param event the controller event |
160 | */ | 160 | */ |
161 | static void | 161 | static void |
162 | controller_event_cb (void *cls, | 162 | controller_event_cb(void *cls, |
163 | const struct GNUNET_TESTBED_EventInformation *event) | 163 | const struct GNUNET_TESTBED_EventInformation *event) |
164 | { | 164 | { |
165 | switch (event->type) | 165 | switch (event->type) |
166 | { | ||
167 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: | ||
168 | /* Control reaches here when a peer linking operation fails */ | ||
169 | if (NULL != event->details.operation_finished.emsg) | ||
170 | { | 166 | { |
171 | printf ("F"); | 167 | case GNUNET_TESTBED_ET_OPERATION_FINISHED: |
172 | fflush (stdout); | 168 | /* Control reaches here when a peer linking operation fails */ |
173 | failed_links++; | 169 | if (NULL != event->details.operation_finished.emsg) |
174 | if (++cont_fails > num_cont_fails) | 170 | { |
175 | { | 171 | printf("F"); |
176 | printf ("\nAborting due to very high failure rate\n"); | 172 | fflush(stdout); |
177 | print_overlay_links_summary (); | 173 | failed_links++; |
178 | GNUNET_SCHEDULER_shutdown (); | 174 | if (++cont_fails > num_cont_fails) |
179 | return; | 175 | { |
180 | } | 176 | printf("\nAborting due to very high failure rate\n"); |
177 | print_overlay_links_summary(); | ||
178 | GNUNET_SCHEDULER_shutdown(); | ||
179 | return; | ||
180 | } | ||
181 | } | ||
182 | break; | ||
183 | |||
184 | case GNUNET_TESTBED_ET_CONNECT: | ||
185 | { | ||
186 | if (0 != cont_fails) | ||
187 | cont_fails--; | ||
188 | if (0 == established_links) | ||
189 | printf("Establishing links. Please wait\n"); | ||
190 | printf("."); | ||
191 | fflush(stdout); | ||
192 | established_links++; | ||
181 | } | 193 | } |
182 | break; | 194 | break; |
183 | case GNUNET_TESTBED_ET_CONNECT: | 195 | |
184 | { | 196 | default: |
185 | if (0 != cont_fails) | 197 | GNUNET_break(0); |
186 | cont_fails--; | 198 | } |
187 | if (0 == established_links) | ||
188 | printf ("Establishing links. Please wait\n"); | ||
189 | printf ("."); | ||
190 | fflush (stdout); | ||
191 | established_links++; | ||
192 | } | ||
193 | break; | ||
194 | default: | ||
195 | GNUNET_break (0); | ||
196 | } | ||
197 | } | 199 | } |
198 | 200 | ||
199 | 201 | ||
@@ -209,30 +211,30 @@ controller_event_cb (void *cls, | |||
209 | * @param links_failed the number of overlay link | 211 | * @param links_failed the number of overlay link |
210 | */ | 212 | */ |
211 | static void | 213 | static void |
212 | test_run (void *cls, | 214 | test_run(void *cls, |
213 | struct GNUNET_TESTBED_RunHandle *h, | 215 | struct GNUNET_TESTBED_RunHandle *h, |
214 | unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, | 216 | unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, |
215 | unsigned int links_succeeded, | 217 | unsigned int links_succeeded, |
216 | unsigned int links_failed) | 218 | unsigned int links_failed) |
217 | { | 219 | { |
218 | result = GNUNET_OK; | 220 | result = GNUNET_OK; |
219 | fprintf (stdout, "\n"); | 221 | fprintf(stdout, "\n"); |
220 | print_overlay_links_summary (); | 222 | print_overlay_links_summary(); |
221 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); | 223 | GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); |
222 | if (noninteractive) | 224 | if (noninteractive) |
223 | { | 225 | { |
224 | GNUNET_SCHEDULER_cancel (abort_task); | 226 | GNUNET_SCHEDULER_cancel(abort_task); |
225 | abort_task = NULL; | 227 | abort_task = NULL; |
226 | return; | 228 | return; |
227 | } | 229 | } |
228 | #if (!ENABLE_SUPERMUC) | 230 | #if (!ENABLE_SUPERMUC) |
229 | fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n"); | 231 | fprintf(stdout, "Testbed running, waiting for keystroke to shut down\n"); |
230 | fflush (stdout); | 232 | fflush(stdout); |
231 | (void) getc (stdin); | 233 | (void)getc(stdin); |
232 | #endif | 234 | #endif |
233 | fprintf (stdout, "Shutting down. Please wait\n"); | 235 | fprintf(stdout, "Shutting down. Please wait\n"); |
234 | fflush (stdout); | 236 | fflush(stdout); |
235 | GNUNET_SCHEDULER_shutdown (); | 237 | GNUNET_SCHEDULER_shutdown(); |
236 | } | 238 | } |
237 | 239 | ||
238 | 240 | ||
@@ -245,25 +247,25 @@ test_run (void *cls, | |||
245 | * @param config configuration | 247 | * @param config configuration |
246 | */ | 248 | */ |
247 | static void | 249 | static void |
248 | run (void *cls, char *const *args, const char *cfgfile, | 250 | run(void *cls, char *const *args, const char *cfgfile, |
249 | const struct GNUNET_CONFIGURATION_Handle *config) | 251 | const struct GNUNET_CONFIGURATION_Handle *config) |
250 | { | 252 | { |
251 | if (0 == num_peers) | 253 | if (0 == num_peers) |
252 | { | 254 | { |
253 | LOG (GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), | 255 | LOG(GNUNET_ERROR_TYPE_ERROR, _("Exiting as the number of peers is %u\n"), |
254 | num_peers); | 256 | num_peers); |
255 | return; | 257 | return; |
256 | } | 258 | } |
257 | cfg = GNUNET_CONFIGURATION_dup (config); | 259 | cfg = GNUNET_CONFIGURATION_dup(config); |
258 | event_mask = 0; | 260 | event_mask = 0; |
259 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); | 261 | event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); |
260 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); | 262 | event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); |
261 | GNUNET_TESTBED_run (hosts_file, cfg, num_peers, event_mask, | 263 | GNUNET_TESTBED_run(hosts_file, cfg, num_peers, event_mask, |
262 | &controller_event_cb, NULL, | 264 | &controller_event_cb, NULL, |
263 | &test_run, NULL); | 265 | &test_run, NULL); |
264 | abort_task = | 266 | abort_task = |
265 | GNUNET_SCHEDULER_add_shutdown (&do_abort, | 267 | GNUNET_SCHEDULER_add_shutdown(&do_abort, |
266 | NULL); | 268 | NULL); |
267 | } | 269 | } |
268 | 270 | ||
269 | 271 | ||
@@ -273,47 +275,47 @@ run (void *cls, char *const *args, const char *cfgfile, | |||
273 | * @return 0 on success | 275 | * @return 0 on success |
274 | */ | 276 | */ |
275 | int | 277 | int |
276 | main (int argc, char *const *argv) | 278 | main(int argc, char *const *argv) |
277 | { | 279 | { |
278 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 280 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
279 | GNUNET_GETOPT_option_uint ('p', | 281 | GNUNET_GETOPT_option_uint('p', |
280 | "num-peers", | 282 | "num-peers", |
281 | "COUNT", | 283 | "COUNT", |
282 | gettext_noop ("create COUNT number of peers"), | 284 | gettext_noop("create COUNT number of peers"), |
283 | &num_peers), | 285 | &num_peers), |
284 | GNUNET_GETOPT_option_uint ('e', | 286 | GNUNET_GETOPT_option_uint('e', |
285 | "num-errors", | 287 | "num-errors", |
286 | "COUNT", | 288 | "COUNT", |
287 | gettext_noop ("tolerate COUNT number of continious timeout failures"), | 289 | gettext_noop("tolerate COUNT number of continious timeout failures"), |
288 | &num_cont_fails), | 290 | &num_cont_fails), |
289 | GNUNET_GETOPT_option_flag ('n', | 291 | GNUNET_GETOPT_option_flag('n', |
290 | "non-interactive", | 292 | "non-interactive", |
291 | gettext_noop ("run profiler in non-interactive mode where upon " | 293 | gettext_noop("run profiler in non-interactive mode where upon " |
292 | "testbed setup the profiler does not wait for a " | 294 | "testbed setup the profiler does not wait for a " |
293 | "keystroke but continues to run until a termination " | 295 | "keystroke but continues to run until a termination " |
294 | "signal is received"), | 296 | "signal is received"), |
295 | &noninteractive), | 297 | &noninteractive), |
296 | #if !ENABLE_SUPERMUC | 298 | #if !ENABLE_SUPERMUC |
297 | GNUNET_GETOPT_option_string ('H', | 299 | GNUNET_GETOPT_option_string('H', |
298 | "hosts", | 300 | "hosts", |
299 | "FILENAME", | 301 | "FILENAME", |
300 | gettext_noop ("name of the file with the login information for the testbed"), | 302 | gettext_noop("name of the file with the login information for the testbed"), |
301 | &hosts_file), | 303 | &hosts_file), |
302 | #endif | 304 | #endif |
303 | GNUNET_GETOPT_OPTION_END | 305 | GNUNET_GETOPT_OPTION_END |
304 | }; | 306 | }; |
305 | const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; | 307 | const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]"; |
306 | int ret; | 308 | int ret; |
307 | 309 | ||
308 | unsetenv ("XDG_DATA_HOME"); | 310 | unsetenv("XDG_DATA_HOME"); |
309 | unsetenv ("XDG_CONFIG_HOME"); | 311 | unsetenv("XDG_CONFIG_HOME"); |
310 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 312 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args(argc, argv, &argc, &argv)) |
311 | return 2; | 313 | return 2; |
312 | result = GNUNET_SYSERR; | 314 | result = GNUNET_SYSERR; |
313 | ret = | 315 | ret = |
314 | GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp, | 316 | GNUNET_PROGRAM_run(argc, argv, "gnunet-testbed-profiler", binaryHelp, |
315 | options, &run, NULL); | 317 | options, &run, NULL); |
316 | GNUNET_free ((void *) argv); | 318 | GNUNET_free((void *)argv); |
317 | if (GNUNET_OK != ret) | 319 | if (GNUNET_OK != ret) |
318 | return ret; | 320 | return ret; |
319 | if (GNUNET_OK != result) | 321 | if (GNUNET_OK != result) |