GNUnet 0.21.1
gnunet-fs-profiler.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testbed_service.h"
29
33static int ret;
34
38static char *host_filename;
39
43static unsigned int num_peers;
44
49
54
55
64static void
65shutdown_task (void *cls,
66 struct GNUNET_TESTBED_Operation *op,
67 const char *emsg)
68{
69 if (NULL != emsg)
70 fprintf (stderr,
71 "Error collecting statistics: %s\n",
72 emsg);
74}
75
76
89static int
90process_stats (void *cls,
91 const struct GNUNET_TESTBED_Peer *peer,
92 const char *subsystem,
93 const char *name,
94 uint64_t value,
95 int is_persistent)
96{
97 fprintf (stdout,
98 "%p-%s: %s = %llu\n",
99 peer,
100 subsystem,
101 name,
102 (unsigned long long) value);
103 return GNUNET_OK;
104}
105
106
113static void
114terminate_task (void *cls)
115{
116 if (NULL != terminate_taskid)
117 {
119 terminate_taskid = NULL;
120 }
121 GNUNET_TESTBED_get_statistics (0, NULL,
122 NULL, NULL,
125 NULL);
126}
127
128
135static void
136timeout_task (void *cls)
137{
138 terminate_taskid = NULL;
140}
141
142
155static void
156test_master (void *cls,
157 struct GNUNET_TESTBED_RunHandle *h,
158 unsigned int num_peers,
159 struct GNUNET_TESTBED_Peer **peers,
160 unsigned int links_succeeded,
161 unsigned int links_failed)
162{
163 // const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
164 // FIXME: enable clients to signal 'completion' before timeout;
165 // in that case, run the 'terminate_task' "immediately"
166
167 if (0 != timeout.rel_value_us)
170 NULL);
172 NULL);
173}
174
175
184static void
185run (void *cls, char *const *args, const char *cfgfile,
186 const struct GNUNET_CONFIGURATION_Handle *cfg)
187{
188 GNUNET_TESTBED_run (host_filename,
189 cfg,
190 num_peers,
191 0, NULL, NULL,
192 &test_master, (void *) cfg);
193}
194
195
203int
204main (int argc, char *const *argv)
205{
208 "num-peers",
209 "COUNT",
211 "run the experiment with COUNT peers"),
212 &num_peers),
213
215 "hosts",
216 "HOSTFILE",
218 "specifies name of a file with the HOSTS the testbed should use"),
220
222 "timeout",
223 "DELAY",
225 "automatically terminate experiment after DELAY"),
226 &timeout),
227
229 };
230
231 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
232 return 2;
233
234 ret = (GNUNET_OK ==
235 GNUNET_PROGRAM_run (argc, argv, "gnunet-fs-profiler",
237 "run a testbed to measure file-sharing performance"),
238 options, &run,
239 NULL)) ? ret : 1;
240 GNUNET_free_nz ((void *) argv);
241 return ret;
242}
243
244
245/* end of gnunet-fs-profiler.c */
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct GNUNET_SCHEDULER_Task * terminate_taskid
Handle to the task run during termination.
static void terminate_task(void *cls)
Task run on shutdown to terminate.
static int process_stats(void *cls, const struct GNUNET_TESTBED_Peer *peer, const char *subsystem, const char *name, uint64_t value, int is_persistent)
Callback function to process statistic values from all peers.
static void timeout_task(void *cls)
Task run on timeout to terminate.
static void test_master(void *cls, struct GNUNET_TESTBED_RunHandle *h, unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, unsigned int links_succeeded, unsigned int links_failed)
Signature of a main function for a testcase.
static int ret
Final status code.
static struct GNUNET_TIME_Relative timeout
After how long do we abort the test?
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
int main(int argc, char *const *argv)
Program to run a file-sharing testbed.
static char * host_filename
Data file with the hosts for the testbed.
static unsigned int num_peers
Number of peers to run in the experiment.
static void shutdown_task(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Function called after we've collected the statistics.
static char * name
Name (label) of the records to list.
static char * value
Value of the record to add/remove.
struct GNUNET_CONTAINER_MultiPeerMap * peers
Map from PIDs to struct CadetPeer entries.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_uint(char shortName, const char *name, const char *argumentHelp, const char *description, unsigned int *val)
Allow user to specify an unsigned int.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_relative_time(char shortName, const char *name, const char *argumentHelp, const char *description, struct GNUNET_TIME_Relative *val)
Allow user to specify a struct GNUNET_TIME_Relative (using human-readable "fancy" time).
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
@ GNUNET_OK
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1340
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1230
Definition of a command line option.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.