GNUnet  0.11.x
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 
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  {
118  GNUNET_SCHEDULER_cancel (terminate_taskid);
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)
168  terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout,
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 {
206  struct GNUNET_GETOPT_CommandLineOption options[] = {
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 ((void*) argv);
241  return ret;
242 }
243 
244 
245 /* end of gnunet-fs-profiler.c */
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_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...
static char * subsystem
Set to subsystem that we&#39;re going to get stats for (or NULL for all).
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static void terminate_task(void *cls)
Task run on shutdown to terminate.
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1300
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1438
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 int ret
Final status code.
static void shutdown_task(void *cls, struct GNUNET_TESTBED_Operation *op, const char *emsg)
Function called after we&#39;ve collected the statistics.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static unsigned int num_peers
Number of peers to run in the experiment.
Definition of a command line option.
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.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:526
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
Opaque handle to an abstract operation to be executed by the testing framework.
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.
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:1253
static char * value
Value of the record to add/remove.
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.
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.
int main(int argc, char *const *argv)
Program to run a file-sharing testbed.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static struct GNUNET_SCHEDULER_Task * terminate_taskid
Handle to the task run during termination.
static char * host_filename
Data file with the hosts for the testbed.
configuration data
Definition: configuration.c:85
const char * name
static struct CadetPeer * peers
Operation to get peer ids.
Entry in list of pending tasks.
Definition: scheduler.c:134
int 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, parse options).
Definition: program.c:367
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.
static struct GNUNET_TIME_Relative timeout
After how long do we abort the test?
static struct GNUNET_ARM_Operation * op
Current operation.
Definition: gnunet-arm.c:144
A peer controlled by the testing framework.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
#define gettext_noop(String)
Definition: gettext.h:69
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966