aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-fs-profiler.c
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 11:55:21 +0200
committerMartin Schanzenbach <schanzen@gnunet.org>2023-10-19 11:55:21 +0200
commit579d9473bb75072303789599b23be9b0203336fc (patch)
tree687506d1968bd2a391b71b8832d1e97905db3ca8 /src/fs/gnunet-fs-profiler.c
parentb56e4e05ad919c7191260fcf1d78b1f8d739871a (diff)
downloadgnunet-579d9473bb75072303789599b23be9b0203336fc.tar.gz
gnunet-579d9473bb75072303789599b23be9b0203336fc.zip
BUILD: Move fs to contrib/service
Diffstat (limited to 'src/fs/gnunet-fs-profiler.c')
-rw-r--r--src/fs/gnunet-fs-profiler.c245
1 files changed, 0 insertions, 245 deletions
diff --git a/src/fs/gnunet-fs-profiler.c b/src/fs/gnunet-fs-profiler.c
deleted file mode 100644
index 62da46834..000000000
--- a/src/fs/gnunet-fs-profiler.c
+++ /dev/null
@@ -1,245 +0,0 @@
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
21/**
22 * @file fs/gnunet-fs-profiler.c
23 * @brief tool to benchmark/profile file-sharing
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_testbed_service.h"
29
30/**
31 * Final status code.
32 */
33static int ret;
34
35/**
36 * Data file with the hosts for the testbed.
37 */
38static char *host_filename;
39
40/**
41 * Number of peers to run in the experiment.
42 */
43static unsigned int num_peers;
44
45/**
46 * After how long do we abort the test?
47 */
48static struct GNUNET_TIME_Relative timeout;
49
50/**
51 * Handle to the task run during termination.
52 */
53static struct GNUNET_SCHEDULER_Task *terminate_taskid;
54
55
56/**
57 * Function called after we've collected the statistics.
58 *
59 * @param cls NULL
60 * @param op the operation that has been finished
61 * @param emsg error message in case the operation has failed; will be NULL if
62 * operation has executed successfully.
63 */
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);
73 GNUNET_SCHEDULER_shutdown ();
74}
75
76
77/**
78 * Callback function to process statistic values from all peers.
79 * Prints them out.
80 *
81 * @param cls closure
82 * @param peer the peer the statistic belong to
83 * @param subsystem name of subsystem that created the statistic
84 * @param name the name of the datum
85 * @param value the current value
86 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
87 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
88 */
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
107/**
108 * Task run on shutdown to terminate. Triggers printing out
109 * all statistics.
110 *
111 * @param cls NULL
112 */
113static void
114terminate_task (void *cls)
115{
116 if (NULL != terminate_taskid)
117 {
118 GNUNET_SCHEDULER_cancel (terminate_taskid);
119 terminate_taskid = NULL;
120 }
121 GNUNET_TESTBED_get_statistics (0, NULL,
122 NULL, NULL,
123 &process_stats,
124 &shutdown_task,
125 NULL);
126}
127
128
129/**
130 * Task run on timeout to terminate. Triggers printing out
131 * all statistics.
132 *
133 * @param cls NULL
134 */
135static void
136timeout_task (void *cls)
137{
138 terminate_taskid = NULL;
139 GNUNET_SCHEDULER_shutdown ();
140}
141
142
143/**
144 * Signature of a main function for a testcase.
145 *
146 * @param cls closure
147 * @param h the run handle
148 * @param num_peers number of peers in 'peers'
149 * @param peers handle to peers run in the testbed
150 * @param links_succeeded the number of overlay link connection attempts that
151 * succeeded
152 * @param links_failed the number of overlay link connection attempts that
153 * failed
154 */
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)
168 terminate_taskid = GNUNET_SCHEDULER_add_delayed (timeout,
169 &timeout_task,
170 NULL);
171 GNUNET_SCHEDULER_add_shutdown (&terminate_task,
172 NULL);
173}
174
175
176/**
177 * Main function that will be run by the scheduler.
178 *
179 * @param cls closure
180 * @param args remaining command-line arguments
181 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
182 * @param cfg configuration
183 */
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
196/**
197 * Program to run a file-sharing testbed.
198 *
199 * @param argc number of arguments from the command line
200 * @param argv command line arguments
201 * @return 0 ok, 1 on error
202 */
203int
204main (int argc, char *const *argv)
205{
206 struct GNUNET_GETOPT_CommandLineOption options[] = {
207 GNUNET_GETOPT_option_uint ('n',
208 "num-peers",
209 "COUNT",
210 gettext_noop (
211 "run the experiment with COUNT peers"),
212 &num_peers),
213
214 GNUNET_GETOPT_option_string ('H',
215 "hosts",
216 "HOSTFILE",
217 gettext_noop (
218 "specifies name of a file with the HOSTS the testbed should use"),
219 &host_filename),
220
221 GNUNET_GETOPT_option_relative_time ('t',
222 "timeout",
223 "DELAY",
224 gettext_noop (
225 "automatically terminate experiment after DELAY"),
226 &timeout),
227
228 GNUNET_GETOPT_OPTION_END
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 */