aboutsummaryrefslogtreecommitdiff
path: root/src/nse
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-12-07 13:40:28 +0000
committerBart Polot <bart@net.in.tum.de>2011-12-07 13:40:28 +0000
commita07507e69721a1ee257ed758ce1561a4391660c7 (patch)
tree2a3674fd31ca0cba8dbbcc680587d5fd3404364d /src/nse
parent9d66be3547caed59bdb553ebef6368fba810d453 (diff)
downloadgnunet-a07507e69721a1ee257ed758ce1561a4391660c7.tar.gz
gnunet-a07507e69721a1ee257ed758ce1561a4391660c7.zip
- Add periodic statistic readings to output
Diffstat (limited to 'src/nse')
-rw-r--r--src/nse/gnunet-nse-profiler.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/nse/gnunet-nse-profiler.c b/src/nse/gnunet-nse-profiler.c
index 32f650feb..37e5ecfbd 100644
--- a/src/nse/gnunet-nse-profiler.c
+++ b/src/nse/gnunet-nse-profiler.c
@@ -40,6 +40,8 @@ struct NSEPeer
40 struct GNUNET_TESTING_Daemon *daemon; 40 struct GNUNET_TESTING_Daemon *daemon;
41 41
42 struct GNUNET_NSE_Handle *nse_handle; 42 struct GNUNET_NSE_Handle *nse_handle;
43
44 struct GNUNET_STATISTICS_Handle *stats;
43}; 45};
44 46
45 47
@@ -226,7 +228,87 @@ handle_estimate (void *cls, struct GNUNET_TIME_Absolute timestamp,
226 228
227} 229}
228 230
231/**
232 * Process core statistic values.
233 *
234 * @param cls closure
235 * @param subsystem name of subsystem that created the statistic
236 * @param name the name of the datum
237 * @param value the current value
238 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
239 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
240 */
241static int
242core_stats_iterator (void *cls, const char *subsystem, const char *name,
243 uint64_t value, int is_persistent)
244{
245 struct NSEPeer *peer = cls;
246 char *output_buffer;
247 size_t size;
248
249 if (output_file != NULL)
250 {
251 size =
252 GNUNET_asprintf (&output_buffer, "%s -> %s [%s]: %llu\n",
253 GNUNET_i2s (&peer->daemon->id),
254 subsystem, name, value);
255 if (size != GNUNET_DISK_file_write (output_file, output_buffer, size))
256 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Unable to write to file!\n");
257 GNUNET_free (output_buffer);
258 }
259 else
260 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
261 "%s -> %s [%s]: %llu\n",
262 GNUNET_i2s (&peer->daemon->id), subsystem, name, value);
263
264 return GNUNET_OK;
265}
266
267/**
268 * Continuation called by "get_stats" function.
269 *
270 * @param cls closure
271 * @param success GNUNET_OK if statistics were
272 * successfully obtained, GNUNET_SYSERR if not.
273 */
274static void
275core_stats_cont (void *cls, int success);
276
277static void
278core_get_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
279{
280 struct NSEPeer *peer = cls;
281 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
282 {
283 GNUNET_STATISTICS_destroy(peer->stats, GNUNET_YES);
284 }
285 else
286 {
287 GNUNET_STATISTICS_get(peer->stats, "core", NULL,
288 GNUNET_TIME_UNIT_FOREVER_REL,
289 &core_stats_cont, &core_stats_iterator, peer);
290 }
291}
292
293/**
294 * Continuation called by "get_stats" function.
295 *
296 * @param cls closure
297 * @param success GNUNET_OK if statistics were
298 * successfully obtained, GNUNET_SYSERR if not.
299 */
300static void
301core_stats_cont (void *cls, int success)
302{
303 struct NSEPeer *peer = cls;
304 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
305 &core_get_stats, peer);
306}
307
229 308
309/**
310 *
311 */
230static void 312static void
231connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 313connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
232{ 314{
@@ -254,6 +336,13 @@ connect_nse_service (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
254 current_peer); 336 current_peer);
255 GNUNET_assert (current_peer->nse_handle != NULL); 337 GNUNET_assert (current_peer->nse_handle != NULL);
256 } 338 }
339 current_peer->stats = GNUNET_STATISTICS_create("profiler", current_peer->daemon->cfg);
340 GNUNET_STATISTICS_get(current_peer->stats, "core", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
341 &core_stats_cont, &core_stats_iterator, current_peer);
342 GNUNET_STATISTICS_get(current_peer->stats, "transport", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
343 NULL, &core_stats_iterator, current_peer);
344 GNUNET_STATISTICS_get(current_peer->stats, "nse", NULL, GNUNET_TIME_UNIT_FOREVER_REL,
345 NULL, &core_stats_iterator, current_peer);
257 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer); 346 GNUNET_CONTAINER_DLL_insert (peer_head, peer_tail, current_peer);
258 } 347 }
259} 348}