GNUnet  0.20.0
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 
33 static int ret;
34 
38 static char *host_filename;
39 
43 static unsigned int num_peers;
44 
48 static struct GNUNET_TIME_Relative timeout;
49 
54 
55 
64 static void
65 shutdown_task (void *cls,
67  const char *emsg)
68 {
69  if (NULL != emsg)
70  fprintf (stderr,
71  "Error collecting statistics: %s\n",
72  emsg);
74 }
75 
76 
89 static int
90 process_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 
113 static void
114 terminate_task (void *cls)
115 {
116  if (NULL != terminate_taskid)
117  {
119  terminate_taskid = NULL;
120  }
122  NULL, NULL,
123  &process_stats,
124  &shutdown_task,
125  NULL);
126 }
127 
128 
135 static void
136 timeout_task (void *cls)
137 {
138  terminate_taskid = NULL;
140 }
141 
142 
155 static void
156 test_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)
169  &timeout_task,
170  NULL);
172  NULL);
173 }
174 
175 
184 static void
185 run (void *cls, char *const *args, const char *cfgfile,
186  const struct GNUNET_CONFIGURATION_Handle *cfg)
187 {
189  cfg,
190  num_peers,
191  0, NULL, NULL,
192  &test_master, (void *) cfg);
193 }
194 
195 
203 int
204 main (int argc, char *const *argv)
205 {
208  "num-peers",
209  "COUNT",
210  gettext_noop (
211  "run the experiment with COUNT peers"),
212  &num_peers),
213 
215  "hosts",
216  "HOSTFILE",
217  gettext_noop (
218  "specifies name of a file with the HOSTS the testbed should use"),
219  &host_filename),
220 
222  "timeout",
223  "DELAY",
224  gettext_noop (
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",
236  gettext_noop (
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 const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
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 CadetPeer * peers
Operation to get peer ids.
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 * value
Value of the record to add/remove.
static char * subsystem
Set to subsystem that we're going to get stats for (or NULL for all).
API for writing tests and creating large-scale emulation testbeds for GNUnet.
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:562
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:1334
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
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:1272
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:1222
void GNUNET_TESTBED_run(const char *host_filename, const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int num_peers, uint64_t event_mask, GNUNET_TESTBED_ControllerCallback cc, void *cc_cls, GNUNET_TESTBED_TestMaster test_master, void *test_master_cls)
Convenience method for running a testbed with a single call.
struct GNUNET_TESTBED_Operation * GNUNET_TESTBED_get_statistics(unsigned int num_peers, struct GNUNET_TESTBED_Peer **peers, const char *subsystem, const char *name, GNUNET_TESTBED_StatisticsIterator proc, GNUNET_TESTBED_OperationCompletionCallback cont, void *cls)
Convenience method that iterates over all (running) peers and retrieves all statistics from each peer...
const char * name
Definition of a command line option.
Entry in list of pending tasks.
Definition: scheduler.c:136
Opaque handle to an abstract operation to be executed by the testing framework.
A peer controlled by the testing framework.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.