diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-18 15:49:57 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-04-18 15:49:57 +0000 |
commit | 8f3820b6244a0ac7fa28956413e17a6d3feb860c (patch) | |
tree | 592d6cdbf4f1f3239a2b834754ccfe056076eba9 /src/ats/perf_ats_mlp.c | |
parent | cc8cf22281f1f9d77fb498664ad8f847dccee17e (diff) | |
download | gnunet-8f3820b6244a0ac7fa28956413e17a6d3feb860c.tar.gz gnunet-8f3820b6244a0ac7fa28956413e17a6d3feb860c.zip |
- remove statistics use return values
Diffstat (limited to 'src/ats/perf_ats_mlp.c')
-rw-r--r-- | src/ats/perf_ats_mlp.c | 124 |
1 files changed, 28 insertions, 96 deletions
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c index 623f187ea..63dce8b37 100644 --- a/src/ats/perf_ats_mlp.c +++ b/src/ats/perf_ats_mlp.c | |||
@@ -47,15 +47,12 @@ struct ATS_Address *a; | |||
47 | 47 | ||
48 | static int ret; | 48 | static int ret; |
49 | 49 | ||
50 | struct GNUNET_STATISTICS_Handle * stats; | ||
51 | |||
52 | struct GNUNET_CONTAINER_MultiHashMap * amap; | 50 | struct GNUNET_CONTAINER_MultiHashMap * amap; |
53 | 51 | ||
54 | struct GAS_MLP_Handle *mlp; | 52 | struct GAS_MLP_Handle *mlp; |
55 | 53 | ||
56 | struct GNUNET_STATISTICS_Handle * stats; | ||
57 | 54 | ||
58 | struct GNUNET_OS_Process *stats_proc; | 55 | |
59 | 56 | ||
60 | GNUNET_SCHEDULER_TaskIdentifier shutdown_task; | 57 | GNUNET_SCHEDULER_TaskIdentifier shutdown_task; |
61 | 58 | ||
@@ -107,70 +104,27 @@ do_shutdown (void *cls, | |||
107 | GNUNET_CONTAINER_multihashmap_destroy(amap); | 104 | GNUNET_CONTAINER_multihashmap_destroy(amap); |
108 | GNUNET_free_non_null (a); | 105 | GNUNET_free_non_null (a); |
109 | GNUNET_free_non_null (p); | 106 | GNUNET_free_non_null (p); |
110 | if (stats != NULL) | ||
111 | GNUNET_STATISTICS_destroy (stats,GNUNET_NO); | ||
112 | 107 | ||
113 | if (NULL != stats_proc) | ||
114 | { | ||
115 | if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM)) | ||
116 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
117 | if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK) | ||
118 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); | ||
119 | GNUNET_OS_process_close (stats_proc); | ||
120 | stats_proc = NULL; | ||
121 | } | ||
122 | } | 108 | } |
123 | 109 | ||
124 | int stat_lp_it (void *cls, const char *subsystem, | ||
125 | const char *name, uint64_t value, | ||
126 | int is_persistent) | ||
127 | { | ||
128 | static long long unsigned lp_time; | ||
129 | static long long unsigned mlp_time; | ||
130 | static long long unsigned lp_time_set; | ||
131 | static long long unsigned mlp_time_set; | ||
132 | |||
133 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received: `%s' : %u \n", name, value); | ||
134 | |||
135 | if (0 == strcmp (name, "# LP execution time (ms)")) | ||
136 | { | ||
137 | lp_time = value; | ||
138 | lp_time_set = GNUNET_YES; | ||
139 | } | ||
140 | if (0 == strcmp (name, "# MLP execution time (ms)")) | ||
141 | { | ||
142 | mlp_time = value; | ||
143 | mlp_time_set = GNUNET_YES; | ||
144 | } | ||
145 | 110 | ||
146 | if ((GNUNET_YES == lp_time_set) && (GNUNET_YES == mlp_time_set)) | 111 | static void |
147 | { | 112 | check (void *cls, char *const *args, const char *cfgfile, |
148 | if (GNUNET_YES == numeric) | 113 | const struct GNUNET_CONFIGURATION_Handle *cfg) |
149 | printf ("%u;%u;%llu;%llu\n",peers, addresses, lp_time, mlp_time); | ||
150 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
151 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
152 | shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); | ||
153 | } | ||
154 | return GNUNET_OK; | ||
155 | } | ||
156 | |||
157 | int stat_ready_it (void *cls, const char *subsystem, | ||
158 | const char *name, uint64_t value, | ||
159 | int is_persistent) | ||
160 | { | 114 | { |
161 | unsigned int c = 0; | 115 | unsigned int c = 0; |
162 | unsigned int c2 = 0; | 116 | unsigned int c2 = 0; |
163 | unsigned int ca = 0; | 117 | unsigned int ca = 0; |
164 | struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
165 | 118 | ||
166 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics service ready\n"); | 119 | #if !HAVE_LIBGLPK |
167 | 120 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); | |
168 | GNUNET_STATISTICS_watch (stats, "ats", "# LP execution time (ms)", &stat_lp_it, NULL); | 121 | ret = 1; |
169 | GNUNET_STATISTICS_watch (stats, "ats", "# MLP execution time (ms)", &stat_lp_it, NULL); | 122 | return; |
123 | #endif | ||
170 | 124 | ||
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses); | 125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses); |
172 | 126 | ||
173 | mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); | 127 | mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); |
174 | if (NULL == mlp) | 128 | if (NULL == mlp) |
175 | { | 129 | { |
176 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n"); | 130 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n"); |
@@ -178,7 +132,6 @@ int stat_ready_it (void *cls, const char *subsystem, | |||
178 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | 132 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) |
179 | GNUNET_SCHEDULER_cancel(shutdown_task); | 133 | GNUNET_SCHEDULER_cancel(shutdown_task); |
180 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 134 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); |
181 | return GNUNET_NO; | ||
182 | } | 135 | } |
183 | 136 | ||
184 | if (peers == 0) | 137 | if (peers == 0) |
@@ -195,7 +148,7 @@ int stat_ready_it (void *cls, const char *subsystem, | |||
195 | for (c=0; c < peers; c++) | 148 | for (c=0; c < peers; c++) |
196 | { | 149 | { |
197 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); | 150 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); |
198 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey); | 151 | GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, &p[c].id.hashPubKey); |
199 | 152 | ||
200 | for (c2=0; c2 < addresses; c2++) | 153 | for (c2=0; c2 < addresses; c2++) |
201 | { | 154 | { |
@@ -212,9 +165,9 @@ int stat_ready_it (void *cls, const char *subsystem, | |||
212 | 165 | ||
213 | a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information)); | 166 | a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information)); |
214 | a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; | 167 | a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; |
215 | a[ca].ats[0].value = 20; | 168 | a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); |
216 | a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE; | 169 | a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE; |
217 | a[ca].ats[1].value = 2; | 170 | a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); |
218 | a[ca].ats_count = 2; | 171 | a[ca].ats_count = 2; |
219 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca); | 172 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca); |
220 | GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 173 | GNUNET_CONTAINER_multihashmap_put (amap, &a[ca].peer.hashPubKey, &a[ca], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
@@ -222,51 +175,30 @@ int stat_ready_it (void *cls, const char *subsystem, | |||
222 | ca++; | 175 | ca++; |
223 | } | 176 | } |
224 | } | 177 | } |
225 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); | 178 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); |
226 | 179 | ||
227 | GNUNET_assert (peers == mlp->c_p); | 180 | GNUNET_assert (peers == mlp->c_p); |
228 | GNUNET_assert (peers * addresses == mlp->addr_in_problem); | 181 | GNUNET_assert (peers * addresses == mlp->addr_in_problem); |
229 | 182 | ||
230 | /* Solving the problem */ | 183 | /* Solving the problem */ |
231 | if (GNUNET_OK == GAS_mlp_solve_problem(mlp)) | 184 | struct GAS_MLP_SolutionContext ctx; |
232 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n"); | ||
233 | else | ||
234 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses); | ||
235 | |||
236 | GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, "Waiting for statistics\n"); | ||
237 | |||
238 | 185 | ||
239 | return GNUNET_OK; | 186 | if (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx)) |
240 | } | ||
241 | |||
242 | static void | ||
243 | check (void *cls, char *const *args, const char *cfgfile, | ||
244 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
245 | { | ||
246 | #if !HAVE_LIBGLPK | ||
247 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); | ||
248 | ret = 1; | ||
249 | return; | ||
250 | #endif | ||
251 | |||
252 | stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", | ||
253 | "gnunet-service-statistics", NULL); | ||
254 | |||
255 | if (NULL == stats_proc) | ||
256 | { | 187 | { |
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n"); | 188 | GNUNET_assert (GNUNET_OK == ctx.lp_result); |
258 | ret = 1; | 189 | GNUNET_assert (GNUNET_OK == ctx.mlp_result); |
259 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | 190 | if (GNUNET_YES == numeric) |
260 | GNUNET_SCHEDULER_cancel(shutdown_task); | 191 | printf ("%u;%u;%llu;%llu\n",mlp->c_p, mlp->addr_in_problem, (long long unsigned int) ctx.lp_duration.rel_value, (long long unsigned int) ctx.mlp_duration.rel_value); |
261 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | 192 | else |
262 | return; | 193 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Problem solved successfully (LP: %llu ms / MLP: %llu ms)\n", ctx.lp_duration.rel_value, ctx.mlp_duration.rel_value); |
263 | } | ||
264 | 194 | ||
265 | stats = GNUNET_STATISTICS_create("ats", cfg); | 195 | } |
196 | else | ||
197 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses); | ||
198 | if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) | ||
199 | GNUNET_SCHEDULER_cancel(shutdown_task); | ||
200 | shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); | ||
266 | 201 | ||
267 | GNUNET_STATISTICS_watch (stats, "ats", "watch", &stat_ready_it, (void *) cfg); | ||
268 | GNUNET_STATISTICS_set(stats, "watch", 1, GNUNET_NO); | ||
269 | return; | ||
270 | } | 202 | } |
271 | 203 | ||
272 | 204 | ||