2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU 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.
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.
17 * @file fs/gnunet-fs-profiler.c
18 * @brief tool to benchmark/profile file-sharing
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
23 #include "gnunet_testbed_service.h"
31 * Data file with the hosts for the testbed.
33 static char *host_filename;
36 * Number of peers to run in the experiment.
38 static unsigned int num_peers;
41 * After how long do we abort the test?
43 static struct GNUNET_TIME_Relative timeout;
46 * Handle to the task run during termination.
48 static struct GNUNET_SCHEDULER_Task * terminate_taskid;
52 * Function called after we've collected the statistics.
55 * @param op the operation that has been finished
56 * @param emsg error message in case the operation has failed; will be NULL if
57 * operation has executed successfully.
60 shutdown_task (void *cls,
61 struct GNUNET_TESTBED_Operation *op,
66 "Error collecting statistics: %s\n",
68 GNUNET_SCHEDULER_shutdown ();
73 * Callback function to process statistic values from all peers.
77 * @param peer the peer the statistic belong to
78 * @param subsystem name of subsystem that created the statistic
79 * @param name the name of the datum
80 * @param value the current value
81 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
82 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
85 process_stats (void *cls,
86 const struct GNUNET_TESTBED_Peer *peer,
87 const char *subsystem,
97 (unsigned long long) value);
103 * Task run on shutdown to terminate. Triggers printing out
109 terminate_task (void *cls)
111 if (NULL != terminate_taskid)
113 GNUNET_SCHEDULER_cancel (terminate_taskid);
114 terminate_taskid = NULL;
116 GNUNET_TESTBED_get_statistics (0, NULL,
125 * Task run on timeout to terminate. Triggers printing out
131 timeout_task (void *cls)
133 terminate_taskid = NULL;
134 GNUNET_SCHEDULER_shutdown ();
139 * Signature of a main function for a testcase.
142 * @param h the run handle
143 * @param num_peers number of peers in 'peers'
144 * @param peers handle to peers run in the testbed
145 * @param links_succeeded the number of overlay link connection attempts that
147 * @param links_failed the number of overlay link connection attempts that
151 test_master (void *cls,
152 struct GNUNET_TESTBED_RunHandle *h,
153 unsigned int num_peers,
154 struct GNUNET_TESTBED_Peer **peers,
155 unsigned int links_succeeded,
156 unsigned int links_failed)
158 // const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
159 // FIXME: enable clients to signal 'completion' before timeout;
160 // in that case, run the 'terminate_task' "immediately"
162 if (0 != timeout.rel_value_us)
163 terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout,
166 GNUNET_SCHEDULER_add_shutdown (&terminate_task,
172 * Main function that will be run by the scheduler.
175 * @param args remaining command-line arguments
176 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
177 * @param cfg configuration
180 run (void *cls, char *const *args, const char *cfgfile,
181 const struct GNUNET_CONFIGURATION_Handle *cfg)
183 GNUNET_TESTBED_run (host_filename,
187 &test_master, (void *) cfg);
192 * Program to run a file-sharing testbed.
194 * @param argc number of arguments from the command line
195 * @param argv command line arguments
196 * @return 0 ok, 1 on error
199 main (int argc, char *const *argv)
201 struct GNUNET_GETOPT_CommandLineOption options[] = {
203 GNUNET_GETOPT_option_uint ('n',
206 gettext_noop ("run the experiment with COUNT peers"),
209 GNUNET_GETOPT_option_string ('H',
212 gettext_noop ("specifies name of a file with the HOSTS the testbed should use"),
215 GNUNET_GETOPT_option_relative_time ('t',
218 gettext_noop ("automatically terminate experiment after DELAY"),
221 GNUNET_GETOPT_OPTION_END
223 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
227 GNUNET_PROGRAM_run (argc, argv, "gnunet-fs-profiler",
228 gettext_noop ("run a testbed to measure file-sharing performance"), options, &run,
230 GNUNET_free ((void*) argv);
234 /* end of gnunet-fs-profiler.c */