diff options
author | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-12-04 17:35:11 +0000 |
---|---|---|
committer | Fabian Oehlmann <oehlmann@in.tum.de> | 2013-12-04 17:35:11 +0000 |
commit | 6f2f56bb209592d291c3dec341ad94aed659c3a8 (patch) | |
tree | fdf26a499d0a9d5c84289dc934e42dc7031c2469 /src/ats | |
parent | c988fa3520d372343a21a19b22ca0a8d473cd47b (diff) | |
download | gnunet-6f2f56bb209592d291c3dec341ad94aed659c3a8.tar.gz gnunet-6f2f56bb209592d291c3dec341ad94aed659c3a8.zip |
added file-output for plots
Diffstat (limited to 'src/ats')
-rwxr-xr-x | src/ats/test_ats_solver_convergence.c | 76 |
1 files changed, 51 insertions, 25 deletions
diff --git a/src/ats/test_ats_solver_convergence.c b/src/ats/test_ats_solver_convergence.c index 7a03ecb53..c223eda40 100755 --- a/src/ats/test_ats_solver_convergence.c +++ b/src/ats/test_ats_solver_convergence.c | |||
@@ -19,7 +19,7 @@ | |||
19 | */ | 19 | */ |
20 | /** | 20 | /** |
21 | * @file ats/test_ats_solver_add_address.c | 21 | * @file ats/test_ats_solver_add_address.c |
22 | * @brief solver test: add address, request address and wait for suggest | 22 | * @brief solver test: add address, request address and wait for suggests, write data to file |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Fabian Oehlmann | 25 | * @author Fabian Oehlmann |
@@ -83,27 +83,27 @@ uint32_t test_ats_count; | |||
83 | /** | 83 | /** |
84 | * Seconds to run the test | 84 | * Seconds to run the test |
85 | */ | 85 | */ |
86 | unsigned int seconds; | 86 | static unsigned int seconds; |
87 | 87 | ||
88 | /** | 88 | /** |
89 | * When the test starts | 89 | * When the test starts |
90 | */ | 90 | */ |
91 | struct GNUNET_TIME_Absolute time_start; | 91 | static struct GNUNET_TIME_Absolute time_start; |
92 | 92 | ||
93 | /** | 93 | /** |
94 | * Whether to write a data file | 94 | * Whether to write a data file |
95 | */ | 95 | */ |
96 | int write_data_file; | 96 | static int write_data_file; |
97 | 97 | ||
98 | /** | 98 | /** |
99 | * File handle | 99 | * File name |
100 | */ | 100 | */ |
101 | struct GNUNET_DISK_FileHandle *data_file_handle; | 101 | static char *data_file_name; |
102 | 102 | ||
103 | /** | 103 | /** |
104 | * File name | 104 | * Run name |
105 | */ | 105 | */ |
106 | char *data_file_name; | 106 | static char *run_name; |
107 | 107 | ||
108 | static int | 108 | static int |
109 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, | 109 | stat_cb(void *cls, const char *subsystem, const char *name, uint64_t value, |
@@ -135,9 +135,6 @@ end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
135 | /* Close data file */ | 135 | /* Close data file */ |
136 | if (write_data_file) | 136 | if (write_data_file) |
137 | { | 137 | { |
138 | if (GNUNET_SYSERR == GNUNET_DISK_file_close (data_file_handle)) | ||
139 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file '%s'\n", | ||
140 | data_file_name); | ||
141 | GNUNET_free_non_null(data_file_name); | 138 | GNUNET_free_non_null(data_file_name); |
142 | } | 139 | } |
143 | 140 | ||
@@ -164,6 +161,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
164 | { | 161 | { |
165 | struct GNUNET_TIME_Relative time_delta; | 162 | struct GNUNET_TIME_Relative time_delta; |
166 | char *data; | 163 | char *data; |
164 | struct GNUNET_DISK_FileHandle *data_file_handle; | ||
167 | 165 | ||
168 | GNUNET_assert (NULL != address); | 166 | GNUNET_assert (NULL != address); |
169 | GNUNET_assert (NULL == session); | 167 | GNUNET_assert (NULL == session); |
@@ -181,8 +179,22 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | |||
181 | (double) time_delta.rel_value_us / 1000000., | 179 | (double) time_delta.rel_value_us / 1000000., |
182 | ntohl(bandwidth_in.value__)/1024, | 180 | ntohl(bandwidth_in.value__)/1024, |
183 | ntohl(bandwidth_out.value__)/1024); | 181 | ntohl(bandwidth_out.value__)/1024); |
184 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(data_file_handle, data, strlen(data))) | 182 | data_file_handle = GNUNET_DISK_file_open (data_file_name, |
185 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to file `%s'\n", data_file_name); | 183 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_APPEND, |
184 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | ||
185 | if (NULL == data_file_handle) | ||
186 | { | ||
187 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to file `%s'\n", data_file_name); | ||
188 | } | ||
189 | else | ||
190 | { | ||
191 | if (GNUNET_SYSERR == GNUNET_DISK_file_write(data_file_handle, data, strlen(data))) | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot write data to file `%s'\n", data_file_name); | ||
193 | if (GNUNET_SYSERR == GNUNET_DISK_file_close (data_file_handle)) | ||
194 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file '%s'\n", | ||
195 | data_file_name); | ||
196 | } | ||
197 | |||
186 | GNUNET_free(data); | 198 | GNUNET_free(data); |
187 | } | 199 | } |
188 | 200 | ||
@@ -206,10 +218,11 @@ static void | |||
206 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | 218 | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, |
207 | struct GNUNET_TESTING_Peer *peer) | 219 | struct GNUNET_TESTING_Peer *peer) |
208 | { | 220 | { |
221 | struct GNUNET_DISK_FileHandle *data_file_handle; | ||
222 | |||
209 | stats = GNUNET_STATISTICS_create ("ats", mycfg); | 223 | stats = GNUNET_STATISTICS_create ("ats", mycfg); |
210 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); | 224 | GNUNET_STATISTICS_watch (stats, "ats", "# addresses", &stat_cb, NULL); |
211 | 225 | ||
212 | |||
213 | /* Connect to ATS scheduling */ | 226 | /* Connect to ATS scheduling */ |
214 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); | 227 | sched_ats = GNUNET_ATS_scheduling_init (mycfg, &address_suggest_cb, NULL); |
215 | if (sched_ats == NULL) | 228 | if (sched_ats == NULL) |
@@ -219,17 +232,26 @@ run (void *cls, const struct GNUNET_CONFIGURATION_Handle *mycfg, | |||
219 | return; | 232 | return; |
220 | } | 233 | } |
221 | 234 | ||
222 | /* Set up file handle */ | 235 | /* Create or truncate file */ |
223 | GNUNET_asprintf (&data_file_name, "test_convergence_s%d.data", seconds); | 236 | if (write_data_file) |
224 | data_file_handle = GNUNET_DISK_file_open (data_file_name, | 237 | { |
225 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_TRUNCATE, | 238 | GNUNET_asprintf (&data_file_name, "test_convergence_%s_s%d.data", run_name, seconds); |
226 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); | 239 | data_file_handle = GNUNET_DISK_file_open (data_file_name, |
227 | if (NULL == data_file_handle) { | 240 | GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE | GNUNET_DISK_OPEN_TRUNCATE, |
228 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open data file\n"); | 241 | GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); |
229 | GNUNET_free(data_file_handle); | 242 | if (NULL == data_file_handle) |
230 | GNUNET_free(data_file_name); | 243 | { |
231 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | 244 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not open data file\n"); |
232 | return; | 245 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); |
246 | return; | ||
247 | } | ||
248 | if (GNUNET_SYSERR == GNUNET_DISK_file_close (data_file_handle)) | ||
249 | { | ||
250 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close log file '%s'\n", | ||
251 | data_file_name); | ||
252 | GNUNET_SCHEDULER_add_now (&end_badly, NULL); | ||
253 | return; | ||
254 | } | ||
233 | } | 255 | } |
234 | 256 | ||
235 | /* Set up peer */ | 257 | /* Set up peer */ |
@@ -322,6 +344,7 @@ int | |||
322 | main (int argc, char *argv[]) | 344 | main (int argc, char *argv[]) |
323 | { | 345 | { |
324 | seconds = 5; | 346 | seconds = 5; |
347 | run_name = NULL; | ||
325 | 348 | ||
326 | static struct GNUNET_GETOPT_CommandLineOption options[] = { | 349 | static struct GNUNET_GETOPT_CommandLineOption options[] = { |
327 | { 's', "seconds", NULL, | 350 | { 's', "seconds", NULL, |
@@ -330,6 +353,9 @@ main (int argc, char *argv[]) | |||
330 | { 'd', "data-file", NULL, | 353 | { 'd', "data-file", NULL, |
331 | gettext_noop ("generate data file"), | 354 | gettext_noop ("generate data file"), |
332 | 0, &GNUNET_GETOPT_set_one, &write_data_file}, | 355 | 0, &GNUNET_GETOPT_set_one, &write_data_file}, |
356 | { 'r', "run-name", "NAME", | ||
357 | gettext_noop ("will be part of the data file name"), | ||
358 | 1, &GNUNET_GETOPT_set_string, &run_name}, | ||
333 | GNUNET_GETOPT_OPTION_END | 359 | GNUNET_GETOPT_OPTION_END |
334 | }; | 360 | }; |
335 | 361 | ||