From: Matthias Wachs Date: Wed, 18 Apr 2012 15:49:57 +0000 (+0000) Subject: - remove statistics use return values X-Git-Tag: initial-import-from-subversion-38251~13890 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=8f3820b6244a0ac7fa28956413e17a6d3feb860c;p=oweals%2Fgnunet.git - remove statistics use return values --- diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index dfb62e665..85113ea8e 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -807,13 +807,6 @@ mlp_create_problem (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHas } -struct SolveContext -{ - struct GNUNET_TIME_Relative lp_duration; - struct GNUNET_TIME_Relative mlp_duration; -}; - - /** * Solves the LP problem * @@ -822,7 +815,7 @@ struct SolveContext * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure */ static int -mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) +mlp_solve_lp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx) { int res; struct GNUNET_TIME_Relative duration; @@ -916,7 +909,7 @@ lp_solv: * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure */ int -mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) +mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *s_ctx) { int res; struct GNUNET_TIME_Relative duration; @@ -981,23 +974,23 @@ mlp_solve_mlp_problem (struct GAS_MLP_Handle *mlp, struct SolveContext *s_ctx) return GNUNET_OK; } -int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp); +int GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx); static void mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { struct GAS_MLP_Handle *mlp = cls; + struct GAS_MLP_SolutionContext ctx; mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) return; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Scheduled problem solving\n"); if (mlp->addr_in_problem != 0) - GAS_mlp_solve_problem(mlp); + GAS_mlp_solve_problem(mlp, &ctx); } /** @@ -1007,12 +1000,16 @@ mlp_scheduler (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure */ int -GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) +GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx) { int res; - struct SolveContext s_ctx; mlp->last_execution = GNUNET_TIME_absolute_get (); + ctx->lp_result = GNUNET_SYSERR; + ctx->mlp_result = GNUNET_SYSERR; + ctx->lp_duration = GNUNET_TIME_relative_get_forever(); + ctx->mlp_duration = GNUNET_TIME_relative_get_forever(); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve LP problem\n"); #if WRITE_MLP char * name; @@ -1023,12 +1020,14 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) GNUNET_free (name); # endif - res = mlp_solve_lp_problem (mlp, &s_ctx); + res = mlp_solve_lp_problem (mlp, ctx); + ctx->lp_result = res; if (res != GNUNET_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "LP Problem solving failed\n"); return GNUNET_SYSERR; } + #if WRITE_MLP GNUNET_asprintf(&name, "problem_%i_lp_solution", i); glp_print_sol (mlp->prob, name); @@ -1037,7 +1036,8 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Solve MLP problem\n"); - res = mlp_solve_mlp_problem (mlp, &s_ctx); + res = mlp_solve_mlp_problem (mlp, ctx); + ctx->mlp_result = res; if (res != GNUNET_OK) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP Problem solving failed\n"); @@ -1050,7 +1050,7 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) # endif GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved %s (LP duration %llu / MLP duration %llu)\n", - (GNUNET_OK == res) ? "successfully" : "failed", s_ctx.lp_duration, s_ctx.mlp_duration); + (GNUNET_OK == res) ? "successfully" : "failed", ctx->lp_duration.rel_value, ctx->mlp_duration.rel_value); /* Process result */ struct ATS_Peer *p = NULL; struct ATS_Address *a = NULL; @@ -1085,7 +1085,7 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) GNUNET_SCHEDULER_cancel(mlp->mlp_task); mlp->mlp_task = GNUNET_SCHEDULER_NO_TASK; } - mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); + //mlp->mlp_task = GNUNET_SCHEDULER_add_delayed (mlp->exec_interval, &mlp_scheduler, mlp); return res; } @@ -1427,7 +1427,7 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) c3 ++; } } - if (c3 > 0) + if ((c3 > 0) && (avg > 0)) /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ mlpi->q_averaged[c] = (double) c3 / avg; else @@ -1452,7 +1452,7 @@ update_quality (struct GAS_MLP_Handle *mlp, struct ATS_Address * address) c3 ++; } } - if (c3 > 0) + if ((c3 > 0) && (avg > 0)) /* avg = 1 / ((q[0] + ... + q[l]) /c3) => c3 / avg*/ mlpi->q_averaged[c] = (double) c3 / avg; else @@ -1540,6 +1540,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult { int new; struct MLP_information *mlpi; + struct GAS_MLP_SolutionContext ctx; GNUNET_STATISTICS_update (mlp->stats, "# MLP address updates", 1, GNUNET_NO); @@ -1624,7 +1625,7 @@ GAS_mlp_address_update (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult mlp->presolver_required = GNUNET_YES; } if (mlp->auto_solve == GNUNET_YES) - GAS_mlp_solve_problem (mlp); + GAS_mlp_solve_problem (mlp, &ctx); } /** @@ -1641,6 +1642,7 @@ void GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_MultiHashMap * addresses, struct ATS_Address *address) { GNUNET_STATISTICS_update (mlp->stats,"# LP address deletions", 1, GNUNET_NO); + struct GAS_MLP_SolutionContext ctx; /* Free resources */ if (address->mlp_information != NULL) @@ -1682,7 +1684,7 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult /* Recalculate */ mlp->presolver_required = GNUNET_YES; if (mlp->auto_solve == GNUNET_YES) - GAS_mlp_solve_problem (mlp); + GAS_mlp_solve_problem (mlp, &ctx); } } diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index e8db35c27..14684d3ba 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h @@ -73,6 +73,14 @@ struct ATS_PreferedAddress struct ATS_Address *address; }; +struct GAS_MLP_SolutionContext +{ + int lp_result; + int mlp_result; + struct GNUNET_TIME_Relative lp_duration; + struct GNUNET_TIME_Relative mlp_duration; +}; + /** * MLP Handle */ @@ -324,7 +332,7 @@ GAS_mlp_init (const struct GNUNET_CONFIGURATION_Handle *cfg, * @return GNUNET_OK if could be solved, GNUNET_SYSERR on failure */ int -GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp); +GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp, struct GAS_MLP_SolutionContext *ctx); /** 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; static int ret; -struct GNUNET_STATISTICS_Handle * stats; - struct GNUNET_CONTAINER_MultiHashMap * amap; struct GAS_MLP_Handle *mlp; -struct GNUNET_STATISTICS_Handle * stats; -struct GNUNET_OS_Process *stats_proc; + GNUNET_SCHEDULER_TaskIdentifier shutdown_task; @@ -107,70 +104,27 @@ do_shutdown (void *cls, GNUNET_CONTAINER_multihashmap_destroy(amap); GNUNET_free_non_null (a); GNUNET_free_non_null (p); - if (stats != NULL) - GNUNET_STATISTICS_destroy (stats,GNUNET_NO); - if (NULL != stats_proc) - { - if (0 != GNUNET_OS_process_kill (stats_proc, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - if (GNUNET_OS_process_wait (stats_proc) != GNUNET_OK) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); - GNUNET_OS_process_close (stats_proc); - stats_proc = NULL; - } } -int stat_lp_it (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) -{ - static long long unsigned lp_time; - static long long unsigned mlp_time; - static long long unsigned lp_time_set; - static long long unsigned mlp_time_set; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received: `%s' : %u \n", name, value); - - if (0 == strcmp (name, "# LP execution time (ms)")) - { - lp_time = value; - lp_time_set = GNUNET_YES; - } - if (0 == strcmp (name, "# MLP execution time (ms)")) - { - mlp_time = value; - mlp_time_set = GNUNET_YES; - } - if ((GNUNET_YES == lp_time_set) && (GNUNET_YES == mlp_time_set)) - { - if (GNUNET_YES == numeric) - printf ("%u;%u;%llu;%llu\n",peers, addresses, lp_time, mlp_time); - if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) - GNUNET_SCHEDULER_cancel(shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL); - } - return GNUNET_OK; -} - -int stat_ready_it (void *cls, const char *subsystem, - const char *name, uint64_t value, - int is_persistent) +static void +check (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { unsigned int c = 0; unsigned int c2 = 0; unsigned int ca = 0; - struct GNUNET_CONFIGURATION_Handle *cfg = cls; - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Statistics service ready\n"); - - GNUNET_STATISTICS_watch (stats, "ats", "# LP execution time (ms)", &stat_lp_it, NULL); - GNUNET_STATISTICS_watch (stats, "ats", "# MLP execution time (ms)", &stat_lp_it, NULL); +#if !HAVE_LIBGLPK + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); + ret = 1; + return; +#endif GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up %u peers with %u addresses per peer\n", peers, addresses); - mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); + mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS); if (NULL == mlp) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init MLP\n"); @@ -178,7 +132,6 @@ int stat_ready_it (void *cls, const char *subsystem, if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) GNUNET_SCHEDULER_cancel(shutdown_task); shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return GNUNET_NO; } if (peers == 0) @@ -195,7 +148,7 @@ int stat_ready_it (void *cls, const char *subsystem, for (c=0; c < peers; c++) { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up peer %u\n", c); - GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[c].id.hashPubKey); + GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_NONCE, &p[c].id.hashPubKey); for (c2=0; c2 < addresses; c2++) { @@ -212,9 +165,9 @@ int stat_ready_it (void *cls, const char *subsystem, a[ca].ats = GNUNET_malloc (2 * sizeof (struct GNUNET_ATS_Information)); a[ca].ats[0].type = GNUNET_ATS_QUALITY_NET_DELAY; - a[ca].ats[0].value = 20; + a[ca].ats[0].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 10); a[ca].ats[1].type = GNUNET_ATS_QUALITY_NET_DISTANCE; - a[ca].ats[1].value = 2; + a[ca].ats[1].value = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2); a[ca].ats_count = 2; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Setting up address %u\n", ca); 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, ca++; } } - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Problem contains %u peers and %u adresses\n", mlp->c_p, mlp->addr_in_problem); GNUNET_assert (peers == mlp->c_p); GNUNET_assert (peers * addresses == mlp->addr_in_problem); /* Solving the problem */ - if (GNUNET_OK == GAS_mlp_solve_problem(mlp)) - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Problem solved successfully \n"); - else - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses); - - GNUNET_log ( GNUNET_ERROR_TYPE_WARNING, "Waiting for statistics\n"); - + struct GAS_MLP_SolutionContext ctx; - return GNUNET_OK; -} - -static void -check (void *cls, char *const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) -{ -#if !HAVE_LIBGLPK - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!"); - ret = 1; - return; -#endif - - stats_proc = GNUNET_OS_start_process (GNUNET_YES, NULL, NULL, "gnunet-service-statistics", - "gnunet-service-statistics", NULL); - - if (NULL == stats_proc) + if (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx)) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start statistics service \n"); - ret = 1; - if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) - GNUNET_SCHEDULER_cancel(shutdown_task); - shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - return; - } + GNUNET_assert (GNUNET_OK == ctx.lp_result); + GNUNET_assert (GNUNET_OK == ctx.mlp_result); + if (GNUNET_YES == numeric) + 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); + else + 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); - stats = GNUNET_STATISTICS_create("ats", cfg); + } + else + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Solving problem with %u peers and %u addresses failed\n", peers, addresses); + if (GNUNET_SCHEDULER_NO_TASK != shutdown_task) + GNUNET_SCHEDULER_cancel(shutdown_task); + shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); - GNUNET_STATISTICS_watch (stats, "ats", "watch", &stat_ready_it, (void *) cfg); - GNUNET_STATISTICS_set(stats, "watch", 1, GNUNET_NO); - return; }