GNUnet  0.19.5
gnunet-testbed-profiler.c File Reference

Profiling driver for the testbed. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_testbed_service.h"
#include "testbed_api_hosts.h"
Include dependency graph for gnunet-testbed-profiler.c:

Go to the source code of this file.

Macros

#define LOG(kind, ...)    GNUNET_log (kind, __VA_ARGS__)
 Generic loggins shorthand. More...
 

Functions

static void do_shutdown (void *cls)
 Shutdown nicely. More...
 
static void do_abort (void *cls)
 abort task to run on test timed out More...
 
static void print_overlay_links_summary ()
 Function to print summary about how many overlay links we have made and how many failed. More...
 
static void controller_event_cb (void *cls, const struct GNUNET_TESTBED_EventInformation *event)
 Controller event callback. More...
 
static void test_run (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. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 Main function. More...
 

Variables

struct GNUNET_CONFIGURATION_Handlecfg
 Handle to global configuration. More...
 
struct GNUNET_TESTBED_Operationtopology_op
 Peer linking - topology operation. More...
 
static char * hosts_file
 Name of the file with the hosts to run the test over (configuration option). More...
 
static struct GNUNET_SCHEDULER_Taskabort_task
 Abort task identifier. More...
 
uint64_t event_mask
 Global event mask for all testbed events. More...
 
static unsigned int num_peers
 Number of peers to be started by the profiler. More...
 
static unsigned int num_cont_fails
 Number of timeout failures to tolerate. More...
 
static unsigned int cont_fails
 Continuous failures during overlay connect operations. More...
 
static unsigned int established_links
 Links which are successfully established. More...
 
static unsigned int failed_links
 Links which are not successfully established. More...
 
static int result
 Global testing status. More...
 
static int noninteractive
 Are we running non interactively. More...
 

Detailed Description

Profiling driver for the testbed.

Author
Sree Harsha Totakura sreeh.nosp@m.arsh.nosp@m.a@tot.nosp@m.akur.nosp@m.a.in

Definition in file gnunet-testbed-profiler.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)     GNUNET_log (kind, __VA_ARGS__)

Generic loggins shorthand.

Definition at line 35 of file gnunet-testbed-profiler.c.

Function Documentation

◆ do_shutdown()

static void do_shutdown ( void *  cls)
static

Shutdown nicely.

Parameters
clsNULL

Definition at line 107 of file gnunet-testbed-profiler.c.

108 {
109  if (NULL != abort_task)
110  {
112  abort_task = NULL;
113  }
114  if (NULL != cfg)
115  {
117  cfg = NULL;
118  }
119 }
static struct GNUNET_SCHEDULER_Task * abort_task
Abort task identifier.
struct GNUNET_CONFIGURATION_Handle * cfg
Handle to global configuration.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975

References abort_task, cfg, GNUNET_CONFIGURATION_destroy(), and GNUNET_SCHEDULER_cancel().

Referenced by test_run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_abort()

static void do_abort ( void *  cls)
static

abort task to run on test timed out

Parameters
clsNULL

Definition at line 128 of file gnunet-testbed-profiler.c.

129 {
130  abort_task = NULL;
132  "Aborting\n");
135 }
static int result
Global testing status.
#define LOG(kind,...)
Generic loggins shorthand.
@ GNUNET_SYSERR
@ GNUNET_ERROR_TYPE_WARNING
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562

References abort_task, GNUNET_ERROR_TYPE_WARNING, GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, LOG, and result.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ print_overlay_links_summary()

static void print_overlay_links_summary ( )
static

Function to print summary about how many overlay links we have made and how many failed.

Definition at line 143 of file gnunet-testbed-profiler.c.

144 {
145  static int printed_already;
146 
147  if (GNUNET_YES == printed_already)
148  return;
149  printed_already = GNUNET_YES;
150  printf ("%u links succeeded\n", established_links);
151  printf ("%u links failed due to timeouts\n", failed_links);
152 }
static unsigned int failed_links
Links which are not successfully established.
static unsigned int established_links
Links which are successfully established.
@ GNUNET_YES

References established_links, failed_links, and GNUNET_YES.

Referenced by controller_event_cb(), and test_run().

Here is the caller graph for this function:

◆ controller_event_cb()

static void controller_event_cb ( void *  cls,
const struct GNUNET_TESTBED_EventInformation event 
)
static

Controller event callback.

Parameters
clsNULL
eventthe controller event

Definition at line 162 of file gnunet-testbed-profiler.c.

164 {
165  switch (event->type)
166  {
168  /* Control reaches here when a peer linking operation fails */
169  if (NULL != event->details.operation_finished.emsg)
170  {
171  printf ("F");
172  fflush (stdout);
173  failed_links++;
174  if (++cont_fails > num_cont_fails)
175  {
176  printf ("\nAborting due to very high failure rate\n");
179  return;
180  }
181  }
182  break;
183 
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);
193  }
194  break;
195 
196  default:
197  GNUNET_break (0);
198  }
199 }
static unsigned int num_cont_fails
Number of timeout failures to tolerate.
static unsigned int cont_fails
Continuous failures during overlay connect operations.
static void print_overlay_links_summary()
Function to print summary about how many overlay links we have made and how many failed.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_TESTBED_ET_CONNECT
A connection between two peers was established.
@ GNUNET_TESTBED_ET_OPERATION_FINISHED
A requested testbed operation has been completed.
enum GNUNET_TESTBED_EventType type
Type of the event.
union GNUNET_TESTBED_EventInformation::@43 details
Details about the event.
struct GNUNET_TESTBED_EventInformation::@43::@48 operation_finished
Details about an operation finished event.

References cont_fails, GNUNET_TESTBED_EventInformation::details, established_links, failed_links, GNUNET_break, GNUNET_SCHEDULER_shutdown(), GNUNET_TESTBED_ET_CONNECT, GNUNET_TESTBED_ET_OPERATION_FINISHED, num_cont_fails, GNUNET_TESTBED_EventInformation::operation_finished, print_overlay_links_summary(), and GNUNET_TESTBED_EventInformation::type.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ test_run()

static void test_run ( void *  cls,
struct GNUNET_TESTBED_RunHandle h,
unsigned int  num_peers,
struct GNUNET_TESTBED_Peer **  peers,
unsigned int  links_succeeded,
unsigned int  links_failed 
)
static

Signature of a main function for a testcase.

Parameters
clsclosure
hthe run handle
num_peersnumber of peers in 'peers'
peershandle to peers run in the testbed
links_succeededthe number of overlay link connection attempts that succeeded
links_failedthe number of overlay link

Definition at line 214 of file gnunet-testbed-profiler.c.

219 {
220  result = GNUNET_OK;
221  fprintf (stdout, "\n");
224  if (noninteractive)
225  {
227  abort_task = NULL;
228  return;
229  }
230  fprintf (stdout, "Testbed running, waiting for keystroke to shut down\n");
231  fflush (stdout);
232  (void) getc (stdin);
233  fprintf (stdout, "Shutting down. Please wait\n");
234  fflush (stdout);
236 }
static void do_shutdown(void *cls)
Shutdown nicely.
static int noninteractive
Are we running non interactively.
@ GNUNET_OK
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

References abort_task, do_shutdown(), GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_cancel(), GNUNET_SCHEDULER_shutdown(), noninteractive, print_overlay_links_summary(), and result.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle config 
)
static

Main function that will be run by the scheduler.

Parameters
clsclosure
argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)
configconfiguration

Definition at line 248 of file gnunet-testbed-profiler.c.

250 {
251  if (0 == num_peers)
252  {
253  LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Exiting as the number of peers is %u\n"),
254  num_peers);
255  return;
256  }
258  event_mask = 0;
262  &controller_event_cb, NULL,
263  &test_run, NULL);
264  abort_task =
266  NULL);
267 }
static const struct GNUNET_CONFIGURATION_Handle * config
static void test_run(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 void controller_event_cb(void *cls, const struct GNUNET_TESTBED_EventInformation *event)
Controller event callback.
static void do_abort(void *cls)
abort task to run on test timed out
uint64_t event_mask
Global event mask for all testbed events.
static char * hosts_file
Name of the file with the hosts to run the test over (configuration option).
static unsigned int num_peers
Number of peers to be started by the profiler.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
@ GNUNET_ERROR_TYPE_ERROR
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, abort_task, cfg, config, controller_event_cb(), do_abort(), event_mask, GNUNET_CONFIGURATION_dup(), GNUNET_ERROR_TYPE_ERROR, GNUNET_SCHEDULER_add_shutdown(), GNUNET_TESTBED_ET_CONNECT, GNUNET_TESTBED_ET_OPERATION_FINISHED, GNUNET_TESTBED_run(), hosts_file, LOG, num_peers, and test_run().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ main()

int main ( int  argc,
char *const *  argv 
)

Main function.

Returns
0 on success

Definition at line 276 of file gnunet-testbed-profiler.c.

277 {
280  "num-peers",
281  "COUNT",
282  gettext_noop ("create COUNT number of peers"),
283  &num_peers),
285  "num-errors",
286  "COUNT",
287  gettext_noop (
288  "tolerate COUNT number of continuous timeout failures"),
289  &num_cont_fails),
291  "non-interactive",
292  gettext_noop (
293  "run profiler in non-interactive mode where upon "
294  "testbed setup the profiler does not wait for a "
295  "keystroke but continues to run until a termination "
296  "signal is received"),
297  &noninteractive),
299  "hosts",
300  "FILENAME",
301  gettext_noop (
302  "name of the file with the login information for the testbed"),
303  &hosts_file),
305  };
306  const char *binaryHelp = "gnunet-testbed-profiler [OPTIONS]";
307  int ret;
308 
309  unsetenv ("XDG_DATA_HOME");
310  unsetenv ("XDG_CONFIG_HOME");
311  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
312  return 2;
314  ret =
315  GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler", binaryHelp,
316  options, &run, NULL);
317  GNUNET_free_nz ((void *) argv);
318  if (GNUNET_OK != ret)
319  return ret;
320  if (GNUNET_OK != result)
321  return 1;
322  return 0;
323 }
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 int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *config)
Main function that will be run by the scheduler.
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_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
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.
#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
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
Definition of a command line option.

References gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_SYSERR, hosts_file, noninteractive, num_cont_fails, num_peers, options, result, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ cfg

Handle to global configuration.

Handle to our configuration.

Definition at line 42 of file gnunet-testbed-profiler.c.

Referenced by do_shutdown(), and run().

◆ topology_op

struct GNUNET_TESTBED_Operation* topology_op

Peer linking - topology operation.

Definition at line 47 of file gnunet-testbed-profiler.c.

◆ hosts_file

char* hosts_file
static

Name of the file with the hosts to run the test over (configuration option).

It will be NULL if ENABLE_LL is set

Definition at line 53 of file gnunet-testbed-profiler.c.

Referenced by main(), and run().

◆ abort_task

struct GNUNET_SCHEDULER_Task* abort_task
static

Abort task identifier.

Definition at line 58 of file gnunet-testbed-profiler.c.

Referenced by do_abort(), do_shutdown(), run(), and test_run().

◆ event_mask

uint64_t event_mask

Global event mask for all testbed events.

Definition at line 63 of file gnunet-testbed-profiler.c.

Referenced by controller_status_cb(), GNUNET_TESTBED_controller_connect(), GNUNET_TESTBED_run(), GNUNET_TESTBED_test_run(), and run().

◆ num_peers

unsigned int num_peers
static

Number of peers to be started by the profiler.

Definition at line 68 of file gnunet-testbed-profiler.c.

Referenced by main(), and run().

◆ num_cont_fails

unsigned int num_cont_fails
static

Number of timeout failures to tolerate.

Definition at line 73 of file gnunet-testbed-profiler.c.

Referenced by controller_event_cb(), and main().

◆ cont_fails

unsigned int cont_fails
static

Continuous failures during overlay connect operations.

Definition at line 78 of file gnunet-testbed-profiler.c.

Referenced by controller_event_cb().

◆ established_links

unsigned int established_links
static

Links which are successfully established.

Definition at line 83 of file gnunet-testbed-profiler.c.

Referenced by controller_event_cb(), and print_overlay_links_summary().

◆ failed_links

unsigned int failed_links
static

Links which are not successfully established.

Definition at line 88 of file gnunet-testbed-profiler.c.

Referenced by controller_event_cb(), and print_overlay_links_summary().

◆ result

int result
static

Global testing status.

Definition at line 93 of file gnunet-testbed-profiler.c.

Referenced by do_abort(), main(), and test_run().

◆ noninteractive

int noninteractive
static

Are we running non interactively.

Definition at line 98 of file gnunet-testbed-profiler.c.

Referenced by main(), and test_run().